Exemple #1
0
        private bool SetNewCoordinate(Coordinate coordinate)
        {
            if (!CoordinateHelper.IsNotWall(coordinate))
            {
                return(false);
            }

            if (CoordinateHelper.IsSnake(coordinate, ref snake))
            {
                return(false);
            }

            if (CoordinateHelper.IsFood(coordinate, food))
            {
                snake.Insert(0, food);
                GenerateFood();
                Moving();
            }
            else
            {
                snake.Insert(0, coordinate);
                snake.RemoveAt(snake.Count - 1);
            }

            return(true);
        }
Exemple #2
0
        private void GenerateFood()
        {
            Random rnd = new Random();

            do
            {
                food.x = rnd.Next(0, CoordinateHelper.maxWidth);
                food.y = rnd.Next(0, CoordinateHelper.maxHeight);
            } while (CoordinateHelper.IsSnake(food, ref snake) || !CoordinateHelper.IsNotWall(food));
        }
Exemple #3
0
        public void PlayingField()
        {
            Console.Clear();

            for (int y = 0; y <= CoordinateHelper.maxHeight; y++)
            {
                for (int x = 0; x <= CoordinateHelper.maxWidth; x++)
                {
                    if (x == 0 || y == 0 || x == CoordinateHelper.maxWidth || y == CoordinateHelper.maxHeight)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;

                        Console.Write(wall);

                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        if (CoordinateHelper.IsFood(x, y, foodCoordinate))
                        {
                            Console.ForegroundColor = ConsoleColor.Cyan;

                            Console.Write(food);

                            Console.ForegroundColor = ConsoleColor.White;
                        }
                        else if (CoordinateHelper.IsSnake(x, y, ref snakeCoordinate))
                        {
                            Console.ForegroundColor = ConsoleColor.Green;

                            Console.Write(bodySnake);

                            Console.ForegroundColor = ConsoleColor.White;
                        }
                        else
                        {
                            Console.Write(nothing);
                        }
                    }
                }
                Console.WriteLine();
            }
        }