close

『目標』做出一個隨機骰子,其結果將決定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
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
int d1, d2,r;
Random ran = new Random() ;
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);

label1.Text = Convert.ToString(d1);
textBox1.Text = Convert.ToString(d2);
for (int i = 1; i <= d1+d2; i++)
{

//Console.WriteLine(i);
Thread.Sleep(1000); //Delay 1秒
button1.Left = i;
Application.DoEvents();

}

if (button1.Left>=15)
MessageBox.Show("甲贏");
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
int d1, d2;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
textBox1.Text = Convert.ToString(d2);
for (int i = 1; i <= d1 + d2; i++)
{
//Console.WriteLine(i);
Thread.Sleep(1000); //Delay 1秒
button3.Left = i;
Application.DoEvents();
}
if (button3.Left >= 15)
MessageBox.Show("乙贏");
}
}
}

arrow
arrow
    全站熱搜

    wadj223436 發表在 痞客邦 留言(0) 人氣()