2014年10月23日 星期四

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 ssum1 = 0;
        int ssum2 = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, d2,dsum1;
            Random ran = new Random();
            d1 = ran.Next(1, 7);
            d2 = ran.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            dsum1 = d1 + d2;
           
            for (int i = 1; i <= dsum1; i++)
            {

                Thread.Sleep(200); //Delay 1秒
                button2.Left = (ssum1+i)*5;
                Application.DoEvents();
            }
            ssum1 = ssum1 + dsum1;
            textBox1.Text = Convert.ToString(ssum1);
            if (ssum1 >= 80)
            {
                textBox2.Text = "button1 win";
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            int d1, d2, dsum2;
            Random ran = new Random();
            d1 = ran.Next(1, 7);
            d2 = ran.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            dsum2 = d1 + d2;

            for (int i = 1; i <= dsum2; i++)
            {

                Thread.Sleep(200); //Delay 1秒
                button4.Left = (ssum2 + i) * 5;
                Application.DoEvents();
            }
            ssum2 = ssum2 + dsum2;
            textBox1.Text = Convert.ToString(ssum2);
            if (ssum2 >= 80)
            {
                textBox2.Text = "button2 win";
            }
        }
    }
}
========================================================================

========================================================================