1
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,第二张是int pcChanceCard这样我以后可以比较它们。所以:

if yourChanceCard > pcChanceCard
{
    blahblahblah
}
else
    Blah
4

1 回答 1

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
于 2013-04-30T17:33:18.417 回答