示例#1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            txtBoxRace.Clear();
            Turtle turtle = new Turtle("Turtle");
            Liebre liebre = new Liebre("Rabbit");

            race(turtle, liebre);
        }
示例#2
0
 private void ganador(int holderT, int holderL, Turtle turtle, Liebre liebre)
 {
     if (holderT > holderL)
     {
         txtBoxRace.Text += "GANADOR: " + turtle.name.ToUpper();
     }
     else if (holderL < holderT)
     {
         txtBoxRace.Text += "GANADOR: " + liebre.name.ToUpper();
     }
     else
     {
         txtBoxRace.Text += "EMPATE";
     }
 }
示例#3
0
        private void race(Turtle turtle, Liebre liebre)
        {
            int holderTurtle = 0;
            int holderLiebre = 0;

            while (holderTurtle < 80 && holderLiebre < 80)
            {
                holderTurtle += turtle.pasos();
                holderLiebre += liebre.pasos();

                txtBoxRace.Text += turtle.name + " ha dado: " + holderTurtle + " pasos" +
                                   Environment.NewLine + liebre.name + " ha dado: " + holderLiebre + " pasos" +
                                   Environment.NewLine + "----------------------------------------" +
                                   Environment.NewLine;
            }
            ganador(holderTurtle, holderLiebre, turtle, liebre);
        }