public void SetUp() { gb = new GameBoard(); gb.dimensions = new IntVector2(10, 20); gb.Start(); gen = new GameBoardGenerator(gb); }
private void StartNewGame() { this.player.CurrentMoves = 0; var gameBoardArray = GameBoardGenerator.GenerateGameBoard(Config.GameBoardHeight, Config.GameBoardWidth, Config.MaxColorCount); this.GameBoard = new GameBoard(gameBoardArray); this.EntityPopper = new EntityPopper(this.GameBoard.Entities); }
public void Test_GameBoardGenerator_ShouldFillAllFieldsWithBaloons() { var gameBoard = GameBoardGenerator.GenerateGameBoard(20, 20, 4); for (int row = 0; row < gameBoard.GetLength(0); row++) { for (int col = 0; col < gameBoard.GetLength(1); col++) { Assert.IsInstanceOfType(gameBoard[row, col], typeof(Baloon)); } } }
public void TestUserInputMinesNumberWithOne() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("1{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); Assert.IsTrue(GameBoardGenerator.MinesNumber >= 1); } } }
public void TestUserInputCorrectFieldSize() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("5{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); Assert.AreEqual(GameBoardGenerator.GameField.Length, 25); } } }
public void TestBigFieldExplosion() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("10{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); int result = MinesExplosion.CheckForExplosion(GameBoardGenerator.GameField, 5, 5); Assert.IsTrue(result >= 2); } } }
public void TestUserInputCorrectCoordinates() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("10{0}5 5{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); GameInput.ManageUserInput(GameBoardGenerator.GameField); Assert.IsTrue(GameInput.ColCoordinate == 5 && GameInput.RowCoordinate == 5); } } }
public void TestUserInputWithOutOfRangeParameters() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("11{0}2{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); string expectedResult = "Welcome to \"Battle Field\" game.\r\nEnter battle field size between 1 and 10: Size must be between 1 and 10 \nInput new size:"; Assert.AreEqual <string>(expectedResult, sw.ToString()); } } }
public void TestCorrectPrintedFieldSizeWithOne() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("1{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); PrintGameBoard.PrintField(GameBoardGenerator.GameField); string result = sw.ToString(); Assert.IsTrue(result.Length == 92); } } }
public void TestCorrectPrintedFieldSizeWithSix() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("6{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); PrintGameBoard.PrintField(GameBoardGenerator.GameField); string result = sw.ToString(); Assert.IsTrue(result.Length == 202);//size of printed array without the string length of the GetBoardSize console writings } } }
public void TestUserInputIncorrectFormatLength2() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("8{0}ss{0}4 4{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); GameInput.ManageUserInput(GameBoardGenerator.GameField); string output = sw.ToString(); string expectedresult = "Welcome to \"Battle Field\" game.\r\nEnter battle field size between 1 and 10: Please enter coordinates: Choose x and y coordinates, seperated by white space in correct format [Example:2 5]\r\nPlease enter coordinates: "; Assert.AreEqual(expectedresult.Length, output.Length); } } }
public void TestUserInputOutsideOfField() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); using (StringReader sr = new StringReader(string.Format("8{0}9 9{0}3 3{0}", Environment.NewLine))) { Console.SetIn(sr); GameBoardGenerator.GetBoardSize(); GameInput.ManageUserInput(GameBoardGenerator.GameField); string output = sw.ToString(); string expectedresult = "Welcome to \"Battle Field\" game. \nEnter battle field size between 1 and 10: Please enter coordinates: Outside of Field Range Please enter coordinates: "; Assert.AreEqual(expectedresult.Length, output.Length); } } }
public void Generate_A_GameBoard(int row, int col) { //Arr var rule = new Rules(); List <Player> players = Game.AddPlayers(rule.NumberOfPlayers, rule.PiecesPerPlayer, playerColors, startingPositions); IBoardObject[,] GameBoard = GameBoardGenerator.Generate(row, col, players, 4); int dimension = GameBoard.GetLength(0) * GameBoard.GetLength(1); // Act int totalCol = 0; for (int i = 0; i < GameBoard.Length; i++) { ++totalCol; } // Expect Assert.NotNull(GameBoard); Assert.Equal(totalCol, dimension); }
public static void SaveGame(List <Player> players, int currentPlayer, int saveId) { Game.Rules.SaveGameId = saveId; var context = new DbModel(); //if (saveId < 0) //{ context.SaveGames.Add(new SaveGame(currentPlayer)); saveId = context.SaveGames.Count() + 1; context.Rules.Add(new Rules(Game.Rules.NumberOfPlayers, Game.Rules.PiecesPerPlayer, Game.Rules.ThrowAgainOnSixEnabled, Game.Rules.InitialSixRuleEnabled)); for (var i = 0; i < players.Count; i++) { var player = players[i]; var newPlayer = new Player(Game.Rules.PiecesPerPlayer, players[i].Color, i, new Position(players[i].Row, players[i].Col)); newPlayer.SaveGameId = saveId; for (var j = 0; j < player.Pieces.Count; j++) { var piece = player.Pieces[j]; var pos = GameBoardGenerator.FindObject(Game.GameBoard, piece); var newPiece = new GamePiece(j.ToString().First(), i); newPiece.Row = pos.Row; newPiece.Col = pos.Col; newPiece.SaveGameId = saveId; context.Pieces.Add(newPiece); } context.Players.Add(newPlayer); } //} //else //{ // //TODO: Update existing //} context.SaveChanges(); }
/// <summary> /// Move a GamePiece and check if the move was valid. /// </summary> /// <param name="piece">GamePiece to move</param> /// <param name="diceRoll">How far to move (dice)</param> /// <returns>True if the move succeeded, else false</returns> public static bool MovePiece(GamePiece piece, int diceRoll) { Position position = GameBoardGenerator.FindObject(Game.GameBoard, piece); Position newPosition = new Position(); int traversablePos = -1; List <Position> currentPath; var onInnerPath = piece.OnInnerPath; currentPath = piece.OnInnerPath ? Player.GetAllInnerPaths() : Game.Traversable; traversablePos = FindOnPath(currentPath, position, piece); if (traversablePos == -1) { //Couldn't find position return(false); } for (int i = 0; i < diceRoll; i++) { //TODO: Inner path code int offset = 0; var currentDicePosition = 1 + i; if (traversablePos + currentDicePosition >= currentPath.Count) { offset = 0 - currentPath.Count; } var nextStep = currentPath[traversablePos + currentDicePosition + offset]; bool finalStep = i == diceRoll - 1; if (!Movement.TryMove(piece, nextStep, finalStep)) // Om TryMove returnerar false misslyckas move, GamePiece kan inte flyttas { //Move failed return(false); } if (piece.OnInnerPath && !onInnerPath) { currentPath = Player.GetAllInnerPaths(); diceRoll -= currentDicePosition; currentDicePosition = 0; offset = 0; i = -1; traversablePos = (currentPath.Count / Game.Rules.NumberOfPlayers) * piece.PlayerId; onInnerPath = true; } //TODO: If final move is not valid, don't move at all newPosition = currentPath[traversablePos + currentDicePosition + offset]; } //Place piece on new position and set the old position to the original value when we created the board Game.GameBoard[newPosition.Row, newPosition.Col] = piece; Game.GameBoard[position.Row, position.Col] = Game.OriginalGameBoard[position.Row, position.Col]; return(true); }
public void Test_GameBoardGeneratorWithIvalidParameters_ShouldThrowAnExeption() { GameBoardGenerator.GenerateGameBoard(-20, 20, 4); }
private void OnEnable() { gameBoardGenerator = (GameBoardGenerator)target; }
private void Awake() { instance = this; }