10/24方塊賽跑
using System;
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;
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
int totalSum1 = 0;
int totalSum2 = 0;
{
public partial class Form1 : Form
{
int totalSum1 = 0;
int totalSum2 = 0;
public Form1()
{
InitializeComponent();
}
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2,sum;//第一個方塊
int D1, D2, SUM;//第二個方塊
Random ran = new Random();
{
int d1, d2,sum;//第一個方塊
int D1, D2, SUM;//第二個方塊
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
D1 = ran.Next(1, 7);
D2 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
D1 = ran.Next(1, 7);
D2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
label3.Text = Convert.ToString(D1);
label4.Text = Convert.ToString(D2);
sum = d1 + d2;
SUM = D1 + D2;
for (int i = 1; i <= sum; i++)
{
button2.Left = (i+totalSum1)*5;
Thread.Sleep(50);//delay 1 秒
Application.DoEvents();
label2.Text = Convert.ToString(d2);
label3.Text = Convert.ToString(D1);
label4.Text = Convert.ToString(D2);
sum = d1 + d2;
SUM = D1 + D2;
for (int i = 1; i <= sum; i++)
{
button2.Left = (i+totalSum1)*5;
Thread.Sleep(50);//delay 1 秒
Application.DoEvents();
}//第一個方快走的
totalSum1 += sum;//總步數
textBox1.Text = Convert.ToString(totalSum1);
totalSum1 += sum;//總步數
textBox1.Text = Convert.ToString(totalSum1);
for (int i = 1; i <= SUM; i++)
{
button3.Left = (i+totalSum2)*5;
Thread.Sleep(50);//delay 1 秒
Application.DoEvents();
}//第二個方快走的
totalSum2 += SUM;//總步數
textBox2.Text = Convert.ToString(totalSum2);
{
button3.Left = (i+totalSum2)*5;
Thread.Sleep(50);//delay 1 秒
Application.DoEvents();
}//第二個方快走的
totalSum2 += SUM;//總步數
textBox2.Text = Convert.ToString(totalSum2);
if (totalSum1 > 50 && totalSum2 > 50)
{
if (totalSum1 > totalSum2)
{
MessageBox.Show("第一個贏了");
}
else if (totalSum1 < totalSum2)
MessageBox.Show("第二個贏了");
else
MessageBox.Show("平手");
}
{
if (totalSum1 > totalSum2)
{
MessageBox.Show("第一個贏了");
}
else if (totalSum1 < totalSum2)
MessageBox.Show("第二個贏了");
else
MessageBox.Show("平手");
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
{
}
}
}
}
}
0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁