public static GridPoint[,] AddGridPointsToBoard(this GridPoint[,] board) { var height = board.GetLength(0); var width = board.GetLength(1); for (int x = 0; x < height; x++) { for (int y = 0; y < width; y++) { board[x, y] = new GridPoint { NeighbourCoordinates = GridPointHelper.CalculateNeighbourCoordinates(x, y, height, width), IsHidden = true, IsMine = false, AdjacentMineCount = 0 }; } ; } ; return(board); }
public GameState UpdateGameStateOnUserInput(GridPoint[,] board, GridPoint selectedPoint) { if (selectedPoint.IsMine) { _state = GamePlay.MineHit(board, _boardSettings.Letters, _messages); _inputRetriever.UserInputReadKey(); return(_state); } else { GamePlay.MineNotHit(selectedPoint); _state = GamePlay.CheckForWin(board, _boardSettings.MineCount); if (_state == GameState.Won) { GamePlay.DisplayBoard(board, _boardSettings.Letters); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(_messages.Win); Console.ForegroundColor = ConsoleColor.Gray; return(_state); } return(_state); } }
public static GameState MineNotHit(GridPoint selectedPoint) { selectedPoint.IsHidden = false; GridPointHelper.SetDisplayCharacter(selectedPoint); return(GameState.InProgress); }
public static GridPoint SetDisplayCharacter(GridPoint point) { point.DisplayCharacter = point.IsHidden ? "*" : point.IsMine ? "m" : point.AdjacentMineCount.ToString(); return(point); }