Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int tracklength = 330;
            int s1Position  = 0;
            int s2Postition = 0;

            Snail s1 = new Snail(10, 20, "James");
            Snail s2 = new Snail(12, 18, "Jim");

            Console.WriteLine("Welcome to Snail Race! Now it's off to the races!");

            //Loop until a snail has finished
            while (s1Position < tracklength && s2Postition < tracklength)
            {
                int move1 = s1.Move();
                s1Position += move1;
                int move2 = s2.Move();
                s2Postition += move2;
                Console.WriteLine(s1.ToString() + " moves " + move1 + " for a total of " + s1Position);
                Console.WriteLine(s2.ToString() + " moves " + move2 + " for a total of " + s2Postition);
            }

            //Calculate winner
            if (s1Position >= 330 && s2Postition >= 330)
            {
                Console.WriteLine("It's a tie!");
            }
            else if (s1Position >= 330)
            {
                Console.WriteLine(s1.ToString() + " wins the race!");
            }
            else if (s2Postition >= 330)
            {
                Console.WriteLine(s2.ToString() + " wins the race!");
            }
            else
            {
                Console.WriteLine("Uh oh, something went wrong");
            }

            Console.WriteLine("Press any key to exit.");
            ConsoleKey repeatAnswer = Console.ReadKey().Key;
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int tracklength = 330;

            int positionSnailOne = 0;
            int positionSnailTwo = 0;

            string snailOneName;
            string snailTwoName;

            int snailOneMinSpeed;
            int snailOneMaxSpeed;

            int snailTwoMinSpeed;
            int snailTwoMaxSpeed;



            Console.WriteLine("Welcome to the races!");
            Console.WriteLine("");
            Console.WriteLine("What is the first snail name?");
            snailOneName = Console.ReadLine();
            Console.WriteLine("What is the first snails minimum speed?");
            snailOneMinSpeed = Int32.Parse(Console.ReadLine());
            Console.WriteLine("What is the first snails maximum speed?");
            snailOneMaxSpeed = Int32.Parse(Console.ReadLine());

            Console.WriteLine("What is the second snail name?");
            snailTwoName = Console.ReadLine();
            Console.WriteLine("What is the second snails minimum speed?");
            snailTwoMinSpeed = Int32.Parse(Console.ReadLine());
            Console.WriteLine("What is the second snails maximum speed?");
            snailTwoMaxSpeed = Int32.Parse(Console.ReadLine());


            if (snailOneMinSpeed > snailOneMaxSpeed)
            {
                int tempInt = snailOneMinSpeed;
                snailOneMinSpeed = snailOneMaxSpeed;
                snailOneMaxSpeed = tempInt;
            }

            if (snailTwoMinSpeed > snailTwoMaxSpeed)
            {
                int tempInt = snailTwoMinSpeed;
                snailTwoMinSpeed = snailTwoMaxSpeed;
                snailTwoMaxSpeed = tempInt;
            }



            var snailOne = new Snail(snailOneMinSpeed, snailOneMaxSpeed, snailOneName);
            var snailTwo = new Snail(snailTwoMinSpeed, snailTwoMaxSpeed, snailTwoName);

            Console.WriteLine("On your marks!");
            Thread.Sleep(200);
            Console.WriteLine("Get set!");
            Thread.Sleep(200);
            Console.WriteLine("GO!");

            while (positionSnailOne < tracklength || positionSnailTwo < tracklength)
            {
                int snailOneTravel;
                snailOneTravel    = snailOne.Move();
                positionSnailOne += snailOneTravel;

                Console.WriteLine($"{snailOne.ToString()} has moved {snailOneTravel}mm to {positionSnailOne}mm");

                if (positionSnailOne > tracklength)
                {
                    Console.WriteLine($"{snailOne.ToString()} wins!");
                    break;
                }
                Thread.Sleep(400);

                int snailTwoTravel;
                snailTwoTravel    = snailTwo.Move();
                positionSnailTwo += snailTwoTravel;

                Console.WriteLine($"{snailTwo.ToString()} has moved {snailTwoTravel}mm to {positionSnailTwo}mm");

                if (positionSnailTwo > tracklength)
                {
                    Console.WriteLine($"{snailTwo.ToString()} wins!");
                    break;
                }
                Thread.Sleep(400);
                Console.WriteLine("Next round!");
            }

            Console.ReadKey();
        }