예제 #1
0
        public void EnemyEatFood(FoodPoint foodPoint, int id, Guid id_player)
        {
            var food = FoodPoints.FirstOrDefault(i => i.ID == id);

            FoodPoints.Remove(food);
            FoodPoints.Add(foodPoint);

            var player = EnemyPlayers.FirstOrDefault(i => i.ID == id_player);

            if (player != null)
            {
                player.Size++;
                player.Score++;
            }

            PlayerEvents.GetInstance().EnemyEatFood();
        }
예제 #2
0
        private void CheckIfThereSomeFood()
        {
            var foodPoint = FoodPoints.FirstOrDefault(f => f.PointColumn == Console.CursorLeft &&
                                                      f.PointRow == Console.CursorTop);

            if (foodPoint == null)
            {
                return;
            }

            FoodPoints.Remove(foodPoint);
            IncrementCounter();

            if (!FoodPoints.Any())
            {
                WinGame();
            }
        }
예제 #3
0
        public UpdateStatus MoveingSnake(Direction dir)
        {
            var snakeHead = SnakeBodyPoints.First();

            Point newHead = dir switch
            {
                Direction.Up => new Point(snakeHead.Left, snakeHead.Top - 1),
                Direction.Down => new Point(snakeHead.Left, snakeHead.Top + 1),
                Direction.Left => new Point(snakeHead.Left - 2, snakeHead.Top),
                Direction.Right => new Point(snakeHead.Left + 2, snakeHead.Top),
                _ => null,
            };

            if (newHead.Left != 0 && newHead.Left != PlayGroundWidth && newHead.Top != 0 && newHead.Top != PlayGroundHeight - 1)
            {
                SnakeBodyPoints.Insert(0, newHead);


                var flag = true;
                foreach (var item in FoodPoints.ToList())
                {
                    if (newHead == item)
                    {
                        FoodPoints.Remove(item);
                        flag = false;
                    }
                }

                if (flag)
                {
                    SnakeBodyPoints.Remove(SnakeBodyPoints.Last());
                }

                if (FoodPoints.Count() == 0)
                {
                    return(UpdateStatus.EndOfFoods);
                }
                return(UpdateStatus.ateFood);
            }
            else
            {
                return(UpdateStatus.BoardersHited);
            }
        }