Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            Rabbit   rabbit   = new Rabbit();
            Tortoise tortoise = new Tortoise();
            Thread   t1       = new Thread(() => rabbit.Run(this.richTextBox1));
            Thread   t2       = new Thread(() => tortoise.Run(this.richTextBox2));

            t1.Start();
            t2.Start();
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Thread t1 = new Thread(() => Run(this.textBox1));
            //t1.Name = "兔子";
            //Thread t2 = new Thread(() => Run(this.textBox2));
            //t2.Name = "乌龟";
            //t1.Start();
            //t2.Start();
            Rabbit   rabbit   = new Rabbit();
            Tortoise tortoise = new Tortoise();
            Thread   t1       = new Thread(() => rabbit.Run(this.textBox1));
            Thread   t2       = new Thread(() => tortoise.Run(this.textBox2));

            t1.Start();
            t2.Start();
        }
Ejemplo n.º 3
0
    public void StartRace()
    {
        int tortoisePosition = 0;
        int harePosition     = 0;

        Console.WriteLine("Hare{0, 55}", "Tortoise");
        while (tortoisePosition < raceTrackLength && harePosition < raceTrackLength)
        {
            harePosition += hare.Run();
            Console.Write("{0, 30}", "");
            tortoisePosition += tortoise.Run();
            Console.WriteLine();
            System.Threading.Thread.Sleep(250);
        }

        if (tortoisePosition > harePosition)
        {
            Console.WriteLine("The tortoise has won the race!");
        }
        else
        {
            Console.WriteLine("The hare has won the race!");
        }
    }