예제 #1
0
파일: Form1.cs 프로젝트: cmwldysz/superman
        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();
        }
예제 #2
0
파일: Form1.cs 프로젝트: cmwldysz/superman
        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();
        }
예제 #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!");
        }
    }