我是C#的新手,我想做一个纸牌游戏.我有什么是卡(串)有了这样一份名单c6, s3, h11, d13,其中character represents the colour和number represents the value.当按下按钮时,程序从列表中获取随机字符串并将其显示在文本框中.从那里开始,游戏的目的是猜测下一张随机卡是否会比之前的卡具有更高的值或更低的值.
我想要做的是从文本框中取出字符串并将其转换为int,以便我可以将前一张卡的值与新卡的值进行比较.唯一的问题是我如何摆脱cin c6所以我可以通过使用转换它parse.
这是我的代码.
public partial class MainWindow : Window
{
static Random rndmlist = new Random();
Random rndm = new Random();
List<string> deck = new List<string>();
int score = 0;
public MainWindow()
{
InitializeComponent();
}
private void test_Click(object sender, RoutedEventArgs e)
{
//disregard this
foreach (string j in deck)
{
testbox.Text += j + ", ";
}
}
private void btnstart_Click(object sender, RoutedEventArgs e)
{
//this is where i add all the cards to the list
for (int i = 1; i <= 13;)
{
deck.Add("c" + i);
i++;
}
for (int i = 1; i <= 13; )
{
deck.Add("s" + i);
i++;
}
for (int i = 1; i <= 13; )
{
deck.Add("h" + i);
i++;
}
for (int i = 1; i <= 13; )
{
deck.Add("d" + i);
i++;
}
}
private void btnbegin_Click(object sender, RoutedEventArgs e)
{
//this is where i take a random card from the list and display it in textBox2
int r = rndmlist.Next(deck.Count);
textBox2.Text = ((string)deck[r]);
//disregard this
testbox.Text += ((string)deck[r]) + ", ";
deck.Remove((string)deck[r]);
}
private void btnhigh_Click(object sender, RoutedEventArgs e)
{
//this is where i want to compare the cards.
}
}
Run Code Online (Sandbox Code Playgroud)
提前感谢您阅读本文.(:
| 归档时间: |
|
| 查看次数: |
7271 次 |
| 最近记录: |