private void CountMinesAround(Cell cell, Board board) { if (cell.IsMine) { MinesAround++; } }
private void Reveal(Cell cell, Board board) { if (MinesAround == 0) { cell.Reveal(board); } }
public void TestIsPlayerGrandWinner() { MinesweeperEngine testGame = new MinesweeperEngine(); Cell[,] matrix = new Cell[5, 10]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 9; j++) { matrix[i, j].Value = "3"; } matrix[i, 9].Value = "*"; } var result = testGame.IsPlayerGrandWinner(matrix, 5); Assert.AreEqual(true, result); /* Field mineFieldTest = new Minesweeper.Field(5, 10, 5); //mineFieldTest.Initialize(); Cell [,] testMineFiled = mineFieldTest.MineField; for (int i = 0; i < 5; i++) { for (int j = 0; j < 9; j++) { testMineFiled[i, j].Value = "4"; //testMineFiled[i, j].isFlagged = true; } //testMineFiled[i, 9].isBomb = true; testMineFiled[i, 9].Value = "*"; } var result = testGame.IsPlayerGrandWinner(testMineFiled, 5); Assert.AreEqual(true, result);*/ }
public CellElement(int x, int y) { InitializeComponent(); currentCell = new Cell(); Location = new Point(x, y); this.x = x; this.y = y; this.BackColor = Color.DarkGray; this.checkedCell = false; }
public bool IsPlayerGrandWinner(Cell[,] matrix, int minesCount) { bool isWinner = false; if (this.field.RevealedCells == matrix.Length - minesCount) { isWinner = true; } return isWinner; }
private Cell[,] InitializeGame(int maxRow, int maxCol) { var mines = InitializeMines(maxRow, maxCol); var game = new Cell[maxRow, maxCol]; for (int row = 0; row < maxRow; row++) for (int col = 0; col < maxCol; col++) { game[row, col] = new Cell(row, col, mines[row, col]); } InitializeMinesAround(); return game; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.userControl = ((Minesweeper.Cell)(target)); return; case 2: this.cell = ((System.Windows.Controls.Grid)(target)); #line 18 "..\..\Cell.xaml" this.cell.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Click); #line default #line hidden return; case 3: this.DotLabel = ((System.Windows.Shapes.Ellipse)(target)); return; case 4: this.Mine = ((System.Windows.Controls.Image)(target)); return; case 5: this.Flag = ((System.Windows.Controls.Image)(target)); return; case 6: this.ValueLabel = ((System.Windows.Controls.Label)(target)); return; } this._contentLoaded = true; }
/// <summary> /// Initializes all the mines in the various cells. /// </summary> /// <param name="type">These types: mined, special, and noMines.</param> public void InitializeCells(string type) { if(type.Equals("noMines")) { for (int i = 0; i < Cells.Length; i++) { Cells[i] = new Cell(dimension, CellHeight, PositionFromIndex(i), false); Cells[i].StateChanged(); } } else if (type.Equals("mined")) { Random gen = new Random(); // Creates an empty field. for (int i = 0; i < Cells.Length; i++) { Cells[i] = new Cell(dimension, CellHeight, PositionFromIndex(i), false); } // Sets totalMines random mines in the field. for (int i = 0; i < totalMines; i++) { bool done = false; int n; while(!done) { n = gen.Next(Cells.Length); if (!Cells[n].isMined) { Cells[n].isMined = true; done = true; } } } } else if (type.Equals("special")) { for (int i = 0; i < Cells.Length; i++) { Cells[i] = new Cell(dimension, CellHeight, PositionFromIndex(i), false); Cells[i].StateChanged(); } Cells[1] = new Cell(dimension, CellHeight, PositionFromIndex(0), true); Cells[dimension] = new Cell(dimension, CellHeight, PositionFromIndex(dimension), true); Cells[1 + dimension] = new Cell(dimension, CellHeight, PositionFromIndex(1 + dimension), true); } SetMineCount(); }
private void placeTheBombs(int x, int y) { //Fisher–Yates shuffle. int count = 0; Cell[] array = new Cell[currentDifficulty.sideX * currentDifficulty.sideY - 1]; for (int i = 0; i < currentDifficulty.sideX; i++) { for (int j = 0; j < currentDifficulty.sideY; j++) { if (i != x || j != y) { array[count] = new Cell(i, j); count++; } } } int k; Cell temp; for (int i = count - 1; i >= 0; i--) { k = rand.Next(0, i + 1); temp = array[k]; array[k] = array[i]; array[i] = temp; } for (int i = 0; i < currentDifficulty.Bombs ; i++) { grid[array[i].X, array[i].Y].CurrentCell.currentCellState = CellState.Bomb; } }
// Zaplní celou hrací desku políčky. Tyto políčka neobsahují miny a jsou neprozkoumané protected void generateCells() { for (int y = 0; y < this.size; y++) { for (int x = 0; x < this.size; x++) { Cell c = new Cell(); c.axis = new Axis(x, y); this.set(x, y, c); } } }
// Změní políčko na daných souřadnicích public void set(int x, int y, Cell cell) { if ((x >= 0) && (y >= 0) && (x < this.size) && (y < this.size)) this.cells[x, y] = cell; }
public void PlayMines() { this.scoreBoard = new ScoreBoard(new TextFileDataManager()); this.printer = Printer.GetInstance(this.scoreBoard); this.validator = new Validator(); var cel = new Cell(); this.field = new Field(5, 10, 15); this.commandFactory = new CommandFactoryWithLazyLoading(this.printer, this.field, this.validator); this.field.Initialize(); bool isBoomed = false; bool playerWon = false; this.printer.PrintMessage(Messages.StartMessage); while (true) { if (isBoomed || playerWon) { this.field.Initialize(); isBoomed = false; } this.printer.PrintField(this.field.MineField, isBoomed); this.printer.PrintMessage(Messages.EnterRowColCommand); string line = Console.ReadLine(); line = line.Trim(); if (this.validator.IsMoveEntered(line)) { string[] inputParams = line.Split(); int row = int.Parse(inputParams[0]); int col = int.Parse(inputParams[1]); if (this.field.IsMoveInBounds(row, col) && !this.field.IsCellClickled(row, col)) { isBoomed = this.field.MineField[row, col].IsBomb; playerWon = this.IsPlayerGrandWinner(this.field.MineField, this.field.NumberOfMines); this.EndGame(isBoomed, playerWon); this.field.RevialCell(row, col); } else { this.printer.PrintMessage(Messages.AlreadyOpenedOrOutOfRange); } } else { ICommand command = this.commandFactory.CreateCommand(line); if (command != null) { command.Execute(); } } } }
// 初期化 public void Init() { _cells = new Cell[CELL_NUM, CELL_NUM]; for (int x = 0; x < CELL_NUM; x++) { for (int y = 0; y < CELL_NUM; y++) { _cells[x, y] = new Cell(new Point(x, y), Status.Close, 0); } } flagCnt = 0; gameState = false; }
public Field(Cell[][] field) { _field = field; CountMinesInField(); }
private void ClickCell(Button current, Cell currentCell) { CheckForWin(); NumberCell(current, currentCell); CheckSurroundingCells(current.Location.X, current.Location.Y, currentCell); }
// Vypíše buňku tabulky protected static void printCell(Cell c, int n) { // Buď symbol reprezentující minu/neprozkoumané políčko, nebo počet min v okolí string value = c.value <= 0 ? Convert.ToString(TUI.symbols[c.value]) : Convert.ToString(c.value); Console.Write("| {0} ", value); // Poslední sloupec je potřeba uzavřít if (c.axis.x == n - 1) Console.Write("|"); }