public void StartGame_TwoPlayers_GameStateIsStarted() { // Arrange var game = new LudoGame(new DieceMock()); game.AddPlayer("player1", PlayerColor.Blue); game.AddPlayer("player2", PlayerColor.Red); // Act bool result = game.StartGame(); // Assert Assert.True(result); Assert.Equal(GameState.Started, game.GetGameState()); }
public void AddPlayer_TwoBluePlayers_SecondPlayerReturnNull() { // Arrange var game = new LudoGame(new DieceMock()); // Act var player1 = game.AddPlayer("player1", PlayerColor.Blue); var player2 = game.AddPlayer("player2", PlayerColor.Blue); // Assert Assert.NotNull(player1); Assert.Null(player2); // Extra asserts Assert.Equal(0, player1.PlayerId); }
public void AddPlayer_TwoPlayersWithDifferentColors_BothPlayersNotNull() { // Arrange var game = new LudoGame(new DieceMock()); // Act var player1 = game.AddPlayer("player1", PlayerColor.Blue); var player2 = game.AddPlayer("player2", PlayerColor.Red); // Assert Assert.NotNull(player1); Assert.NotNull(player2); // Extra asserts Assert.Equal(0, player1.PlayerId); Assert.Equal(1, player2.PlayerId); }
public JsonResult Post(int id, string name, int color) { // hämtar spelet där spelaren skall skapas LudoGame game = _games.GetOrCreateGame(id); // lägg till en ny spelare till spelet Player player = game.AddPlayer(name, (PlayerColor)color); // retunera den nya spelaren return(new JsonResult(player)); }
public void AddPlayer_FirstPlayer_ReturnNotNull() { // Arrange var game = new LudoGame(new DieceMock()); // Act var player = game.AddPlayer("player1", PlayerColor.Blue); // Assert Assert.NotNull(player); Assert.Equal(0, player.PlayerId); }
public ActionResult Post(int id, string name, int color) { // hämtar spelet där spelaren skall skapas LudoGame game = _games.GetOrCreateGame(id); //kontroller så att alla spelare har unika färger if (game.GetPlayers().Where(p => (int)p.PlayerColor == color).Count() > 0) { //BadRequest = en felaktig för frågan. BadRequest är en http standard fel. return(BadRequest($"Unable to add player because color is already used")); } // lägg till en ny spelare till spelet Player player = game.AddPlayer(name, (PlayerColor)color); // retunera den nya spelaren return(new JsonResult(player)); }