I am working on a program in C# where you have a button, and it will choose two random cards from a pre-determined selection. For example, I'm starting off with 5 cards that will be chosen from: the Ace of Spades, Seven of Spades, Ace of Hearts, Five of Clubs and Two of Diamonds. Now it will compare these two cards determine which card is higher and will make it be the winner, with Spades > Hearts > Clubs > Diamonds and Ace being low. So a Ace of Spades will win over a Two of Diamonds. I have made a CardClass where I set the Suits and Ranks:
public enum Suits
{
Spades,
Hearts,
Clubs,
Diamonds
}
public enum Ranks
{
Ace,
_2,
_3,
_4,
_5,
_6,
_7,
_8,
_9,
_10,
Jacks,
Queen,
King
}
//Private instance variables suit and rank
private Suits suit;
private Ranks rank;
//Provide properties for suit and rank that insure they can only be set to valid values
public Suits Suit
{
get
{
return this.suit;
}
set
{
this.suit = value;
}
}
public Ranks Rank
{
get
{
return this.Rank;
}
set
{
this.rank = value;
}
}
//Provide a default constructor (no parameters) that sets the card to Ace of Spades.
public CardClass()
{
// Use the properties to set these values
this.Rank = Ranks.Ace;
this.Suit = Suits.Spades;
}
// Provide an explicit constructor with parameters for ALL instance variables.
public CardClass(Ranks rank, Suits suit)
{
//Use the properties to set these values
this.Rank = rank;
this.Suit = suit;
}
Now for my button click, I set it so it will choose 2 different numbers, one for player 1 and one for player 2:
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int play1choice, play2choice;
private void btnCard_Click(object sender, EventArgs e)
{
Random player1 = new Random();
int Player1 = (player1.Next(5) + 1);
Random player2 = new Random();
int Player2 = (player2.Next(5) + 1);
}
}
}
Is there a way to set certain cards for the numbers? So if the random number generator picks 1 it will assign it to Ace of Spades, and 2 make it Seven of Spades, etc. ?