public void TestLabyrintConsolePrintWithSecondMatrix() { char[,] matrixToTest02 = { {'X','-','X','X','X','X','X'}, {'X','-','X','X','X','X','X'}, {'X','-','X','X','X','X','X'}, {'X','-','-','-','-','-','X'}, {'X','X','X','-','X','X','X'}, {'X','X','X','X','X','X','X'}, {'X','X','X','X','X','X','X'}, }; LabyrinthPlayer player = new LabyrinthPlayer(0, 1); LabyrinthMatrix lab = new LabyrinthMatrix(7, 7); lab.Matrix = matrixToTest02; LabyrinthRenderer renderer = new LabyrinthRenderer(player, lab); StringWriter writer = new StringWriter(); string expected = String.Format( "{0}X*XXXXX{0}X-XXXXX{0}X-XXXXX{0}X-----X{0}XXX-XXX{0}XXXXXXX{0}XXXXXXX{0}", Environment.NewLine); using (writer) { Console.SetOut(writer); renderer.ConsoleDrawLabyrinth(); string output = writer.ToString(); Assert.AreEqual(expected, output); } }
/// <summary> /// Creates instance of the game engine object. /// </summary> /// <param name="player">Accepts any instance of IPlayer.</param> /// <param name="renderer">Accepts any instance of IRenderer.</param> /// <param name="scoreboard">Accepts any instance of IScoreBoardObserver.</param> /// <param name="matrix">Accepts instance of the class LabyrinthMatrix.</param> private GameEngine(IPlayer player, IRenderer renderer, IScoreBoardObserver scoreboard, LabyrinthMatrix matrix) { this.context = new Context(scoreboard, renderer, player, matrix); this.factory = new CommandFactory(this.context); this.Attach(this.context.ScoreboardHandler); this.context.StartNewGame(); }
private void Restart() { Console.WriteLine(); Console.WriteLine("Welcome to “Labirinth” game. Please try to escape. Use 'top' to view the top scoreboard, 'restart' to start a new game and 'exit' to quit the game."); this.matrix = new LabyrinthMatrix(); moveCount = 0; }
public void LabyrinthWithExitCountTest() { LabyrinthMatrix test = new LabyrinthMatrix(7, 7); char P = test.PassableBlock; char U = test.UnPassableBlock; char[,] customMatrix01 = { {U,P,U,U,U,U,U}, {U,P,U,U,U,U,U}, {U,P,U,U,U,U,U}, {U,P,P,P,P,U,U}, {U,U,U,U,P,U,U}, {U,U,U,U,P,U,U}, {U,U,U,U,P,U,U}, }; int exitsCount = test.CountLabyrinthExits(7 / 2, 7 / 2, customMatrix01); Assert.AreEqual(2, exitsCount); char[,] customMatrix02 = { {U,U,U,U,U,U,U}, {U,P,P,P,P,P,P}, {U,P,P,P,P,P,U}, {U,P,P,P,P,P,U}, {U,P,P,P,P,P,U}, {U,P,P,P,P,P,U}, {U,U,U,U,U,U,U}, }; exitsCount = test.CountLabyrinthExits(7 / 2, 7 / 2, customMatrix02); Assert.AreEqual(1, exitsCount); char[,] customMatrix03 = { {P,U,U,U,U,U,U}, {P,P,U,P,P,P,U}, {P,P,P,P,P,P,U}, {P,P,P,P,P,U,U}, {P,P,P,P,P,P,U}, {P,P,P,P,P,P,U}, {P,U,U,U,U,U,U}, }; exitsCount = test.CountLabyrinthExits(7 / 2, 7 / 2, customMatrix03); Assert.AreEqual(5, exitsCount); char[,] customMatrix04 = { {U,U,U,P,U,U,U}, {U,U,U,P,U,U,U}, {U,U,U,P,U,U,U}, {P,P,P,P,P,P,P}, {U,U,U,P,U,U,U}, {U,U,U,P,U,U,U}, {U,U,U,P,U,U,U}, }; exitsCount = test.CountLabyrinthExits(7 / 2, 7 / 2, customMatrix04); Assert.AreEqual(4, exitsCount); }
/// <summary> /// Creates a thread safety Singleton instance of the GameEngine. /// </summary> /// <param name="player">Accepts any instance of IPlayer.</param> /// <param name="renderer">Accepts any instance of IRenderer.</param> /// <param name="scoreboard">Accepts any instance of IScoreBoardObserver.</param> /// <param name="matrix">Accepts instance of the class LabyrinthMatrix.</param> /// <returns>Instance of the GameEngine class.</returns> public static GameEngine Instance(IPlayer player, IRenderer renderer, IScoreBoardObserver scoreboard, LabyrinthMatrix matrix) { if (gameInstance == null) { lock (syncLock) { if (gameInstance == null) { gameInstance = new GameEngine(player, renderer, scoreboard, matrix); } } } return gameInstance; }
public static void ShowLabyrinth(LabyrinthMatrix labyrinth) { Console.WriteLine(); char[][] myMatrix = labyrinth.Matrix; for (int i = 0; i < myMatrix.Length; i++) { for (int j = 0; j < myMatrix[i].Length; j++) { if (i == labyrinth.MyPostionVertical && j == labyrinth.MyPostionHorizontal) { Console.Write("*"); } else { Console.Write(myMatrix[j][i]); } } Console.WriteLine(); } }
/// <summary> /// Creates a thread safety Singleton instance of the GameEngine. /// </summary> /// <param name="player">Accepts any instance of IPlayer.</param> /// <param name="renderer">Accepts any instance of IRenderer.</param> /// <param name="scoreboard">Accepts any instance of IScoreBoardObserver.</param> /// <param name="matrix">Accepts instance of the class LabyrinthMatrix.</param> /// <returns>Instance of the GameEngine class.</returns> public static GameEngine Instance(IPlayer player, IRenderer renderer, IScoreBoardObserver scoreboard, LabyrinthMatrix matrix) { if (gameInstance == null) { lock (syncLock) { if (gameInstance == null) { gameInstance = new GameEngine(player, renderer, scoreboard, matrix); } } } return(gameInstance); }
public LabyrinthMatrix(LabyrinthMatrix l) { }
public void TestGenerateLabyrinthMatrix() { int matrixSize = 4; LabyrinthMatrix labyrinthMatrix = new LabyrinthMatrix(matrixSize, matrixSize); int numberOfGeneratedMatrix = 1000; if (numberOfGeneratedMatrix < 1000) { throw new Exception("The variable numberOfGeneratedMatrix must be minimum 1000"); } // create matrix to count blocks type in the matrix int[,] passableBlocksCountMatrix = new int[matrixSize, matrixSize]; int[,] unpassableBlocksCountMatrix = new int[matrixSize, matrixSize]; passableBlocksCountMatrix = GenerateCounterMatrix(passableBlocksCountMatrix); unpassableBlocksCountMatrix = passableBlocksCountMatrix.Clone() as int[,]; //generate N random matrix and infill the twoo counter matrices (passableBlocksCountMatrix and unpassableBlocksCountMatrix) for (int i = 0; i < numberOfGeneratedMatrix; i++) { labyrinthMatrix.GenerateLabyrinthMatrix(); for (int col = 0; col < matrixSize; col++) { for (int row = 0; row < matrixSize; row++) { if (labyrinthMatrix.Matrix[col, row] == '-') { passableBlocksCountMatrix[col, row]++; } else if (labyrinthMatrix.Matrix[col, row] == 'X') { unpassableBlocksCountMatrix[col, row]++; } } } } // test for count of random elements by two counter matrix bool isRandom = true; int propabilityOfCountOfBlocks = (int)(numberOfGeneratedMatrix * 0.40); int playerCoordinate = matrixSize / 2; for (int col = 0; col < matrixSize; col++) { for (int row = 0; row < matrixSize; row++) { if (col == playerCoordinate && row == playerCoordinate) { continue; } if (passableBlocksCountMatrix[col, row] < propabilityOfCountOfBlocks || unpassableBlocksCountMatrix[col, row] < propabilityOfCountOfBlocks) { isRandom = false; } } } Assert.IsTrue(isRandom); }
private void Start(int maxRows,int maxCols) { this.player = new LabyrinthPlayer(maxRows/2, maxCols/2); this.labyrinth = new LabyrinthMatrix(maxRows, maxCols); this.labyrinth.GenerateLabyrinthMatrix(); this.renderer = new LabyrinthRenderer(this.player, this.labyrinth); while (true) { // Old - DrawLabyrinth() this.renderer.ConsoleDrawLabyrinth(); if (IsFinished()) { break; } PlayerControl(); } Console.Clear(); }
public void Restart() { this.renderer.ShowMessage(Messenger.WelcomeMessage); this.matrix = new LabyrinthMatrix(); this.player.Score = 0; this.player.PositionCol = StartPositionHorizontal; this.player.PositionRow = StartPositionVertical; }
public void TestIsOutsideMatrix() { int matrixSize = 3; LabyrinthMatrix labyrinthMatrix = new LabyrinthMatrix(matrixSize, matrixSize); //testing inside of the matrix for (int row = 1; row < labyrinthMatrix.Matrix.GetLength(0) - 1; row++) { for (int col = 1; col < labyrinthMatrix.Matrix.GetLength(1) - 1; col++) { Assert.IsFalse(labyrinthMatrix.IsOutsideMatrix(row, col), String.Format("Row: {0}; Col: {1}", col, col) ); } } //testing outside of the matrix - horizontaly boundary int lastRow = labyrinthMatrix.Matrix.GetLength(0) - 1; for (int row = 0; row < labyrinthMatrix.Matrix.GetLength(0); row += lastRow) { for (int col = 0; col < labyrinthMatrix.Matrix.GetLength(1); col++) { Assert.IsTrue(labyrinthMatrix.IsOutsideMatrix(row, col), String.Format("Row: {0}; Col: {1}", col, col) ); } } //testing outside of the matrix - verticaly boundary int lastCol = labyrinthMatrix.Matrix.GetLength(1) - 1; for (int col = 0; col < labyrinthMatrix.Matrix.GetLength(1); col += lastCol) { for (int row = 0; row < labyrinthMatrix.Matrix.GetLength(1); row++) { Assert.IsTrue(labyrinthMatrix.IsOutsideMatrix(row, col), String.Format("Row: {0}; Col: {1}", col, col) ); } } }
public void TestIsPassableWithUnpassableBlocks() { int matrixSize = 3; LabyrinthMatrix labyrinthMatrix = new LabyrinthMatrix(matrixSize, matrixSize); char blockBody = 'X'; labyrinthMatrix = GenerateLabyrinthMatrix(labyrinthMatrix, blockBody); Assert.IsFalse(labyrinthMatrix.IsPassable(0, 1)); //go to up Assert.IsFalse(labyrinthMatrix.IsPassable(1, 2)); //go to right Assert.IsFalse(labyrinthMatrix.IsPassable(2, 1)); //go to down Assert.IsFalse(labyrinthMatrix.IsPassable(1, 0)); //go to left }
private LabyrinthMatrix GenerateLabyrinthMatrix(LabyrinthMatrix matrix, char blockBody) { LabyrinthMatrix labyrinthMatrix = matrix; for (int row = 0; row < labyrinthMatrix.Matrix.GetLength(0); row++) { for (int col = 0; col < labyrinthMatrix.Matrix.GetLength(1); col++) { labyrinthMatrix.Matrix[row, col] = blockBody; } } return labyrinthMatrix; }
public void TestLabyrinthMatrixConstructor() { int matrixSize = 3; LabyrinthMatrix labyrinthMatrix = new LabyrinthMatrix(matrixSize, matrixSize); Assert.AreEqual(matrixSize, labyrinthMatrix.Matrix.GetLength(0)); Assert.AreEqual(matrixSize, labyrinthMatrix.Matrix.GetLength(1)); }