/// <summary> /// Resets the state of the game. /// </summary> /// <param name="difficulty">The given difficulty.</param> public void ResetGame(MinesweeperDifficulty difficulty) { clickedCellCount = 0; lifetimeStats.LastDifficulty = difficulty; msGame.InitializeBoard(difficulty); SetUpTheForm(msGame); }
public StoreGameWinForm(MainForm f, MinesweeperLifetimeStats stats, int currentTime, MinesweeperDifficulty currentDifficulty, string newPath) { InitializeComponent(); mainForm = f; lifetimeStats = stats; time = currentTime; difficulty = currentDifficulty; filePath = newPath; }
// Constructor public HighScoreRecord(string name, int time, MinesweeperDifficulty difficulty) { this.name = name; this.time = time; this.difficulty = difficulty; }
/// <summary> /// Generates the board according to the current game diffaculty. /// </summary> public void InitializeBoard(MinesweeperDifficulty newDifficulty) { Diffaculty = newDifficulty; // Set the board size and mine frequency double localFrequency; switch (Diffaculty) { case MinesweeperDifficulty.Easy: CurrentGridSize = EasyGridSize; localFrequency = EasyMineFrequency; break; case MinesweeperDifficulty.Medium: CurrentGridSize = MediumGridSize; localFrequency = MediumMineFrequency; break; case MinesweeperDifficulty.Hard: CurrentGridSize = HardGridSize; localFrequency = HardMineFrequency; break; case MinesweeperDifficulty.Insain: CurrentGridSize = InsainGridSize; localFrequency = InsainMineFrequency; break; default: CurrentGridSize = 0; localFrequency = 1; break; } // Create the new board Grid Cells = new GridCell[CurrentGridSize, CurrentGridSize]; for (int i = 0; i < CurrentGridSize; i++) { for (int j = 0; j < CurrentGridSize; j++) { Cells[i, j] = new GridCell(i, j); } } // Populate with mines and increment for (int i = 0; i < CurrentGridSize; i++) { for (int j = 0; j < CurrentGridSize; j++) { Cells[i, j].HasMine = rng.NextDouble() <= localFrequency; if (i - 1 >= 0 && i - 1 <= CurrentGridSize - 1 && j - 1 >= 0 && j - 1 <= CurrentGridSize - 1) { if (Cells[i, j].HasMine) { Cells[i - 1, j - 1].AdjMineCount++; } Cells[i, j].Neighbors.Add(Cells[i - 1, j - 1]); } if (j - 1 >= 0 && j - 1 <= CurrentGridSize - 1) { if (Cells[i, j].HasMine) { Cells[i, j - 1].AdjMineCount++; } Cells[i, j].Neighbors.Add(Cells[i, j - 1]); } if (i + 1 >= 0 && i + 1 <= CurrentGridSize - 1 && j - 1 >= 0 && j - 1 <= CurrentGridSize - 1) { if (Cells[i, j].HasMine) { Cells[i + 1, j - 1].AdjMineCount++; } Cells[i, j].Neighbors.Add(Cells[i + 1, j - 1]); } if (i - 1 >= 0 && i - 1 <= CurrentGridSize - 1) { if (Cells[i, j].HasMine) { Cells[i - 1, j].AdjMineCount++; } Cells[i, j].Neighbors.Add(Cells[i - 1, j]); } if (i + 1 >= 0 && i + 1 <= CurrentGridSize - 1) { if (Cells[i, j].HasMine) { Cells[i + 1, j].AdjMineCount++; } Cells[i, j].Neighbors.Add(Cells[i + 1, j]); } if (i - 1 >= 0 && i - 1 <= CurrentGridSize - 1 && j + 1 >= 0 && j + 1 <= CurrentGridSize - 1) { if (Cells[i, j].HasMine) { Cells[i - 1, j + 1].AdjMineCount++; } Cells[i, j].Neighbors.Add(Cells[i - 1, j + 1]); } if (j + 1 >= 0 && j + 1 <= CurrentGridSize - 1) { if (Cells[i, j].HasMine) { Cells[i, j + 1].AdjMineCount++; } Cells[i, j].Neighbors.Add(Cells[i, j + 1]); } if (i + 1 >= 0 && i + 1 <= CurrentGridSize - 1 && j + 1 >= 0 && j + 1 <= CurrentGridSize - 1) { if (Cells[i, j].HasMine) { Cells[i + 1, j + 1].AdjMineCount++; } Cells[i, j].Neighbors.Add(Cells[i + 1, j + 1]); } } } // Set the rest of the images for (int i = 0; i < CurrentGridSize; i++) { for (int j = 0; j < CurrentGridSize; j++) { Cells[i, j].Image = Cells[i, j].HasMine ? GameImage.Mine : (GameImage)Cells[i, j].AdjMineCount; } } }
public MinesweeperGame(MinesweeperDifficulty newDiffaculty) { Diffaculty = newDiffaculty; InitializeBoard(Diffaculty); }