// Console Renderer's constructor public ConsoleRenderer(GameFieldCoords size) { this.InitializeGameField(size); this.gameFieldSize = size; this.consoleSize = new GameFieldCoords(this.gameFieldSize.Row + 2, this.gameFieldSize.Col + 21); this.highScores = FileOperator.ReadHighScoreFile(); Console.CursorVisible = false; Console.WindowHeight = this.consoleSize.Row; Console.BufferHeight = Console.WindowHeight; Console.WindowWidth = this.consoleSize.Col; Console.BufferWidth = Console.WindowWidth; this.InitializeCursorPostions(); }
public void Update() { // Get new head position GameFieldCoords newHeadPosition; if (this.currentDirection == "up") { newHeadPosition = new GameFieldCoords(this.snakeElements.Last().Row - 1, this.snakeElements.Last().Col); } else if (this.currentDirection == "right") { newHeadPosition = new GameFieldCoords(this.snakeElements.Last().Row, this.snakeElements.Last().Col + 1); } else if (this.currentDirection == "down") { newHeadPosition = new GameFieldCoords(this.snakeElements.Last().Row + 1, this.snakeElements.Last().Col); } else { newHeadPosition = new GameFieldCoords(this.snakeElements.Last().Row, this.snakeElements.Last().Col - 1); } // Add new snake element to the new position this.snakeElements.Enqueue(newHeadPosition); if (!this.isGettingBigger) { // Remove the last element if the snake is not getting bigger this.snakeElements.Dequeue(); } this.isGettingBigger = false; }
private void InitializeGameField(GameFieldCoords size) { Console.Title = "Snake Game"; this.gameField = new char[size.Row, size.Col]; for (int row = 0; row < this.gameField.GetLength(0); row++) { for (int col = 0; col < this.gameField.GetLength(1); col++) { this.gameField[row, col] = ' '; } } }
public Food(GameFieldCoords position) { this.foodCoords = new GameFieldCoords(position.Row, position.Col); }