Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     //Console.SetWindowSize(100, 80);
     int dist = 500;
     int[,] players = new int[4, 2];
     Random rand = new Random();
     Sport sp = new Sport();
     MySpeedUpEvent up = new MySpeedUpEvent();
     MySpeedDownEvent down = new MySpeedDownEvent();
     MyFinishEvent finish = new MyFinishEvent();
     Car[][] cars = new Car[4][];
     cars[0] = new Sport[4];
     cars[1] = new Passenger[4];
     cars[2] = new Bus[4];
     cars[3] = new Truck[4];
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             finish.FinishEvent += cars[i][j].Finish;
         }
     }
     do
     {
         for (int i = 0; i < 4; i++)
         {
             players[i, 0] = rand.Next() % 4;
             players[i, 1] = rand.Next() % 4;
         }
         bool unic = true;
         do
         {
             unic = true;
             for (int i = 0; i < 3; i++)
             {
                 if (players[i, 0] == players[i + 1, 0])
                 {
                     if (players[i, 1] == players[i + 1, 1])
                     {
                         players[i, 1] = (players[i, 1] + 1) % 4;
                         unic = false;
                     }
                 }
             }
         } while (!unic);
         for (int i = 0; i < 4; i++)
         {
             for (int j = 0; j < 4; j++)
             {
                 up.SpeedUpEvent += cars[i][j].ChangeSpeed;
                 down.SpeedDownEvent += cars[i][j].ChangeSpeed;
             }
         }
         while (!IsFinish(cars, dist))
         {
             //продвижение
             Show();
             Thread.Sleep(10);
         }
         Thread.Sleep(5000);
         finish.OnFinishEvent();
     } while (true);
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Console.SetWindowSize(100, 80);
            int dist = 500;

            int[,] players = new int[4, 2];
            Random           rand   = new Random();
            Sport            sp     = new Sport();
            MySpeedUpEvent   up     = new MySpeedUpEvent();
            MySpeedDownEvent down   = new MySpeedDownEvent();
            MyFinishEvent    finish = new MyFinishEvent();

            Car[][] cars = new Car[4][];
            cars[0] = new Sport[4];
            cars[1] = new Passenger[4];
            cars[2] = new Bus[4];
            cars[3] = new Truck[4];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    finish.FinishEvent += cars[i][j].Finish;
                }
            }
            do
            {
                for (int i = 0; i < 4; i++)
                {
                    players[i, 0] = rand.Next() % 4;
                    players[i, 1] = rand.Next() % 4;
                }
                bool unic = true;
                do
                {
                    unic = true;
                    for (int i = 0; i < 3; i++)
                    {
                        if (players[i, 0] == players[i + 1, 0])
                        {
                            if (players[i, 1] == players[i + 1, 1])
                            {
                                players[i, 1] = (players[i, 1] + 1) % 4;
                                unic          = false;
                            }
                        }
                    }
                } while (!unic);
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        up.SpeedUpEvent     += cars[i][j].ChangeSpeed;
                        down.SpeedDownEvent += cars[i][j].ChangeSpeed;
                    }
                }
                while (!IsFinish(cars, dist))
                {
                    //продвижение
                    Show();
                    Thread.Sleep(10);
                }
                Thread.Sleep(5000);
                finish.OnFinishEvent();
            } while (true);
        }