Пример #1
0
 void Tick()
 {
     Console.Clear();
     _gameBoard.Draw();
     _snake.Move();
     if (_snake.Eat(_gameBoard.Food.Item1, _gameBoard.Food.Item2))
     {
         _gameBoard.RandomizeFood(_snake.GetSnake());
         _score += 10;
     }
     _snake.Draw();
     _turned = false;
     Console.SetCursorPosition(_gameBoard.Width + 2, 1);
     Console.Write($"Score: {_score}");
     Console.SetCursorPosition(0, 0);
     if (!_snake.Collided(0, _gameBoard.Width, 0, _gameBoard.Height))
     {
         ScheduleNextTick();
     }
     else
     {
         Console.SetCursorPosition(_gameBoard.Width + 2, 3);
         Console.Write("Game Over!");
     }
 }
Пример #2
0
        private void DefineIfReplacements()
        {
            Collisionables.Add(typeof(EmptyBlock), (gameAux, otherBlock) => { });
            Collisionables.Add(typeof(FoodBlock), (gameAux, otherBlock) =>
            {
                Console.WriteLine("Snake was on " + Snake + " when eated!");
                otherBlock.Collided(game);
                Snake.Collided(game);
                GenerateFood();
            });
            Collisionables.Add(typeof(SnakeBlock), (gameAux, otherBlock) =>
            {
                Console.WriteLine("Snake was on " + Snake + " when collisioned with " + otherBlock + "!");
                game.GameEnds();
            });

            MatrixFinderActions.Add(true, (x, y) => { return(new int[] { x, y }); });
            //MatrixFinderActions.Add(false, (x, y) => { return new int[] { x, y }; });

            ChangeSnakeDirectionActionSelector.Add(true, (newDirection) => { return(newDirection); });
            ChangeSnakeDirectionActionSelector.Add(false, (newDirection) => { return(Direction); });
        }