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); }
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(); } }