private IMinefield GetFakeField() { IMinefield minefield = Substitute.For <IMinefield>(); minefield.CellsStateCanBeChanged.Returns(true); return(minefield); }
private static IMinefield CreateGameOveredMinefield() { IMinefield minefield = Substitute.For <IMinefield>(); minefield.State.Returns(FieldState.GameOver); return(minefield); }
public Minesweeper(IMinefieldFactory minefield_factory, GameOptions game_options) { _game_id = game_options.player_id; DomainEvents.raise(new MinesweeperGameStarted(_game_id)); _minefield = minefield_factory.create_a_mindfield_with_these_options(game_options, _game_id); }
public void OpenAllNoMinedCells_StateToWin() { IMinefield minefield = SetMineToCenter(); WinGame(minefield); Assert.AreEqual(FieldState.Win, minefield.State); }
public void FirstSetFlag_StateChangeToInGame() { IMinefield minefield = SetMineToCenter(); minefield.Cells[4][4].SetFlag(); Assert.AreEqual(FieldState.InGame, minefield.State); }
public Minesweeper(IMinefieldFactory minefield_factory, GameOptions game_options) { _game_id = game_options.player_id; DomainEvents.raise(new MinesweeperGameStarted(_game_id)); _minefield = minefield_factory.create_a_mindfield_with_these_options(game_options, _game_id); }
public void Solve(IMinefield minefield) { // For every mine in the minefield foreach (IMineArea area in minefield.MineAreas()) { // Select all neighbors and increment their number of adjacent mines area.NeighboringAreas(minefield).ForEach(neighbor => neighbor.AdjacentMines += 1); } }
public void Explosion_StateToLosse() { IMinefield minefield = SetMineToCenter(); minefield.Cells[4][4].Open(); minefield.Cells[5][5].Open(); Assert.AreEqual(FieldState.GameOver, minefield.State); }
public void SetMineToCenterAndItselfHasNoMinedNearby() { IMinefield field = SetMineToCenter(); IEnumerable <ICell> toCheck = GetNearbyFromCenter(field); ICell center = field.GetCellByCoords(5, 5); Assert.AreEqual(0, center.MinesNearby); }
public void Solve(IMinefield minefield) { // For every mine in the minefield foreach (IMineArea area in minefield.MineAreas()) { // Select all neighbors and increment their number of adjacent mines area.NeighboringAreas(minefield).ForEach(neighbor => neighbor.AdjacentMines += 1); } }
/// <summary> /// List all of the areas in a minefield by column. /// </summary> /// <param name="minefield">The minefield to enumerate.</param> /// <returns>An enumerable collection of IMineAreas in column order.</returns> public static IEnumerable <IMineArea> AreasByColumn(this IMinefield minefield) { for (int col = 0; col < minefield.Width; col++) { for (int row = 0; row < minefield.Height; row++) { yield return(minefield.GetArea(row, col)); } } }
public void OpenCellWithNoAdjacentMine_AllAdjacentCellStateToOpen() { IMinefield minefield = SetMineToCenter(); minefield.Cells[0][0].Open(); Assert.AreEqual(CellState.Opened, minefield.Cells[1][0].State); Assert.AreEqual(CellState.Opened, minefield.Cells[0][1].State); Assert.AreEqual(CellState.Opened, minefield.Cells[1][1].State); }
public void ResetFlag_FlagsCountDown() { IMinefield minefield = SetMineToCenter(); minefield.Cells[0][0].SetFlag(); minefield.Cells[1][1].SetFlag(); minefield.Cells[1][1].SetFlag(); Assert.AreEqual(1, minefield.FlagsCount); }
public void SendFillIncorrectParameters_ThrowException(int height, int width, int mineCount, string expected) { IMinefield minefield = MinefieldTestHelper.CreateDefaultMinefield(); SettingsItem settings = CreateCustomSettings(height, width, mineCount); minefield.SetGameSettings(settings); var ex = Assert.Catch <Exception>(() => minefield.Fill()); StringAssert.Contains(expected.ToUpper(), ex.Message.ToUpper()); }
public void FirstClickOnMinedCell_NoExplosion() { IMinefield minefield = SetMineToCenter(); ICell cell = minefield.Cells[5][5]; cell.Open(); Assert.AreNotEqual(CellState.Explosion, cell.State); Assert.AreNotEqual(FieldState.GameOver, minefield.State); }
public void FillMinefield_StateToNotStarted() { IMinefield minefield = SetMineToCenter(); SettingsItem settings = CreateCustomSettings(10, 10, 1); minefield.SetGameSettings(settings); minefield.Cells[0][0].Open(); minefield.Fill(); Assert.AreEqual(FieldState.NotStarted, minefield.State); }
public void EndGame_CanNotOpenCell() { IMinefield minefield = SetMineToCenter(); WinGame(minefield); ICell minedCell = minefield.GetCellByCoords(5, 5); minedCell.Open(); Assert.AreEqual(CellState.NotOpened, minedCell.State); }
public void TrySetFlagAfterGameOver_StateNoChanged() { IMinefield minefield = CreateGameOveredMinefield(); ICell cell = new Cell(minefield, 0, 0) { State = CellState.NotOpened }; cell.SetFlag(); Assert.AreEqual(CellState.NotOpened, cell.State); }
private static void WinGame(IMinefield minefield) { foreach (var row in minefield.Cells) { foreach (var cell in row) { if (!cell.Mined) { cell.Open(); } } } }
public void OnChangeGameType_EventHandled() { IMinefield minefield = MinefieldTestHelper.CreateDefaultMinefield(); SettingsManager settingsManager = new SettingsManager(); settingsManager.SelectGameType(GameType.Advanced); TestGame game = new TestGame(settingsManager, MinefieldTestHelper.GetDefaultRecords(), minefield); game.Settings.SelectGameType(GameType.Newbie); Assert.AreEqual(true, game.EventWasHandled); }
private IEnumerable <ICell> GetNearbyFromCenter(IMinefield field) { List <ICell> nearby = new List <ICell>(8); nearby.Add(field.GetCellByCoords(4, 4)); nearby.Add(field.GetCellByCoords(4, 5)); nearby.Add(field.GetCellByCoords(4, 6)); nearby.Add(field.GetCellByCoords(5, 4)); nearby.Add(field.GetCellByCoords(5, 6)); nearby.Add(field.GetCellByCoords(6, 4)); nearby.Add(field.GetCellByCoords(6, 5)); nearby.Add(field.GetCellByCoords(6, 6)); return(nearby); }
public void GameRestart_FlagsCountReset() { IMinefield minefield = SetMineToCenter(); SettingsItem settings = CreateCustomSettings(10, 10, 1); minefield.SetGameSettings(settings); minefield.Cells[0][0].SetFlag(); minefield.Cells[1][1].SetFlag(); minefield.Fill(); Assert.AreEqual(0, minefield.FlagsCount); }
/// <summary> /// Lists all of the areas that are adjacent to a mine area in a minefield. /// </summary> /// <param name="mineArea">Returns the neighbors of this area.</param> /// <param name="minefield">Uses this minefield to get references to neighboring areas.</param> /// <returns>An enumerable collection of IMineAreas that are adjacent to the specified area.</returns> public static IEnumerable<IMineArea> NeighboringAreas(this IMineArea mineArea, IMinefield minefield) { for (int row = mineArea.Row - 1; row <= mineArea.Row + 1; row++) { for (int col = mineArea.Col - 1; col <= mineArea.Col + 1; col++) { // Make sure indexes are in mine grid and area is not the current area if (row >= 0 && row < minefield.Height && col >= 0 && col < minefield.Width && (row != mineArea.Row || col != mineArea.Col)) yield return minefield.GetArea(row, col); } } }
public static IMinefield DefaultMinefield(int fieldHeightCell, int fieldWidthCell) { IMinefield field = MinefieldTestHelper.CreateDefaultMinefield(); SettingsItem settings = new SettingsItem() { Height = fieldHeightCell, Width = fieldWidthCell, MineCount = DefaultMineCount }; field.SetGameSettings(settings); field.Fill(); return(field); }
public void MineExplosion_StateToGameOver() { IMinefield field = SetMineToCenter(); field.GetCellByCoords(0, 1).Mined = true; ICell cell = field.GetCellByCoords(0, 0); cell.Open(); // Boom! cell = field.GetCellByCoords(5, 5); cell.Open(); Assert.AreEqual(FieldState.GameOver, field.State); }
public void FlaggedCountChanged_MinefieldSignalizedAboutIt() { IMinefield minefield = SetMineToCenter(); minefield.OnFlagsCountChanged += Minefield_OnFlagsCountChanged; onFlagsCountChangedEvendReceaved = false; minefield.Cells[0][0].SetFlag(); Assert.AreEqual(true, onFlagsCountChangedEvendReceaved); onFlagsCountChangedEvendReceaved = false; minefield.Cells[0][0].SetFlag(); Assert.AreEqual(true, onFlagsCountChangedEvendReceaved); }
protected Game(ISettingsManager settings, IRecords records, IMinefield gameField, IGetRecordsmanNameProvider getRecordsmanNameProvider = null) { Settings = settings; Settings.OnCurrentGameChanged += Settings_OnCurrentGameChanged; Records = records; Timer = new GameTimer(); GameField = gameField; GameField.SetGameSettings(Settings.CurrentSettings); GameField.Fill(); GameField.OnStateChanged += GameField_OnStateChanged; this.getRecordsmanNameProvider = getRecordsmanNameProvider; }
public TestGame(ISettingsManager settings, IRecords records, IMinefield gameField) : base(settings, records, gameField) { EventWasHandled = false; }
public GameWithOpenConstructor(ISettingsManager settings, IRecords records, IMinefield gameField) : base(settings, records, gameField) { }
public ICell CreateCell(IMinefield field, int x, int y) { return(new Cell(field, x, y)); }
/// <summary> /// Lists all of the areas that are adjacent to a mine area in a minefield. /// </summary> /// <param name="mineArea">Returns the neighbors of this area.</param> /// <param name="minefield">Uses this minefield to get references to neighboring areas.</param> /// <returns>An enumerable collection of IMineAreas that are adjacent to the specified area.</returns> public static IEnumerable <IMineArea> NeighboringAreas(this IMineArea mineArea, IMinefield minefield) { for (int row = mineArea.Row - 1; row <= mineArea.Row + 1; row++) { for (int col = mineArea.Col - 1; col <= mineArea.Col + 1; col++) { // Make sure indexes are in mine grid and area is not the current area if (row >= 0 && row < minefield.Height && col >= 0 && col < minefield.Width && (row != mineArea.Row || col != mineArea.Col)) { yield return(minefield.GetArea(row, col)); } } } }
private static IMinefield SetMineToCenter() { IMinefield field = SetMineToPosition(5, 5); return(field); }
public void CreateFieldWithMine_CheckMinesCount() { IMinefield minefield = SetMineToCenter(); // Количество мин равно единице. Assert.AreEqual(1, minefield.MinesCount); }