Пример #1
0
        internal void Remove(Snake snake, Snake.Direction direction)      //Only happens if the snake is crashing into the wall...
        {
            switch (direction)
            {
            case Snake.Direction.Down: snake.snakeBody.First().Y -= 1; break;

            case Snake.Direction.Up: snake.snakeBody.First().Y += 1; break;

            case Snake.Direction.Left: snake.snakeBody.First().X += 1; break;

            case Snake.Direction.Right: snake.snakeBody.First().X -= 1; break;
            }

            Player p = (Player)collidables[snake.snakeBody.First().X, snake.snakeBody.First().Y];

            p?.Remove(this);
        }
Пример #2
0
        public void Collide(Player player)          //Check if the player collides with itself.
        {
            if (collidables[player.snakeBody.First().X, player.snakeBody.First().Y] != null)
            {
                if (collidables[player.snakeBody.First().X, player.snakeBody.First().Y] is Player)
                {
                    player.Remove(this);

                    Player playerFromMatrix = (Player)collidables[player.snakeBody.First().X, player.snakeBody.First().Y];

                    if (playerFromMatrix.playerID != player.playerID)
                    {
                        playerFromMatrix.Score += 5;
                    }

                    if (Players.Count < 1)
                    {
                        GameOverEvent.Invoke(player.playerID);
                    }
                }
            }
        }