Exemplo n.º 1
0
        public void StartGame()
        {
            run = true;
            wall.LoadLevel(1);
            // draw it only once
            wall.Draw();

            while (run)
            {
                serpent.Draw();
                food.Draw();
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow:
                    // Clear before moving because if serpent moves first, we cannot clear properly
                    serpent.Clear();
                    serpent.Move(Direction.Up);
                    CheckFoodCatch();
                    break;

                case ConsoleKey.DownArrow:
                    serpent.Clear();
                    serpent.Move(Direction.Down);
                    CheckFoodCatch();
                    break;

                case ConsoleKey.LeftArrow:
                    serpent.Clear();
                    serpent.Move(Direction.Left);
                    CheckFoodCatch();
                    break;

                case ConsoleKey.RightArrow:
                    serpent.Clear();
                    serpent.Move(Direction.Right);
                    CheckFoodCatch();
                    break;

                case ConsoleKey.Escape:
                    run = false;
                    break;

                default:
                    break;
                }
            }

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(19, 19);
            Console.Write("GAME OVER");
        }
Exemplo n.º 2
0
        private void DrawAndMoveGameObjects()
        {
            while (true)
            {
                // move and other logic
                serpent.Clear();
                serpent.Move();
                CheckFoodCatch();

                // draw
                serpent.Draw();
                food.Draw();

                // This parameter defines speed of movement
                Thread.Sleep(200);
            }
        }