目標 : 做出一個隨機骰子,其結果將決定Player1、Player2前進步數,順序輪流且至設定終點時跳出勝利宣告。
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int ssum;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2,dsum;
Random irand=new Random();
d1=irand.Next(1,7);
d2=irand.Next(1,7);
label1.Text=Convert.ToString(d1);
label2.Text=Convert.ToString(d2);
dsum=d1+d2;
for (int i = 1; i <= d1 + d2; i++)
{
Thread.Sleep(100);
Application.DoEvents();
button2.Left = i+ssum;
}
ssum=ssum+dsum;
textBox1.Text = Convert.ToString(ssum);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
int ssum;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2,dsum;
Random irand=new Random();
d1=irand.Next(1,7);
d2=irand.Next(1,7);
label1.Text=Convert.ToString(d1);
label2.Text=Convert.ToString(d2);
dsum=d1+d2;
for (int i = 1; i <= d1 + d2; i++)
{
Thread.Sleep(100);
Application.DoEvents();
button2.Left = i+ssum;
}
ssum=ssum+dsum;
textBox1.Text = Convert.ToString(ssum);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
沒有留言:
張貼留言