public void Setup() { IServiceBus bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).Returns(1); _underTest = new MineSweeperGame(3, 3, 1, bus); }
public void ClickCoordinateShouldOnlyOpenOneCoordinateEastOfMine() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(2, 2); var game = new MineSweeperGame(5, 5, 1, bus); int openCount = 0; //Act game.MoveCursorRight(); game.MoveCursorRight(); game.MoveCursorRight(); game.MoveCursorDown(); game.MoveCursorDown(); game.ClickCoordinate(); //Assert for (int y = 0; y < game.SizeY; y++) { for (int x = 0; x < game.SizeX; x++) { if (game.GetCoordinate(x, y).IsOpen) { openCount++; } } } Assert.AreEqual(1, openCount); }
private void InitMineField() { int cols = 10; int rows = 10; int mines = 10; game = MineSweeperGame.Instance; game.Initialize(cols, rows, mines); Console.WriteLine(game); mineFieldGrid.Controls.Clear(); mineFieldGrid.ColumnCount = game.Cols; mineFieldGrid.Location = new System.Drawing.Point(0, 55); mineFieldGrid.AutoSize = true; this.AutoSize = true; this.Controls.Add(mineFieldGrid); buttonSquares = new List <ButtonSquare>(); int i = 0; foreach (Square square in game.Squares.Values) { ButtonSquare button = new ButtonSquare(i, square.ToString()); button.Size = new System.Drawing.Size(30, 30); button.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); button.MouseDown += new MouseEventHandler(OnClick); mineFieldGrid.Controls.Add(button); buttonSquares.Add(button); i++; } newGame.Image = pic_Start; }
public void ConstructorShouldSetCorrectSizeY() { //Arrange & Act var game = new MineSweeperGame(5, 6, 10, new ServiceBus()); //Assert Assert.AreEqual(game.SizeY, 6); }
public void ConstructorShouldStartInStatePlaying() { //Arrange & Act var game = new MineSweeperGame(5, 6, 10, new ServiceBus()); //Assert Assert.AreEqual(game.State, GameState.Playing); }
public void ConstructorShouldSetCorrectMineCount() { //Arrange & Act var game = new MineSweeperGame(5, 6, 10, new ServiceBus()); //Assert Assert.AreEqual(game.NumberOfMines, 10); }
public void ConstructorShouldSetSize() { //Arrange & Act var game = new MineSweeperGame(10, 10, 10, new ServiceBus()); //Assert Assert.AreEqual(game.SizeX, 10); Assert.AreEqual(game.SizeY, 10); }
public void DrawBoardShouldDrawCorrectSymbolForMarkedUnOpenedCoordinates() { //Arrange var bus = A.Fake <IServiceBus>(); var game = new MineSweeperGame(2, 2, 0, bus); //Act game.DrawBoard(); //Assert A.CallTo(() => bus.Write("? ", ConsoleColor.DarkCyan)).MustHaveHappened(Repeated.Exactly.Times(1)); }
public void ConstructorShouldCallResetBoard() { //Arrange var game = new MineSweeperGame(5, 6, 10, new ServiceBus()); //Act var coord = game.GetCoordinate(3, 3); //Assert Assert.IsNotNull(coord); }
public void ResetBoardShouldResetGameStateToPlaying() { //Arrange var game = new MineSweeperGame(3, 3, 0, new ServiceBus()); //Act game.ClickCoordinate(); game.ResetBoard(); //Assert Assert.AreEqual(GameState.Playing, game.State); }
public void DrawBoardShouldDrawMarkedSymbolForFlag() { //Arrange var bus = A.Fake <IServiceBus>(); var game = new MineSweeperGame(2, 2, 0, bus); //Act game.FlagCoordinate(); game.DrawBoard(); //Assert A.CallTo(() => bus.Write("! ", ConsoleColor.DarkCyan)).MustHaveHappened(Repeated.Exactly.Once); }
public void DrawBoardShouldDrawCorrectSymbolForOpenedCoordinates() { //Arrange var bus = A.Fake <IServiceBus>(); var game = new MineSweeperGame(2, 2, 0, bus); //Act game.ClickCoordinate(); game.DrawBoard(); //Assert A.CallTo(() => bus.Write(". ")).MustHaveHappened(Repeated.Exactly.Times(3)); }
public void ClickCoordinateShouldDetectGameWinWhenAllSafePositionsAreOpened() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(2, 2); var game = new MineSweeperGame(5, 5, 1, bus); //Act game.ClickCoordinate(); //Assert Assert.AreEqual(GameState.Won, game.State); }
public void ClickCoordinateShouldNotAlwaysResultInGameWin() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(2, 2, 0, 2); var game = new MineSweeperGame(5, 5, 2, bus); //Act game.ClickCoordinate(); //Assert Assert.AreEqual(GameState.Playing, game.State); }
public void DrawBoardShouldDrawSymbolForFlag() { //Arrange var bus = A.Fake <IServiceBus>(); var game = new MineSweeperGame(2, 2, 0, bus); //Act game.FlagCoordinate(); game.MoveCursorRight(); game.DrawBoard(); //Assert A.CallTo(() => bus.Write("! ")).MustHaveHappened(Repeated.Exactly.Once); }
public void DrawBoardShouldDrawMarkedSymbolForMine() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(0, 0); var game = new MineSweeperGame(2, 2, 1, bus); //Act game.ClickCoordinate(); game.DrawBoard(); //Assert A.CallTo(() => bus.Write("X ", ConsoleColor.DarkCyan)).MustHaveHappened(Repeated.Exactly.Once); }
public void ResetBoardShouldCalculate1Neighbours() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(0, 0); //Act var game = new MineSweeperGame(3, 3, 1, bus); var coordinate = game.GetCoordinate(1, 1); //Assert Assert.AreEqual(1, coordinate.NrOfNeighbours); }
public void ClickCoordinateShouldOpenAllMineCoordinatesIfMineHit() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(1, 1, 0, 0); var game = new MineSweeperGame(2, 2, 2, bus); //Act game.ClickCoordinate(); var coord = game.GetCoordinate(1, 1); //Assert Assert.AreEqual(true, coord.IsOpen); }
public void ClickCoordinateShouldOpenNeighbourPositions() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(2, 2); var game = new MineSweeperGame(5, 5, 1, bus); //Act game.ClickCoordinate(); var coord = game.GetCoordinate(1, 2); //Assert Assert.AreEqual(true, coord.IsOpen); }
public void ClickCoordinateShouldUsePosXAndPosY() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(0, 0); var game = new MineSweeperGame(2, 2, 1, bus); //Act game.MoveCursorRight(); game.MoveCursorDown(); game.ClickCoordinate(); //Assert Assert.AreEqual(true, game.GetCoordinate(1, 1).IsOpen); }
public void DrawBoardShouldDrawSymbolFor1Neighbour() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(1, 1); var game = new MineSweeperGame(2, 2, 1, bus); //Act game.ClickCoordinate(); game.MoveCursorRight(); game.DrawBoard(); //Assert A.CallTo(() => bus.Write("1 ")).MustHaveHappened(Repeated.Exactly.Once); }
public void DrawBoardShouldDrawMarkedPositionBasedOnPosXAndPosY() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(0, 0, 1, 0); var game = new MineSweeperGame(3, 3, 2, bus); //Act game.MoveCursorRight(); game.MoveCursorDown(); game.ClickCoordinate(); game.DrawBoard(); //Assert A.CallTo(() => bus.Write("2 ", ConsoleColor.DarkCyan)).MustHaveHappened(Repeated.Exactly.Once); }
public void ClickCoordinateShouldDetectGameLoss() { //Arrange var bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(1, 1); var game = new MineSweeperGame(2, 2, 1, bus); //Act game.MoveCursorRight(); game.MoveCursorDown(); game.ClickCoordinate(); //Assert Assert.AreEqual(GameState.Lost, game.State); }
public void ResetBoardShouldCalaculateNeighbouringNrOfMinesLargerThan1() { //Arrange & assume IServiceBus bus = A.Fake <IServiceBus>(); A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(1, 1, 2, 2); var game = new MineSweeperGame(3, 3, 2, bus); //Act var coord1 = game.GetCoordinate(2, 1); var coord2 = game.GetCoordinate(1, 2); //Assert Assert.AreEqual(2, coord1.NrOfNeighbours); Assert.AreEqual(2, coord2.NrOfNeighbours); }
private void Start_Click(object sender, RoutedEventArgs e) { try { int w = Int32.Parse(tbWidth.Text); int h = Int32.Parse(tbHeight.Text); int m = Int32.Parse(tbMines.Text); game = new MineSweeperGame(w, h, m); CreateField(); } catch { MessageBox.Show("Error in making a new game!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { rnd = new Random(); gameLogic = new MineSweeperGame(10, 10, 10, this); base.Initialize(); }
public void SetUp() { var gameBoard = InitializeGameBoard(); _mineSweeper = new MineSweeperGame(gameBoard); }
public void Setup() { _mockedServiceBus = new MockedServiceBus(); _underTest = new MineSweeperGame(2, 2, 1, _mockedServiceBus); }
public void Setup() { _underTest = new MineSweeperGame(5, 5, 0, new ServiceBus()); }