public void GetImageShouldReturnProperTwoDimensionalArrayOfCellImageEnumsTrueShowAll() { // Arrange cellPosition.Setup(x => x.Col).Returns(1); cellPosition.Setup(x => x.Row).Returns(0); Mock <ICellPosition> secondCell = new Mock <ICellPosition>(); secondCell.Setup(c => c.Row).Returns(1); secondCell.Setup(c => c.Col).Returns(0); CellImage[,] expectedImageArray = new CellImage[, ] { { CellImage.Bomb, CellImage.Num, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb }, { CellImage.Num, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb }, { CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb }, { CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb }, { CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.Bomb }, }; // Act testMinefield.OpenCellHandler(cellPosition.Object); testMinefield.OpenCellHandler(secondCell.Object); var imageMatrix = testMinefield.GetImage(true); // Assert Assert.IsTrue(expectedImageArray.ContentEquals(imageMatrix)); }
public void DrawGameFieldShouldIterateExactTimes() { // Arrange int counter = 0; testRenderer.Setup(tr => tr.WriteAt(It.IsInRange(0, 25, Range.Inclusive), It.IsInRange(0, 25, Range.Inclusive), It.IsAny <string>())).Callback(() => counter += 1); CellImage[,] sendedImageArray = new CellImage[, ] { { CellImage.Num, CellImage.Flagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged }, { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged }, { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged }, { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged }, { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged } }; int[,] sendedNeighborMinesArray = new int[, ] { { 1, 0, 1, 0, 0 }, { 1, 1, 1, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 1 }, { 0, 0, 0, 1, 0 } }; // Act testBoardDrawer.DrawGameField(sendedImageArray, sendedNeighborMinesArray, CellPos.Empty); // Assert Assert.AreEqual(25, counter, "DrawGamefield has not iterated 25 times as it should."); }
public void DrawGameFieldShouldSendProperStringToRenderer() { // Arrange int counter = 0; testRenderer.Setup(tr => tr.WriteAt(It.IsInRange(0, 25, Range.Inclusive), It.IsInRange(0, 25, Range.Inclusive), It.Is <string>(s => s.Equals("#")))).Callback(() => counter += 1); CellImage[,] sendedImageArray = new CellImage[, ] { { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged }, { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged }, { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged }, { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged }, { CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged } }; int[,] sendedNeighborMinesArray = new int[, ] { { 1, 0, 1, 0, 0 }, { 1, 1, 1, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 1 }, { 0, 0, 0, 1, 0 } }; // Act testBoardDrawer.DrawGameField(sendedImageArray, sendedNeighborMinesArray, CellPos.Empty); // Assert Assert.AreEqual(25, counter, "DrawGamefield has not send 25 times required string."); }
public void DrawGameFieldShouldIterateExactTimes() { // Arrange int counter = 0; testRenderer.Setup(tr => tr.WriteAt(It.IsInRange(0, 25, Range.Inclusive), It.IsInRange(0, 25, Range.Inclusive), It.IsAny<string>())).Callback(() => counter += 1); CellImage[,] sendedImageArray = new CellImage[,] { {CellImage.Num, CellImage.Flagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged}, {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged}, {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged}, {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged}, {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged} }; int[,] sendedNeighborMinesArray = new int[,] { {1, 0, 1, 0, 0}, {1, 1, 1, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 1, 1}, {0, 0, 0, 1, 0} }; // Act testBoardDrawer.DrawGameField(sendedImageArray, sendedNeighborMinesArray, CellPos.Empty); // Assert Assert.AreEqual(25, counter, "DrawGamefield has not iterated 25 times as it should."); }
private void GenerateGrid() { for (int i = 0; i < currentAmt; ++i) { // Make sure the object to set exists if (cellImgList.Count <= i) // Instantiate new one if not yet exists { GameObject newObj = Instantiate(cellImgObject); newObj.GetComponent <RectTransform>().SetParent(this.transform, false); CellImage newCell = newObj.GetComponent <CellImage>(); newCell.indexNo = cellImgList.Count; cellImgList.Add(newCell); } else // Else make sure it's activated { cellImgList[i].gameObject.SetActive(true); } // Set the objects' parameters RectTransform curRect = cellImgList[i].gameObject.GetComponent <RectTransform>(); int rowNo = (int)Mathf.Floor(i / gridSize); int colNo = i % gridSize; curRect.localPosition = new Vector2( startCoor.x + ((cellSize + gapSize) * colNo), startCoor.y - ((cellSize + gapSize) * rowNo)); curRect.sizeDelta = new Vector2(cellSize, cellSize); cellImgList[i].InitializeColor(colors[COL_NEUTRAL]); } for (int i = currentAmt; i < lastAmt; ++i) { cellImgList[i].gameObject.SetActive(false); } lastAmt = currentAmt; }
void ReleaseDesignerOutlets() { if (CellDescription != null) { CellDescription.Dispose(); CellDescription = null; } if (CellImage != null) { CellImage.Dispose(); CellImage = null; } if (CellTitle != null) { CellTitle.Dispose(); CellTitle = null; } }
public void DrawGameFieldShouldSendProperStringToRenderer() { // Arrange int counter = 0; testRenderer.Setup(tr => tr.WriteAt(It.IsInRange(0, 25, Range.Inclusive), It.IsInRange(0, 25, Range.Inclusive), It.Is<string>(s => s.Equals("#")))).Callback(() => counter += 1); CellImage[,] sendedImageArray = new CellImage[,] { {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged}, {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged}, {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged}, {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged}, {CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged, CellImage.NotFlagged} }; int[,] sendedNeighborMinesArray = new int[,] { {1, 0, 1, 0, 0}, {1, 1, 1, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 1, 1}, {0, 0, 0, 1, 0} }; // Act testBoardDrawer.DrawGameField(sendedImageArray, sendedNeighborMinesArray, CellPos.Empty); // Assert Assert.AreEqual(25, counter, "DrawGamefield has not send 25 times required string."); }
/// <summary> /// Draws the game field. /// </summary> /// <param name="minefield">The minefield to be drawn.</param> /// <param name="neighborMines">The minefield with all values of neighboring mines.</param> public void DrawGameField(CellImage[,] minefield, int[,] neighborMines) { if (minefield.GetLength(0) != neighborMines.GetLength(0) || minefield.GetLength(1) != neighborMines.GetLength(1)) { throw new ArgumentException("Matrices dimensions are not equal!"); } this.boardGenerator.DrawGameField(minefield, neighborMines, this.minefieldTopLeft); }
public void DrawGameFieldWithDifferentMatricesBySizeShouldThrowAnException() { CellImage[,] minefield = new CellImage[3, 3]; int[,] neighborMines = new int[5, 3]; mockedManager.DrawGameField(minefield, neighborMines); }
public void GetImageShouldReturnProperTwoDimensionalArrayOfCellImageEnumsTrueShowAll() { // Arrange cellPosition.Setup(x => x.Col).Returns(1); cellPosition.Setup(x => x.Row).Returns(0); Mock<ICellPosition> secondCell = new Mock<ICellPosition>(); secondCell.Setup(c => c.Row).Returns(1); secondCell.Setup(c => c.Col).Returns(0); CellImage[,] expectedImageArray = new CellImage[,] { {CellImage.Bomb, CellImage.Num, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb}, {CellImage.Num, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb}, {CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb}, {CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb}, {CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.NoBomb, CellImage.Bomb}, }; // Act testMinefield.OpenCellHandler(cellPosition.Object); testMinefield.OpenCellHandler(secondCell.Object); var imageMatrix = testMinefield.GetImage(true); // Assert Assert.IsTrue(expectedImageArray.ContentEquals(imageMatrix)); }
/// <summary> /// Draws game minefield on screen via given IRenderer. /// </summary> /// <param name="minefield">Image of the minefield represented by two dimensional array of CellImage enumeration.</param> /// <param name="neighborMines">Two dimensional array of numbers representing neighbor mines for each cell.</param> /// <param name="topLeft">Top left coordinates of the board.</param> public void DrawGameField(CellImage[,] minefield, int[,] neighborMines, ICellPosition topLeft) { for (int row = 0; row < minefield.GetLength(0); row++) { for (int col = 0; col < minefield.GetLength(1); col++) { int rowOnScreen = topLeft.Row + BoardOffsetByRow + row; int colOnScreen = topLeft.Col + BoardOffsetByColumn + (col * CellSpaceOnScreen); string symbol; var symbolType = minefield[row, col]; if (symbolType == CellImage.Num) { int num = neighborMines[row, col]; symbol = (num == 0) ? EmptyCell : num.ToString(); } else { symbol = this.symbols[symbolType]; } this.DrawCell(rowOnScreen, colOnScreen, symbol); } } }