PDA

ดูเวอร์ชั่นเต็ม : ช่วยหน่อยครับ C# Windows Forms



tsm113za
5th March 2014, 22:23
เขียนเกมนี้ครับ http://mathminton.blogspot.com/2011/07/count-game.html นับ 1 - 20 แต่ทำนับเป็นแค่หลักหน่วยต้องแก้ตรงไหนหรือเพิ่มอะไรจึงจะนับถึง 20 ครับ

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string s = textBox1.Text;
char[] c = s.ToCharArray();
string total = "";
string t = "";
int sum;

if (s.Length == 1)
{
t = s.Substring(0, 1);
for (int i = 1; i <= 3; i++)
{
int j = int.Parse(t);
sum = j + i;
total += sum.ToString() + "";
if (sum == 20)
{
MessageBox.Show("You Lose");
break;
}
}
textBox2.Text = total;
}
else if (s.Length == 3)
{
t = s.Substring(2, 1);
for (int i = 1; i <= 2; i++)
{
int j = int.Parse(t);
sum = j + i;
total += sum.ToString() + "";
if (sum == 20)
{
MessageBox.Show("You Lose");
break;
}
}
textBox2.Text = total;
}
else if (s.Length == 5)
{
t = s.Substring(4, 1);
for (int i = 1; i <= 1; i++)
{
int j = int.Parse(t);
sum = j + i;
total += sum.ToString() + "";
if(sum == 20)
{
MessageBox.Show("You Lose");
break;
}
}
textBox2.Text = total;
}
else
MessageBox.Show("Enter Again Number");
textBox1.Clear();
textBox1.Focus();
}
}
}