public void ModifyCellTest() { // Will check state mofications for every single cell uint sizeOfBoard = 10; int? zombieCell = null; int? deadCell = 0; int? livingCell = 1; Game gameTest = new Game(sizeOfBoard); //Create new cells to insert into the board Cell[] cells = new Cell[sizeOfBoard * sizeOfBoard]; for (uint row = 0; row < sizeOfBoard; row++) { for (uint column = 0; column < sizeOfBoard; column++) { uint index = row * sizeOfBoard + column; cells[index].Column = column; cells[index].Row = row; cells[index].Status = livingCell; } } //Insert the cells try { gameTest.ModifyCell(cells); } catch (InvalidOperationException ie) { Assert.Fail(); } //Check the board to only contain living cells for (uint a = 0; a < sizeOfBoard; a++) { for (uint b = 0; b < sizeOfBoard; b++) { Assert.AreEqual(gameTest[a,b], livingCell); } } //Modify to a board of pure dead cells for (uint row = 0; row < sizeOfBoard; row++) { for (uint column = 0; column < sizeOfBoard; column++) { uint index = row * sizeOfBoard + column; cells[index].Column = column; cells[index].Row = row; cells[index].Status = 0; } } //Insert the new cells try { gameTest.ModifyCell(cells); } catch (InvalidOperationException ie) { Assert.Fail(); } ///Check the board to be of dead cells for (uint a = 0; a < sizeOfBoard; a++) { for (uint b = 0; b < sizeOfBoard; b++) { Assert.AreEqual(gameTest[a, b], deadCell); } } //Modify to a board of pure zombie cells - Arrrrrg.... for (uint row = 0; row < sizeOfBoard; row++) { for (uint column = 0; column < sizeOfBoard; column++) { uint index = row * sizeOfBoard + column; cells[index].Column = column; cells[index].Row = row; cells[index].Status = zombieCell; } } //Insert the new cells try { gameTest.ModifyCell(cells); } catch (InvalidOperationException ie) { Assert.Fail(); } //Check the board to be of zombie cells only for (uint a = 0; a < sizeOfBoard; a++) { for (uint b = 0; b < sizeOfBoard; b++) { Assert.AreEqual(gameTest[a, b], zombieCell); } } //Modify back to be a board of pure living cells (The happy ending!) for (uint row = 0; row < sizeOfBoard; row++) { for (uint column = 0; column < sizeOfBoard; column++) { uint index = row * sizeOfBoard + column; cells[index].Column = column; cells[index].Row = row; cells[index].Status = livingCell; } } //Insert the cells try { gameTest.ModifyCell(cells); } catch (InvalidOperationException ie) { Assert.Fail(); } //Check the board for living cells only for (uint a = 0; a < sizeOfBoard; a++) { for (uint b = 0; b < sizeOfBoard; b++) { Assert.AreEqual(gameTest[a, b], livingCell); } } }
public void SetSizeTest() { uint numberAboveMaxSize = 2000; for (uint index = 0; index < 2; index++) { if (index == 1) index = numberAboveMaxSize; try { Game gameTest = new Game(numberAboveMaxSize); Assert.Fail(); } catch (ArgumentException e) { //If inside here, every thing is just perfect. ;o) } } }
public void NextDayTest2() { uint gameSize = 10; Game gameTest = new Game(gameSize); Cell[] cells = new Cell[gameSize * gameSize]; //Set all the cells to be alive and happy for (uint column = 0; column < gameSize; column++) { for (uint row = 0; row < gameSize; row++) { uint index = column * gameSize + row; cells[index].Column = column; cells[index].Row = row; cells[index].Status = 1; } } gameTest.ModifyCell(cells); gameTest.NextDay(); //Now all cells (except those in the 4 corners) will be dead. The last 4 will still be alive for (uint column = 0; column < gameSize; column++) { for (uint row = 0; row < gameSize; row++) { if ((column == 0 && row == 0) || (column == gameSize - 1 && row == 0) || (column == 0 && row == gameSize - 1) || (column == gameSize - 1 && row == gameSize - 1)) { Assert.AreEqual(gameTest[column, row], 1); } else { Assert.AreEqual(gameTest[column, row], 0); } } } }
public void NextDayTest1() { uint gameSize = 10; Game gameTest = new Game(gameSize); Cell[] cells = new Cell[gameSize * gameSize]; //Make all cells zombies for (uint column = 0; column < gameSize; column++) { for (uint row = 0; row < gameSize; row++) { uint index = column * gameSize + row; cells[index].Column = column; cells[index].Row = row; cells[index].Status = null; } } gameTest.ModifyCell(cells); gameTest.NextDay(); //All cells are zombies, so the next day will be with just as many zombies... for (uint column = 0; column < gameSize; column++) { for (uint row = 0; row < gameSize; row++) { Assert.AreEqual(gameTest[column,row], null); } } }
static void Main() { Game game = new Game(50); game.StartGame(); }
/// <summary> /// A method to keep track of each individual game the user wants to play /// </summary> private void StartUpGame() { bool playNewGame = true; do { uint size = AskUserForSizeOfGame(MAX_SIZE_OF_GAME); _game = new Game(size); AskUserForModifyCell(size * size); bool continueCurrentGame = true; uint day = 1; do { PrintState(day++); char key = AskUserForNextAction(); //Any keystroke, except for q, will show the next day of the game if (key != 'q') _game.NextDay(); else continueCurrentGame = false; } while (continueCurrentGame); playNewGame = WantsToPlayANewGame(); } while (playNewGame); }
public ConsoleUI() { game = new Game(); }