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 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 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); }