我对 C# 很陌生,我想做一个纸牌游戏。我所拥有的是一个卡片列表(字符串),其名称如c6, s3, h11, d13
wherecharacter represents the colour
和number represents the value
. 当按下按钮时,程序会从列表中获取一个随机字符串并将其显示在文本框中。从那里开始,游戏的重点是猜测下一张随机牌的值是比前一张牌高还是低。
我想要做的是从文本框中获取字符串并将其转换为 int,以便我可以将前一张卡的值与新卡进行比较。唯一的问题是我如何摆脱c
inc6
以便我可以使用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.
}
}
预先感谢您阅读本文。(: