/// <summary> /// Update a game player's point count /// </summary> /// <param name="filter">The filter used to update a player's points</param> public void Execute(Entities.Filters.GamePlayer.UpdatePoints filter) { using (DbCommand cmd = _db.GetStoredProcCommand("GamePlayer_UpdatePoints")) { _db.AddInParameter(cmd, "@GameID", DbType.Int32, filter.GameID); _db.AddInParameter(cmd, "@UserId", DbType.Int32, filter.UserId); _db.ExecuteNonQuery(cmd); } }
/// <summary> /// Complete the current round /// </summary> /// <param name="gameID">The ID of the game that contains the round</param> /// <param name="cardIDs">The IDs of the winning cards</param> /// <param name="userId">The user Id trying to complete the round</param> /// <returns></returns> public Entities.ActionResponses.RoundComplete Execute(Int32 gameID, List <Int32> cardIDs, Int32 userId) { Entities.ActionResponses.RoundComplete response = new Entities.ActionResponses.RoundComplete(); Entities.GameRound currentRound = _selectGameRound.Execute(gameID, true); //Validate that the user trying to complete the round is in fact the commander if (currentRound.IsCommander(userId)) { //Validate that select cards were actually played during the round List <Int32> invalidWinners = currentRound.ValidateWinnerSelection(cardIDs); if (invalidWinners.Count == 0) { Entities.User newCommander = currentRound.Winner(); //Update cards as winners Entities.Filters.GameRoundCard.UpdateWinner cardfilter = new Entities.Filters.GameRoundCard.UpdateWinner(); cardfilter.CardIDs = cardIDs; cardfilter.GameID = gameID; Boolean autoPlayed = _updateGameRoundCard.Execute(cardfilter); if (!autoPlayed) { //Update player points Entities.Filters.GamePlayer.UpdatePoints playerFilter = new Entities.Filters.GamePlayer.UpdatePoints(); playerFilter.GameID = gameID; playerFilter.UserId = newCommander.UserId; _updateGamePlayer.Execute(playerFilter); } //Start round Entities.Filters.Game.Select gameFilter = new Entities.Filters.Game.Select(); gameFilter.GameID = gameID; gameFilter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards; Entities.Game game = _selectGame.Execute(gameFilter); response.NewRoundCreated = _startGameRoud.Execute(game, game.NextCommander(newCommander)); response.CompletedRound = currentRound; response.Game = game; if (!response.NewRoundCreated) { response.Game.Rounds.Add(currentRound); } } } return(response); }
/// <summary> /// Update a game player's point count /// </summary> /// <param name="filter">The filter used to update a player's points</param> public void Execute(Entities.Filters.GamePlayer.UpdatePoints filter) { _update.Execute(filter); }
/// <summary> /// Complete the current round /// </summary> /// <param name="gameID">The ID of the game that contains the round</param> /// <param name="cardIDs">The IDs of the winning cards</param> /// <param name="userId">The user Id trying to complete the round</param> /// <returns></returns> public Entities.ActionResponses.RoundComplete Execute(Int32 gameID, List<Int32> cardIDs, Int32 userId) { Entities.ActionResponses.RoundComplete response = new Entities.ActionResponses.RoundComplete(); Entities.GameRound currentRound = _selectGameRound.Execute(gameID, true); //Validate that the user trying to complete the round is in fact the commander if (currentRound.IsCommander(userId)) { //Validate that select cards were actually played during the round List<Int32> invalidWinners = currentRound.ValidateWinnerSelection(cardIDs); if (invalidWinners.Count == 0) { Entities.User newCommander = currentRound.Winner(); //Update cards as winners Entities.Filters.GameRoundCard.UpdateWinner cardfilter = new Entities.Filters.GameRoundCard.UpdateWinner(); cardfilter.CardIDs = cardIDs; cardfilter.GameID = gameID; Boolean autoPlayed = _updateGameRoundCard.Execute(cardfilter); if (!autoPlayed) { //Update player points Entities.Filters.GamePlayer.UpdatePoints playerFilter = new Entities.Filters.GamePlayer.UpdatePoints(); playerFilter.GameID = gameID; playerFilter.UserId = newCommander.UserId; _updateGamePlayer.Execute(playerFilter); } //Start round Entities.Filters.Game.Select gameFilter = new Entities.Filters.Game.Select(); gameFilter.GameID = gameID; gameFilter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards; Entities.Game game = _selectGame.Execute(gameFilter); response.NewRoundCreated = _startGameRoud.Execute(game, game.NextCommander(newCommander)); response.CompletedRound = currentRound; response.Game = game; if(!response.NewRoundCreated) { response.Game.Rounds.Add(currentRound); } } } return response; }