保存随机生成的数字以进行比较
本文关键字:比较 数字 随机 保存 | 更新日期: 2023-09-27 18:11:45
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
如果你的主类有两个成员变量,如:
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