Exemplo n.º 1
0
        public void CorrerMain(object i)
        {
            Caballo horse = (Caballo)i;

            Console.SetCursorPosition(0, caballos.Length + 1);
            Console.Write(empty);

            while (!meta)
            {
                Thread.Sleep(random.Next(1, 350));

                lock (l)
                {
                    if (!meta)
                    {
                        Console.SetCursorPosition(horse.Correr(), horse.Y);
                        Console.Write("*");

                        if (horse.Position == horse.Finishline)
                        {
                            meta   = true;
                            winner = horse.Number;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void MakeFinishline()
        {
            Caballo horse = new Caballo(0, 0);

            for (int i = 0; i < caballos.Length; i++)
            {
                Console.SetCursorPosition(0, i); // Cleans the last horse race to make room for a new one
                Console.Write(empty);
            }

            for (int i = 0; i < caballos.Length; i++)
            {
                Console.SetCursorPosition(horse.Finishline, i);
                Console.WriteLine("||");
            }
        }
Exemplo n.º 3
0
        public void StartCarrera()
        {
            Thread[] carrera = new Thread[maxNumber];
            Caballo  caballo;

            caballos = new Caballo[maxNumber];
            int number = 1;

            for (int i = 0; i < caballos.Length; i++)
            {
                caballo     = new Caballo((i + 1), i);
                caballos[i] = caballo;
                carrera[i]  = new Thread(CorrerMain);
                carrera[i].Start(caballos[i]);
                number = i;
            }

            for (int i = 0; i < caballos.Length; i++)
            {
                carrera[i].Join();
            }

            if (meta)
            {
                Console.SetCursorPosition(0, caballos.Length + 1);
                Console.WriteLine($"\n--> The winner is {winner}!");

                if (bet == winner)
                {
                    Console.Write(empty);
                    Console.WriteLine("You won the bet!!!");
                }
                else
                {
                    Console.Write(empty);
                    Console.WriteLine("You lost the bet...");
                }

                RunAgain();
            }
        }