Exemple #1
0
        static void Main(string[] args)
        {
            Console.Clear();
            Console.CursorVisible = false;

            var snake = Snakes.First();

            snake.Position = Vector2.One;
            snake.Draw();

            UpdateScore(snake);

            Thread inputThread = new Thread(InputLoop);

            inputThread.Start();

            CreateNewFood();
        }
Exemple #2
0
        static void InputLoop()
        {
            while (Run)
            {
                float speedModifier = 1;

                var key   = Console.ReadKey(true);
                var snake = Snakes.First();

                foreach (var food in Foods)
                {
                    food.Draw();
                }

                UpdateScore(snake);

                switch (key.Key)
                {
                case ConsoleKey.W:
                    snake.Move(new Vector2(0, -1) * speedModifier);
                    break;

                case ConsoleKey.A:
                    snake.Move(new Vector2(-1, 0) * speedModifier);
                    break;

                case ConsoleKey.D:
                    snake.Move(new Vector2(1, 0) * speedModifier);
                    break;

                case ConsoleKey.S:
                    snake.Move(new Vector2(0, 1) * speedModifier);
                    break;
                }
            }
        }