/// <summary> /// Here we create and print the gameField with its game description along with the main algorithm. /// </summary> public void InitializeGame() { this.gameField = new GameField(); this.PrintGameDescription(); this.gameField.Print(); this.runGame = true; int moves = 0; this.MainAlgorithm(moves); }
public void EmptyRowColTest() { GameField gameField = new GameField(); SetGameFieldBody(gameField, new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 16 }, { 13, 14, 15, 12 } }); Assert.AreEqual(gameField.EmptyCol, 3); }
public void InvalidMoveEmptyCellTest() { GameField gameField = new GameField(); SetGameFieldBody(gameField, new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }); gameField.MoveEmptyCell(4, 3); }
public void CheckSolvedGameField() { GameField gameField = new GameField(); SetGameFieldBody(gameField, new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }); Assert.IsTrue(gameField.CheckIfSolved()); }
public void MoveEmptyCellTest() { GameField gameField = new GameField(); SetGameFieldBody(gameField, new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 16 }, { 13, 14, 15, 12 } }); gameField.MoveEmptyCell(3, 3); int[,] expected = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }; CollectionAssert.AreEqual(gameField.Body, expected); }
public void IfOutOfMatrixTest2() { GameField gameField = new GameField(); Assert.IsFalse(gameField.IfOutOfMatrix(2, 0)); }
public void IfOutOfMatrixTest() { GameField gameField = new GameField(); Assert.IsTrue(gameField.IfOutOfMatrix(5, 0)); }
private GameField SetGameFieldBody(GameField gameField, int[,] matrix) { typeof(GameField).GetProperty("Body").SetValue(gameField, matrix); for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { if (matrix[i, j] == 16) { typeof(GameField).GetProperty("EmptyRow").SetValue(gameField, i); typeof(GameField).GetProperty("EmptyCol").SetValue(gameField, j); } } } return gameField; }
public void TestGameFieldPrint() { GameField gameField = new GameField(); SetGameFieldBody(gameField, new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 15, 11 }, { 13, 14, 12, 16 } }); string expected = " -------------\r\n| 1 2 3 4 |\r\n| 5 6 7 8 |\r\n| 9 10 15 11 |\r\n| 13 14 12 |\r\n -------------\r\n"; StringBuilder sb = new StringBuilder(); Console.SetOut(new System.IO.StringWriter(sb)); gameField.Print(); StringAssert.Equals(expected, sb.ToString()); }