Ejemplo n.º 1
0
        private static void GetMovementDirection()
        {
            Timer1 = DateTime.Now;

            while (true)
            {
                Timer2 = DateTime.Now;
                if (Timer2.Subtract(Timer1).TotalMilliseconds > timestep)
                {
                    break;
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey(true);
                    if (keyInfo.Key.Equals(ConsoleKey.UpArrow) && curent_directionP1 != Moving_directions.Down)
                    {
                        curent_directionP1 = Moving_directions.Up;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.RightArrow) && curent_directionP1 != Moving_directions.Left)
                    {
                        curent_directionP1 = Moving_directions.Right;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.DownArrow) && curent_directionP1 != Moving_directions.Up)
                    {
                        curent_directionP1 = Moving_directions.Down;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.LeftArrow) && curent_directionP1 != Moving_directions.Right)
                    {
                        curent_directionP1 = Moving_directions.Left;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.W) && curent_directionP2 != Moving_directions.Down)
                    {
                        curent_directionP2 = Moving_directions.Up;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.A) && curent_directionP2 != Moving_directions.Right)
                    {
                        curent_directionP2 = Moving_directions.Left;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.S) && curent_directionP2 != Moving_directions.Up)
                    {
                        curent_directionP2 = Moving_directions.Down;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.D) && curent_directionP2 != Moving_directions.Left)
                    {
                        curent_directionP2 = Moving_directions.Right;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private static void GetMovementDirection()
 {
     Timer1     = DateTime.Now;
     KeyPressed = false;
     while (true)
     {
         Timer2 = DateTime.Now;
         if (Timer2.Subtract(Timer1).TotalMilliseconds > timestep)
         {
             break;
         }
         if (Console.KeyAvailable)
         {
             ConsoleKeyInfo keyInfo = Console.ReadKey(true);
             if (keyInfo.Key.Equals(ConsoleKey.UpArrow) && curent_direction != Moving_directions.Down && KeyPressed == false)
             {
                 curent_direction = Moving_directions.Up;
                 KeyPressed       = true;
             }
             else if (keyInfo.Key.Equals(ConsoleKey.RightArrow) && curent_direction != Moving_directions.Left && KeyPressed == false)
             {
                 curent_direction = Moving_directions.Right;
                 KeyPressed       = true;
             }
             else if (keyInfo.Key.Equals(ConsoleKey.DownArrow) && curent_direction != Moving_directions.Up && KeyPressed == false)
             {
                 curent_direction = Moving_directions.Down;
                 KeyPressed       = true;
             }
             else if (keyInfo.Key.Equals(ConsoleKey.LeftArrow) && curent_direction != Moving_directions.Right && KeyPressed == false)
             {
                 curent_direction = Moving_directions.Left;
                 KeyPressed       = true;
             }
         }
     }
 }