private void chanceCard_Click(object sender, EventArgs e)
{
ccards = new ChanceCard();
MessageBox.Show("Chance Card: " + ccards.ChanceCardNumber());
ccards = new ChanceCard();
MessageBox.Show("Opponent's Chance Card: " + ccards.ChanceCardNumber());
我正在用C#创建一个顶级王牌游戏,我是GUI编程的新手。基本上我想知道如何生成两张随机机会卡(如上所示)并存储它们,这样我就可以比较它们,所以第一张机会卡分配给int yourChanceCard
而第二张是{{1}所以我可以稍后比较它们。所以:
int pcChanceCard
答案 0 :(得分:0)
如果你的主类有两个成员变量,那么:
class MyProgram
{
ChanceCard mine;
ChanceCard opponent;
//getters / setters
}
您可以这样做:
private void chanceCard_Click(object sender, EventArgs e)
{
mine = new ChanceCard();
MessageBox.Show("Chance Card: " + mine.ChanceCardNumber());
opponent = new ChanceCard();
MessageBox.Show("Opponent's Chance Card: " + opponent.ChanceCardNumber());
}
最后
if mine > opponent
{
blahblahblah
}
else
Blah