private async Task UpdateGameAndAddPlayer() { List <ActivePlayer> players = new List <ActivePlayer>(); CatanGame catanGame = new CatanGame { ActivePlayers = players, BanditsDistance = 7, BanditsStrength = 4 }; await _catanGameBusinessLogic.UpdateGame(catanGame); UserProfile playerProfile = await _catanPlayerBusinessLogic.GetUser(PlayerEmail1, Password); UserProfile playerProfile2 = new UserProfile { Email = PlayerEmail2, FirstName = "Some", LastName = "Some", Name = "someSomeone2", Password = Password }; await _catanPlayerBusinessLogic.UpdatePlayer(playerProfile2); await _catanGameBusinessLogic.AddPlayerToGame(catanGame, playerProfile2.Email); await _catanGameBusinessLogic.AddPlayerToGame(catanGame, playerProfile.Email); }
public async Task TestAdvanceBarbarians() { CatanGame theGame = await GetGame(); await _catanGameBusinessLogic.AdvanceBarbarians(theGame.Id); theGame = await GetGame(); Assert.AreEqual(6, theGame.BanditsDistance); await _catanGameBusinessLogic.AdvanceBarbarians(theGame.Id); await _catanGameBusinessLogic.AdvanceBarbarians(theGame.Id); await _catanGameBusinessLogic.AdvanceBarbarians(theGame.Id); await _catanGameBusinessLogic.AdvanceBarbarians(theGame.Id); await _catanGameBusinessLogic.AdvanceBarbarians(theGame.Id); await _catanGameBusinessLogic.AdvanceBarbarians(theGame.Id); theGame = await GetGame(); Assert.AreEqual(0, theGame.BanditsDistance); }
private async Task AddNonInterchaneableVPs(CatanGame catanGame, ActivePlayer activePlayer, VPType updateType) { _logger?.LogDebug($"AddVPsToSelectedPlayer game: {catanGame.Id}, player {activePlayer.Id}, updateType: {updateType.TypeToUpdate}"); switch (updateType.TypeToUpdate) { //TODO: Update remaining settlements / cities case VPType.UpdateType.City: catanGame.BanditsStrength++; activePlayer.NumOfCities++; break; case VPType.UpdateType.Settlment: activePlayer.NumOfSettlements++; break; case VPType.UpdateType.SaviorOfCatan: activePlayer.SaviorOfCatanVP++; break; case VPType.UpdateType.Constitution: case VPType.UpdateType.Printer: activePlayer.SpecialVictoryPoints++; break; } activePlayer.NumOfVictoryPoints = await GetPlayerTotalVps(activePlayer); await _catanGamePersist.UpdateGame(catanGame); }
public async Task TestAddPlayerKnight() { CatanGame theCatanGame = await GetGame(); ActivePlayer activePlayer = theCatanGame.ActivePlayers.FirstOrDefault(); await _catanGameBusinessLogic.AddPlayerKnight(theCatanGame.Id, activePlayer.Id, KnightRank.Basic); theCatanGame = await GetGame(); activePlayer = theCatanGame.ActivePlayers.FirstOrDefault(); Assert.AreEqual(1, activePlayer.NumOfTotalKnights); await _catanGameBusinessLogic.AddPlayerKnight(theCatanGame.Id, activePlayer.Id, KnightRank.Strong); theCatanGame = await GetGame(); activePlayer = theCatanGame.ActivePlayers.FirstOrDefault(); Assert.AreEqual(3, activePlayer.NumOfTotalKnights); await _catanGameBusinessLogic.AddPlayerKnight(theCatanGame.Id, activePlayer.Id, KnightRank.Mighty); theCatanGame = await GetGame(); activePlayer = theCatanGame.ActivePlayers.FirstOrDefault(); Assert.AreEqual(6, activePlayer.NumOfTotalKnights); }
public async Task TestGetPlayerActiveGames() { UserProfile playerProfile = await _catanPlayerBusinessLogic.GetUser(PlayerEmail1, Password); IEnumerable <CatanGame> playerGames = await _catanGameBusinessLogic.GetUserActiveGames(playerProfile.UserName); CatanGame theCatanGame = playerGames.FirstOrDefault(); Assert.IsNotNull(theCatanGame); Assert.IsTrue(theCatanGame.ActivePlayers.Select(activePlayer => activePlayer.UserName).Contains(playerProfile.UserName)); }
public async Task UpdateGame(CatanGame catanGame) { _logger?.LogDebug($"UpdateGame for game: {catanGame.Id}"); if (catanGame.ActivePlayers == null) { catanGame.ActivePlayers = new List <ActivePlayer>(); } if (catanGame.RecentDiceRolls == null) { catanGame.RecentDiceRolls = new List <Tuple <int, int> >(); } await _catanGamePersist.UpdateGame(catanGame); }
public async Task TestActivateAllKnightsForPlayer() { CatanGame theCatanGame = await GetGame(); ActivePlayer activePlayer = theCatanGame.ActivePlayers.FirstOrDefault(); await TestAddPlayerKnight(); await _catanGameBusinessLogic.ActivateAllKnightsForPlayer(theCatanGame.Id, activePlayer.Id); theCatanGame = await GetGame(); activePlayer = theCatanGame.ActivePlayers.FirstOrDefault(); Assert.AreEqual(6, activePlayer.NumOfActiveKnights); }
public async Task TestDeactivateAllKnights() { UserProfile playerProfile = await _catanPlayerBusinessLogic.GetUser(PlayerEmail1, Password); IEnumerable <CatanGame> playerGames = await _catanGameBusinessLogic.GetUserActiveGames(playerProfile.UserName); CatanGame theCatanGame = playerGames.FirstOrDefault(); await _catanGameBusinessLogic.DeactivateAllKnights(theCatanGame.Id); playerGames = await _catanGameBusinessLogic.GetUserActiveGames(playerProfile.UserName); theCatanGame = playerGames.FirstOrDefault(); foreach (ActivePlayer activePlayer in theCatanGame.ActivePlayers) { Assert.AreEqual(0, activePlayer.NumOfActiveKnights); } }
public async Task AddPlayerToGame(CatanGame catanGame, string userName) { _logger?.LogDebug($"AddPlayerToGame for catanGame: {catanGame.Id}, player: {userName}"); ActivePlayer activePlayer = new ActivePlayer { Id = Guid.NewGuid(), InterChanageableVPs = new List <VPType.InterChanageableVP>(), NumOfActiveKnights = 0, NumOfCities = 0, NumOfContinousRoads = 0, NumOfSettlements = 0, NumOfTotalKnights = 0, UserName = userName }; catanGame.ActivePlayers.Add(activePlayer); await _catanGamePersist.UpdateGame(catanGame); }
public async Task AddPlayerVictoryPoint(CatanGame catanGame, ActivePlayer activePlayer, VPType updateType) { _logger?.LogDebug($"AddPlayerVictoryPoint for catanGame: {catanGame.Id}, player: {activePlayer.Id}, updateType: {updateType}"); if (updateType.TypeToUpdate == VPType.UpdateType.Interchangeable) { IEnumerable <ActivePlayer> activePlayers = catanGame?.ActivePlayers.Where(player => player.InterChanageableVPs.Contains(updateType.TypeOfInterchangeable)); ActivePlayer reduceVPCandidate = activePlayers?.FirstOrDefault(); if (reduceVPCandidate != null) { reduceVPCandidate.InterChanageableVPs.Remove(updateType.TypeOfInterchangeable); reduceVPCandidate.NumOfVictoryPoints = await GetPlayerTotalVps(reduceVPCandidate); } activePlayer.InterChanageableVPs.Add(updateType.TypeOfInterchangeable); activePlayer.NumOfVictoryPoints = await GetPlayerTotalVps(activePlayer); await _catanGamePersist.UpdateGame(catanGame); return; } await AddNonInterchaneableVPs(catanGame, activePlayer, updateType); }
public async Task TestAddPlayerVictoryPoint() { CatanGame theGame = await GetGame(); int firstPlayerExpectedVPs = 0; int secondPlayerExpectedVPs = 0; VPType vpType = new VPType(VPType.UpdateType.City); firstPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.FirstOrDefault(), vpType); theGame = await GetGame(); int numOfCities = theGame.ActivePlayers.FirstOrDefault().NumOfCities; Assert.AreEqual(1, numOfCities); Assert.AreEqual(0, theGame.ActivePlayers.FirstOrDefault().NumOfSettlements); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Settlment); firstPlayerExpectedVPs++; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.FirstOrDefault(), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.LongestRoad); firstPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.FirstOrDefault(), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.Merchant); firstPlayerExpectedVPs++; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.FirstOrDefault(), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.MetropolisCloth); firstPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.FirstOrDefault(), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.MetropolisCoin); firstPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.FirstOrDefault(), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.MetropolisPaper); firstPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.FirstOrDefault(), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.SaviorOfCatan); firstPlayerExpectedVPs++; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.FirstOrDefault(), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); // Replace Interchangeable vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.LongestRoad); firstPlayerExpectedVPs -= 2; secondPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.ElementAt(1), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.Merchant); firstPlayerExpectedVPs--; secondPlayerExpectedVPs++; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.ElementAt(1), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.MetropolisCloth); firstPlayerExpectedVPs -= 2; secondPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.ElementAt(1), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.MetropolisCoin); firstPlayerExpectedVPs -= 2; secondPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.ElementAt(1), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.Interchangeable, VPType.InterChanageableVP.MetropolisPaper); firstPlayerExpectedVPs -= 2; secondPlayerExpectedVPs += 2; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.ElementAt(1), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); vpType = new VPType(VPType.UpdateType.SaviorOfCatan); secondPlayerExpectedVPs++; await _catanGameBusinessLogic.AddPlayerVictoryPoint(theGame, theGame.ActivePlayers.ElementAt(1), vpType); theGame = await GetGame(); Assert.AreEqual(firstPlayerExpectedVPs, theGame.ActivePlayers.FirstOrDefault().NumOfVictoryPoints); Assert.AreEqual(secondPlayerExpectedVPs, theGame.ActivePlayers.ElementAt(1).NumOfVictoryPoints); }
public async Task RemoveGame(CatanGame catanGame) { _logger?.LogDebug($"RemoveGame for catanGame: {catanGame.Id}"); await _catanGamePersist.RemoveGame(catanGame); }
public async Task UpdatePlayerInGame(CatanGame catanGame, ActivePlayer playerToUpdate) { _logger?.LogDebug($"UpdatePlayerInGame for catanGame: {catanGame.Id}, player to update: {playerToUpdate.Id}"); await _catanGamePersist.UpdatePlayerInGame(catanGame, playerToUpdate); }
public async Task RemoveGame([FromBody] CatanGame catanGame) { _logger?.LogDebug($"RemoveGame for game: {catanGame.Id}"); await _catanGameBusinessLogic.RemoveGame(catanGame); }