So, I decided to try and make a game of Top Trumps using C#, and bearing in mind I've only been using Visual Studio for 3 months now, I'm no pro.
I've been advised to use a Player class, which can then hold the cards for both Player 1 and Player 2's hands. By doing this, I will be able to remove cards when someone wins it.
The issue is I don't really know how to go about doing this.
Also, as I'm new here and to coding, I don't really know what to post code wise, as well as terminology wise.
Here's the whole program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TopTrumps
{
public partial class Form1 : Form
{
Random RandomNumbers = new Random(); //Initialise Random number generator
Deck mDeck = new Deck();
Player mPlayer1 = new Player();
Player mPlayer2 = new Player();
public Form1()
{
InitializeComponent();
mPlayer1.mPlayerHand;
mPlayer2.mPlayerHand;
}
int GetRandomCardIndex() //Get a random card array index from the deck
{
return RandomNumbers.Next() % mDeck.mCards.Count; //Limit number to size of array
}
void ShuffleDeck()
{
for (int i = 0; i < 100; i++)
{
int FirstCard;
int SecondCard;
Card TempCard;
FirstCard = GetRandomCardIndex();
SecondCard = GetRandomCardIndex();
TempCard = mDeck.mCards[FirstCard];
mDeck.mCards[FirstCard] = mDeck.mCards[SecondCard];
mDeck.mCards[SecondCard] = TempCard;
}
}
public class Card
{
public string mCarName = "Dodge Viper SRT-10";
public int mTopSpeed = 100;
public float m0_60 = 0.0F;
public int mBHP = 200;
public int mCapacity = 250;
public int mWeight = 5;
public Card()
{
}
public Card(string tCarName, int tTopSpeed, float t0_60, int tBHP, int tCapacity, int tWeight)
{
mCarName = tCarName;
mTopSpeed = tTopSpeed;
m0_60 = t0_60;
mBHP = tBHP;
mCapacity = tCapacity;
mWeight = tWeight;
}
//Method to return a string descrivbing the details of the Car
public string CarDetails()
{
return "CarName: " + mCarName + "\nTopSpeed: " + mTopSpeed + "\n0-60: " + m0_60 + "\nBHP: " + mBHP + "\nCapacity:" + mCapacity + "\nWeight:" + mWeight + "\n\n";
}
}
public class Deck
{
public List<Card> mCards = new List<Card>();
//NAMES OF ALL THE CARDS IN THE DECK
public string[] mAR_ST_CarName = { "Dodge Viper SRT-10", "Bugatti Veyron", "Porsche GT3 RS","Lamborghini Gallardo", "Mercedes SL55 AMG", "Ferarri F40","Noble M12", "Lamborghini Countach", "Porsche 959", "Corvette ZO6","BMW M3 CSL", "AC Cobra", "Honda NSX Type R", "Caterham R500","Lotus Esprit", "Saleen S7", "Jaguar XJ220", "Koenigsnegg CC8S","Mclaren F1", "Maserati MC12", "Mitsubushi Evo VIII", "Subaru Impreza","Aston Martin DB9", "Ferarri Enzo", "Ferrari 360 Stradale", "Radical SR3 Turbo","Ford GT", "Porsche Carrera GT", "TVR Tuscan S", "Bentley Continental GT","Pagani Zonda C12S", "Mercedes SLR Mclaren" };
//EVERY TOP SPEED FOR EVERY CAR IN THE DECK
public int[] mAR_ST_TopSpeed = { 189, 252, 190, 192, 155, 201, 170, 185, 197,
172, 155, 160, 168, 145, 175, 239, 217, 235,
240, 205, 148, 155, 186, 218, 188, 160, 200,
205, 185, 196, 215, 207 };
//EVERY 0-60 TIME FOR EVERY CAR IN THE DECK
public float[] mAR_ST_0_60 = { 4, 2.8F, 4.3F, 4.1F, 4.6F, 3.9F, 3.9F, 4.8F, 3.9F,
4.3F, 4.6F, 4.2F, 4.6F, 3.5F, 4.3F, 3.3F, 3.6F, 4.2F,
3.2F, 3.7F, 4.9F, 4.5F, 4.9F, 3.4F, 4F, 3.2F, 3.8F,
3.7F, 3.8F, 4.8F, 3.8F, 3.7F };
//EVERY BHP VALUE FOR EVERY CAR IN THE DECK
public int[] mAR_ST_BHP = { 500, 987, 381, 493, 493, 478, 352, 455, 450,
405, 360, 485, 276, 230, 350, 550, 542, 655,
627, 622, 276, 316, 450, 650, 425, 320, 500,
604, 400, 552, 542, 617 };
//EVERY CAPACITY VALUE FOR EVERY CAR IN THE DECK
public int[] mAR_ST_Capacity = { 8285, 7993, 3600, 4961, 5493, 2936, 2968, 5167, 2851, 5665,
3246, 6997, 3179, 1796, 3506, 7008, 3500, 4700, 6064, 5998,
1997, 1994, 5935, 5998, 3586, 1500, 5409, 5733, 3996, 5998,
7010, 5439 };
//EVERY WEIGHT FOR EVERY CAR IN THE DECK
public int[] mAR_ST_Weight = { 1542, 1600, 1650, 1520, 1880, 1100, 1080, 1447, 1450, 1413, 1460,
1148, 1270, 460, 1300, 1247, 1456, 1275, 1137, 1335, 1410, 1470,
1750, 1365, 1280, 325, 1519, 1380, 1100, 2385, 1250, 1693 };
public Deck()
{
for (int i = 0; i < 32; i++)
{
mCards.Add(new Card());
mCards[i].mCarName = mAR_ST_CarName[i];
mCards[i].mTopSpeed = mAR_ST_TopSpeed[i];
mCards[i].m0_60 = mAR_ST_0_60[i];
mCards[i].mBHP = mAR_ST_BHP[i];
mCards[i].mCapacity = mAR_ST_Capacity[i];
mCards[i].mWeight = mAR_ST_Weight[i];
}
}
}
public class Player
{
public List<Card> mPlayerHand = new List<Card>();
}
//BUTTON FOR PLAYER 1 FOR THEIR CARDS
private void buttonPlayer1_Click(object sender, EventArgs e)
{
ShuffleDeck();
for (int i = 0; i < 16; i++)
{
comboBoxPlayer1.Items.Add(mdeck)
//comboBoxPlayer1.Items.Add(mDeck.mCards[i].mCarName);
// mDeck.mCards.Remove(mDeck.mCards[i]);
}
comboBoxPlayer1.SelectedIndex = 0;
buttonPlayer1.Enabled = false; //This kills the button after 1 click
}
//LISTBOX FOR PLAYER 1. DISPLAYS THE ATTRIBUTES
private void listBoxPlayer1_SelectedIndexChanged(object sender, EventArgs e)
{
}
//DROPDOWN FOR PLAYER 1. DISPLAYS CARDS
private void comboBoxPlayer1_SelectedIndexChanged(object sender, EventArgs e)
{
listBoxPlayer1.Items.Clear();
listBoxPlayer1.Items.Add(mDeck.mAR_ST_TopSpeed[comboBoxPlayer1.SelectedIndex] + " mph");
listBoxPlayer1.Items.Add(mDeck.mAR_ST_0_60[comboBoxPlayer1.SelectedIndex] + " seconds");
listBoxPlayer1.Items.Add(mDeck.mAR_ST_BHP[comboBoxPlayer1.SelectedIndex] + " BHP");
listBoxPlayer1.Items.Add(mDeck.mAR_ST_Capacity[comboBoxPlayer1.SelectedIndex] + " CC");
listBoxPlayer1.Items.Add(mDeck.mAR_ST_Weight[comboBoxPlayer1.SelectedIndex] + " Kg");
}
//PLAYER 2 BUTTON FOR THEIR CARDS
private void buttonPlayer2_Click(object sender, EventArgs e)
{
ShuffleDeck();
for (int i = 16; i < 32; i++)
{
comboBoxPlayer2.Items.Add(mDeck.mCards[i].mCarName);
}
comboBoxPlayer2.SelectedIndex = 0;
buttonPlayer2.Enabled = false; //This kills the button after 1 click
}
//LISTBOX FOR PLAYER 2. DISPLAYS THE ATTRIBUTES
private void listBoxPlayer2_SelectedIndexChanged(object sender, EventArgs e)
{
}
//DROPDOWN MENU FOR PLAYER 2. DISPLAYS CARDS
private void comboBoxPlayer2_SelectedIndexChanged(object sender, EventArgs e)
{
listBoxPlayer2.Items.Clear();
listBoxPlayer2.Items.Add(mDeck.mAR_ST_TopSpeed[comboBoxPlayer2.SelectedIndex] + " mph");
listBoxPlayer2.Items.Add(mDeck.mAR_ST_0_60[comboBoxPlayer2.SelectedIndex] + " seconds");
listBoxPlayer2.Items.Add(mDeck.mAR_ST_BHP[comboBoxPlayer2.SelectedIndex] + " BHP");
listBoxPlayer2.Items.Add(mDeck.mAR_ST_Capacity[comboBoxPlayer2.SelectedIndex] + " CC");
listBoxPlayer2.Items.Add(mDeck.mAR_ST_Weight[comboBoxPlayer2.SelectedIndex] + " Kg");
}
}
}
Im not expecting code answers, but any pointers or tips would be greatly appreciated.