保存随机生成的数字进行比较

时间:2013-04-30 17:28:03

标签: c# comparison storage

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

1 个答案:

答案 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