using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
int s1sum = 0;
int s2sum = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//button1=User1,button2=Car1
int dsum, d1, d2;
//d1=骰子1,d2=骰子2,dsum=兩個骰子總合
Random iran = new Random();
d1 = iran.Next(1, 7);
//隨機變數1~6
d2 = iran.Next(1, 7);
//隨機變數1~6
label1.Text = Convert.ToString(d1);
//骰子1點數
label2.Text = Convert.ToString(d2);
//骰子2點數
dsum = d1 + d2;
for (int i = 1; i <= dsum; i++)
{
button2.Left = (s1sum + i) * 5;
Thread.Sleep(100);
Application.DoEvents();
}
s1sum = s1sum + dsum;
textBox1.Text = Convert.ToString(dsum);
textBox2.Text = Convert.ToString(s1sum);
//textBox2表示Cra1總共走了多少步
if (button2.Left >= 350)
{
MessageBox.Show("User1 Win.");
//當Car1到達終點時顯示User1 Win.
}
}
private void button4_Click(object sender, EventArgs e)
{
//button4=User2,button3=Car2
int dsum, d1, d2;
//d1=骰子1,d2=骰子2,dsum=兩個骰子總合
Random iran = new Random();
d1 = iran.Next(1, 7);
//隨機變數1~6
d2 = iran.Next(1, 7);
//隨機變數1~6
label1.Text = Convert.ToString(d1);
//骰子1點數
label2.Text = Convert.ToString(d2);
//骰子2點數
dsum = d1 + d2;
for (int i = 1; i <= dsum; i++)
{
button3.Left = (s2sum + i) * 5;
Thread.Sleep(100);
Application.DoEvents();
}
s2sum = s2sum + dsum;
textBox1.Text = Convert.ToString(dsum);
textBox2.Text = Convert.ToString(s2sum);
//textBox2表示Cra2總共走了多少步
if (button3.Left >= 350)
{
MessageBox.Show("User2 Win.");
//當Car2到達終點時顯示User2 Win.
}
}
}
}
沒有留言:
張貼留言