/// <summary> /// Selects a game based on supplied filter /// </summary> /// <param name="filter">Filter used to select game</param> /// <returns>A game that satisfy the supplied filter</returns> public Entities.Game Execute(Entities.Filters.Game.Select filter) { Entities.Game game = _selectGame.Execute(filter); Entities.Filters.GamePlayer.Select playerFilter = new Entities.Filters.GamePlayer.Select(); playerFilter.GameID = filter.GameID; playerFilter.SelectCards = filter.DataToSelect.HasFlag(Entities.Enums.Game.Select.GamePlayerCards); List <Entities.GamePlayer> allPlayers = _selectGamePlayerREPO.Execute(playerFilter); game.Players = allPlayers.Where(x => x.PlayerType == Entities.Enums.GamePlayerType.Player).ToList(); game.Spectators = allPlayers.Where(x => x.PlayerType == Entities.Enums.GamePlayerType.Spectator).ToList(); Entities.Filters.Deck.SelectByGameID deckFilter = new Entities.Filters.Deck.SelectByGameID(); deckFilter.GameIDs.Add(game.GameID); game.GameDecks = _selectDeck.Execute(deckFilter); if (filter.DataToSelect.HasFlag(Entities.Enums.Game.Select.Rounds)) { game.Rounds.Add(_selectGameRound.Execute(game.GameID, true)); } return(game); }
/// <summary> /// Join a game /// </summary> /// <param name="gameID">The id of the game to join</param> /// <param name="user">The current user</param> /// <param name="passphrase">The passphrase for the game</param> /// <param name="playerType">Type of player joining</param> /// <returns>The response to a join request</returns> public Entities.JoinResponse Execute(Int32 gameID, Entities.User user, String passphrase, Entities.Enums.GamePlayerType playerType) { Entities.Filters.Game.Select filter = new Entities.Filters.Game.Select(); filter.GameID = gameID; filter.DataToSelect |= Entities.Enums.Game.Select.Rounds; filter.DataToSelect |= Entities.Enums.Game.Select.GamePlayerCards; Entities.Game game = _selectGame.Execute(filter); Entities.JoinResponse response = _joinGame.Execute(game, user, passphrase, playerType); if (response.Game != null) { if (response.Game.IsWaiting() && response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.SuccessfulAlreadyPlayer) == false) { _sendMessage.UpdateWaiting(response.Game, true); } else if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.NewRoundStart) == true) { _sendMessage.UpdateGame(response.Game, true); } else { _sendMessage.UpdateLobby(response.Game, true); } } return(response); }
/// <summary> /// Join a game /// </summary> /// <param name="gameID">The game to join</param> /// <param name="user">The current user</param> /// <param name="playerType">Type of player joining</param> /// <returns>If the user was able to join the game</returns> public Boolean Execute(Entities.Game game, Entities.User user, Entities.Enums.GamePlayerType playerType) { Entities.GamePlayer player = new Entities.GamePlayer(); player.GameID = game.GameID; player.Points = 0; player.User = user; player.PlayerType = playerType; Boolean successful = _insertGamePlayer.Execute(player) != -1; if (successful) { if (playerType == Entities.Enums.GamePlayerType.Player) { game.Players.Add(player); game.PlayerCount++; } else if (playerType == Entities.Enums.GamePlayerType.Spectator) { game.Spectators.Add(player); game.SpectatorCount++; } } return(successful); }
/// <summary> /// Insert a vote to kick a user <paramref name="vote"/> /// </summary> /// <param name="vote">The user's vote to kick</param> /// <returns></returns> public Entities.ActionResponses.VoteToKick Execute(Entities.GamePlayerKickVote vote) { Entities.ActionResponses.VoteToKick response = new Entities.ActionResponses.VoteToKick(); Entities.Filters.Game.Select filter = new Entities.Filters.Game.Select(); filter.DataToSelect = Entities.Enums.Game.Select.None; filter.GameID = vote.GameID; Entities.Game game = _selectGame.Execute(filter); if (game.IsCurrentPlayer(vote.VotedUserId)) { response = _insert.Execute(vote); response.ResponseCode = Entities.ActionResponses.Enums.VoteToKick.VoteSuccessful; response.Game = game; if (vote.Vote) { response.VotesToKick++; } else { response.VotesToStay++; } return(response); } else { response.ResponseCode = Entities.ActionResponses.Enums.VoteToKick.IneligiblePlayerToVote; return(response); } }
private void SendWinnerSelected(Entities.Game game, Entities.GameRound round, IEnumerable <Entities.ActiveConnection> connections, List <Entities.GamePlayer> users) { Entities.GamePlayer sendToPlayer = null; foreach (Entities.ActiveConnection connection in connections) { sendToPlayer = users.FirstOrDefault(player => player.User.UserId == connection.User_UserId); if (sendToPlayer != null) { Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game); Entities.Models.Game.Board.Answers answersModel = new Entities.Models.Game.Board.Answers(true, model.IsCommander, false, false, false, true, round.GroupedAnswers()); //The round history tab repurposed this to be the winner of the round when the page is loaded //so setting this here so that when pushed into the observable array it will look correct round.CardCommander = round.Winner(); _hub.Clients.Client(connection.ActiveConnectionID) .WinnerSelected(answersModel, model, game.IsWaiting(), game.HasWinner(), round); } } }
private void AsSpectator(Entities.Game game, Entities.User user, String passphrase, Entities.JoinResponse response) { if (game.IsCurrentSpectator(user.UserId) == false) { if (_validatePassphrase.Execute(game, passphrase) == false) { response.Result |= Entities.Enums.Game.JoinResponseCode.BadPassphrase; } else if (game.MaxSpectatorsReached()) { response.Result |= Entities.Enums.Game.JoinResponseCode.SpectatorsFull; } else { Boolean successful = _joinGame.Execute(game, user, Entities.Enums.GamePlayerType.Spectator); if (successful == false) { response.Result |= Entities.Enums.Game.JoinResponseCode.SpectatorsFull; } } } else { response.Result |= Entities.Enums.Game.JoinResponseCode.SuccessfulAlreadyPlayer; } if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.BadPassphrase) == false && response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.FullGame) == false) { response.Game = game; } }
public DTO.Game CreateGame(Entities.Game game) { return(new DTO.Game() { PlayerOne = game.PlayerOne, PlayerOneScore = game.PlayerOneScore, PlayerTwo = game.PlayerTwo, PlayerTwoScore = game.PlayerTwoScore, GameEnd = game.GameEnd, GameId = game.GameID }); }
/// <summary> /// Starts a round if certain requirements are met /// </summary> /// <param name="game">The game to start a new round for</param> /// <param name="commander">The new round's commander</param> /// <returns>If a round was successfully started</returns> public Boolean Execute(Entities.Game game, Entities.User commander) { Boolean successful = false; //Check to make sure game still has required number of players if (game.HasRequiredNumberOfPlayers()) { //Check to make sure the game has not been ended. if (game.GameOver.HasValue == false && !game.HasWinner()) { Entities.GameRound round = _insertGameRound.Execute(game.GameID, commander); successful = round.GameRoundID > 0; if (successful) { game.Rounds.Add(round); game.RoundCount++; //Deal Cards _dealCards.Execute(game); } } } return(successful); }
public bool AddGame(GameVM vm) { using (PlayContext context = new PlayContext()) { try { Game game = new Entities.Game(); Location loc = new Entities.Location(); game.Name = vm.Game.Name; game.Type = vm.Game.Type; game.Description = vm.Game.Description; game.Start = vm.Game.Start; game.End = vm.Game.End; game.Created = DateTime.Now; loc.Name = vm.Game.Location.Name; loc.Coordinates = CreatePoint(vm.Latitude, vm.Longitude); game.Location = loc; context.Games.Add(game); context.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
/// <summary> /// Play a list of cards from a user's hand /// </summary> /// <param name="cardIDs">The card IDs the user has selected </param> /// <param name="gameID">The game ID in which the user wants to play the card</param> /// <param name="userId">The user Id</param> /// <param name="autoPlayed">Were these cards auto played</param> /// <returns>PlayCard action result containing any errors and the round the card was played.</returns> public Entities.ActionResponses.PlayCard Execute(List <Int32> cardIDs, Int32 gameID, Int32 userId, Boolean autoPlayed = false) { Entities.ActionResponses.PlayCard response = _playCard.Execute(cardIDs, gameID, userId, autoPlayed); if (response.ResponseCode == Entities.ActionResponses.Enums.PlayCardResponseCode.Success) { Entities.Filters.Game.Select filter = new Entities.Filters.Game.Select(); filter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards; filter.GameID = gameID; Entities.Game game = _selectGame.Execute(filter); game.Rounds.Add(response.CurrentRound); if (response.CurrentRound.AllPlayersAnswered() && game.SecondsToPlay > 0) { var cachedJobId = MemoryCache.Default.Get(game.RoundTimerKey); BackgroundJob.Delete(cachedJobId as String); } _sendMessage.CardPlayed(game, true); _updateGame.Execute(game.GameID, DateTime.UtcNow, null); } return(response); }
/// <summary> /// Validate the passhrase policy /// </summary> /// <param name="gameID">The gameID for the game containing the policy</param> /// <param name="passphrase">The user supplied passphrase</param> /// <returns>Returns if the passphrase policy was validated</returns> public bool Execute(Int32 gameID, String passphrase) { Entities.Filters.Game.Select filter = new Entities.Filters.Game.Select(); filter.GameID = gameID; Entities.Game game = _selectGame.Execute(filter); return(_validatePassphrase.Execute(game, passphrase)); }
public void RefreshGameView(Int32 gameID, Entities.Enums.ConnectionType connectionType) { Join(gameID, connectionType); AS.GameRound.Base.ISelect _selectGameRound = BusinessLogic.UnityConfig.Container.Resolve <AS.GameRound.Base.ISelect>(); AS.Game.Base.ISelect _selectGame = BusinessLogic.UnityConfig.Container.Resolve <AS.Game.Base.ISelect>(); AS.GamePlayerKickVote.Base.ISelect _selectVotes = BusinessLogic.UnityConfig.Container.Resolve <AS.GamePlayerKickVote.Base.ISelect>(); AS.ActiveConnection.Base.ISelect _selectConnection = BusinessLogic.UnityConfig.Container.Resolve <AS.ActiveConnection.Base.ISelect>(); Int32 currentUserId = Authentication.Security.CurrentUserId; Entities.ActiveConnection connection = _selectConnection.Execute(new Entities.Filters.ActiveConnection.Select(Context.ConnectionId, currentUserId)); Entities.Filters.GamePlayerKickVote.SelectForGame kickVoteFilter = new Entities.Filters.GamePlayerKickVote.SelectForGame(); kickVoteFilter.GameID = gameID; List <Entities.GamePlayerKickVote> votes = _selectVotes.Execute(kickVoteFilter); IEnumerable <IGrouping <Int32, Entities.GamePlayerKickVote> > grouped = votes.GroupBy(x => x.KickUserId); Entities.Models.Game.Board.VoteToKick kickModel = null; List <Entities.Models.Game.Board.VoteToKick> votesToKick = new List <Entities.Models.Game.Board.VoteToKick>(); foreach (IGrouping <Int32, Entities.GamePlayerKickVote> group in grouped) { if (group.FirstOrDefault(x => x.VotedUserId == currentUserId) == null) { kickModel = new Entities.Models.Game.Board.VoteToKick(group.First().KickUser, group.Count(x => x.Vote), group.Count(x => !x.Vote)); votesToKick.Add(kickModel); } } List <Entities.GameRound> completedRounds = _selectGameRound.Execute(new Entities.Filters.GameRound.SelectCompleted(gameID)); Entities.Game game = _selectGame.Execute(new Entities.Filters.Game.Select { GameID = gameID, DataToSelect = Entities.Enums.Game.Select.GamePlayerCards | Entities.Enums.Game.Select.Rounds }); Entities.Enums.GamePlayerType playerType = (connection != null && connection.ConnectionType == Entities.Enums.ConnectionType.GamePlayer) ? Entities.Enums.GamePlayerType.Player : Entities.Enums.GamePlayerType.Spectator; Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(game, currentUserId, playerType, votesToKick, completedRounds); Clients.Client(Context.ConnectionId).UpdateGameView(model, model.LobbyViewModel); }
/// <summary> /// Update most of the game view /// </summary> /// <param name="game">The game to update</param> /// <param name="sendToSpectators">Should this update go to the spectators</param> /// <param name="forcedToLeaveUserId">The player was forced to leave</param> public void UpdateGame(Entities.Game game, Boolean sendToSpectators, Int32?forcedToLeaveUserId) { Entities.ActiveConnection excluded = Execute(game, Entities.Enums.Hubs.Actions.UpdateGameView, sendToSpectators, forcedToLeaveUserId); if (excluded != null) { _hub.Clients.Client(excluded.ActiveConnectionID).ForceLeave(); _hub.Groups.Remove(excluded.ActiveConnectionID, excluded.GroupName); } }
/// <summary> /// Validate the passhrase policy /// </summary> /// <param name="gameID">The game containing the policy</param> /// <param name="passphrase">The user supplied passphrase</param> /// <returns>Returns if the passphrase policy was validated</returns> public bool Execute(Entities.Game game, String passphrase) { Boolean policyValidated = true; if (game.IsPrivate && !String.IsNullOrEmpty(game.Passphrase)) { policyValidated = String.Equals(game.Passphrase, passphrase); } return policyValidated; }
public static Game MapGame(Entities.Game ContextGame) { Game LogicGame = new Game { ClientID = ContextGame.ClientID, GameID = ContextGame.GameID, GameName = ContextGame.GameName }; return(LogicGame); }
/// <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); }
public static Entities.Game MapGame(Game ContextGame) { Entities.Game EntityGame = new Entities.Game { GameID = ContextGame.GameID, GameName = ContextGame.GameName, ClientID = ContextGame.ClientID, Characters = ContextGame.Characters.Select(Mapper.MapCharacter).ToList(), Overviews = ContextGame.Overviews.Select(Mapper.MapOverview).ToList() }; return(EntityGame); }
private void AsPlayer(Entities.Game game, Entities.User user, String passphrase, Entities.JoinResponse response, Boolean wasWaiting) { if (game.IsCurrentPlayer(user.UserId) == false) { if (_validatePassphrase.Execute(game, passphrase) == false) { response.Result |= Entities.Enums.Game.JoinResponseCode.BadPassphrase; } else if (game.IsFull()) { response.Result |= Entities.Enums.Game.JoinResponseCode.FullGame; } else { Boolean successful = _joinGame.Execute(game, user, Entities.Enums.GamePlayerType.Player); if (successful == false) { response.Result |= Entities.Enums.Game.JoinResponseCode.FullGame; } else { if (wasWaiting && !game.IsWaiting()) { Entities.User newCommander = game.NextCommander(null); if (newCommander != null) { if (_startRound.Execute(game, game.NextCommander(null)) == true) { response.Result |= Entities.Enums.Game.JoinResponseCode.NewRoundStart; } } else { response.Result |= Entities.Enums.Game.JoinResponseCode.WaitingOnWinnerSelection; } } } } } else { response.Result |= Entities.Enums.Game.JoinResponseCode.SuccessfulAlreadyPlayer; } if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.BadPassphrase) == false && response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.FullGame) == false) { response.Game = game; } }
/// <summary> /// Insert a game record into the database /// </summary> /// <param name="user">The game to insert</param> public void Execute(Entities.Game game) { _insertGame.Execute(game); if (game.GameID > 0) { Entities.GamePlayer player = game.Players.First(); player.GameID = game.GameID; _insertGamePlayerREPO.Execute(player); } }
/// <summary> /// Update the game view when the commander has selected the winner of the round /// </summary> /// <param name="game">The game to update</param> /// <param name="round">The game's current round</param> /// <param name="sendToSpectators">Should this update go to spectators</param> public void SendWinnerSelected(Entities.Game game, Entities.GameRound round, Boolean sendToSpectators) { Entities.Filters.ActiveConnection.SelectAll filter = new Entities.Filters.ActiveConnection.SelectAll(); filter.GroupName = String.Format("Game_{0}", game.GameID); List <Entities.ActiveConnection> connections = _selectActiveConnection.Execute(filter); SendWinnerSelected(game, round, connections.Where(x => x.ConnectionType == Entities.Enums.ConnectionType.GamePlayer), game.Players); if (sendToSpectators) { SendWinnerSelected(game, round, connections.Where(x => x.ConnectionType == Entities.Enums.ConnectionType.GameSpectator), game.Spectators); } }
/// <summary> /// Insert a game record into the database /// </summary> /// <param name="user">The game to insert</param> public void Execute(Entities.Game game) { Entities.GamePlayer player = new Entities.GamePlayer { Points = 0, User = new Entities.User { UserId = game.GameCreator_UserId } }; game.Players.Add(player); _insertGame.Execute(game); }
/// <summary> /// Play cards for all players that have yet to play /// </summary> /// <param name="gameID">The game ID</param> public void Execute(int gameID) { Entities.Filters.Game.Select gameFilter = new Entities.Filters.Game.Select(); gameFilter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards | Entities.Enums.Game.Select.Rounds; gameFilter.GameID = gameID; Entities.Game game = _selectGame.Execute(gameFilter); Entities.GameRound round = game.CurrentRound(); List <Entities.GamePlayer> players = game.Players.Where(x => !round.HasAnswer(x.User.UserId) && game.IsCurrentPlayer(x.User.UserId) && !game.IsCurrentCommander(x.User.UserId)) .Select(x => x).ToList(); Int32 selectCount = 1 + (Int32)round.Question.Instructions; Random rdm = new Random(); List <Int32> cardIDs = null; Entities.ActionResponses.PlayCard response = null; foreach (Entities.GamePlayer player in players) { cardIDs = player.Hand.OrderBy(x => rdm.Next()).Take(selectCount).Select(x => x.CardID).ToList(); response = _playCard.Execute(cardIDs, gameID, player.User.UserId, true); if (response.AutoPlayedSuccess) { if (player.IdlePlayCount + 1 == 3) { //Player is forced to leave game now UnityConfig.Container.Resolve <AppServices.Game.Base.ILeave>().Execute(gameID, player.User, Entities.Enums.GamePlayerType.Player, true); } else { Entities.Filters.GamePlayer.UpdateIdlePlayCount idlePlayCount = new Entities.Filters.GamePlayer.UpdateIdlePlayCount { GameID = gameID, UserId = player.User.UserId }; _updateGamePlayer.Execute(idlePlayCount); } } } }
/// <summary> /// Get cards shuffle and seperate into questions and answers /// </summary> /// <param name="game">The game to get cards for</param> /// <param name="questions">A list of question cards</param> /// <param name="answers">A list of answer cards</param> public void Execute(Entities.Game game, out List <Entities.Card> questions, out List <Entities.Card> answers) { Entities.Filters.Card.SelectForDeal filter = new Entities.Filters.Card.SelectForDeal(); filter.GameID = game.GameID; List <Entities.Card> cards = _selectCard.Execute(filter); cards.Shuffle(); questions = cards.Where(x => x.Type == Entities.Enums.Card.CardType.Question).ToList(); answers = cards.Where(x => x.Type == Entities.Enums.Card.CardType.Answer).ToList(); questions.Shuffle(); answers.Shuffle(); }
/// <summary> /// Starts a round if certain requirements are met /// </summary> /// <param name="game">The game to start a new round for</param> /// <param name="commander">The new round's commander</param> /// <returns>If a round was successfully started</returns> public Boolean Execute(Entities.Game game, Entities.User commander) { Boolean started = _startRound.Execute(game, commander); if (started && game.SecondsToPlay > 0) { String jobId = BackgroundJob.Schedule <AppServices.GameRound.Base.ITimerExpired>(x => x.Execute(game.GameID), TimeSpan.FromSeconds(15 + game.SecondsToPlay)); MemoryCache.Default.Set(game.RoundTimerKey, jobId, new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(5) }); } _updateGame.Execute(game.GameID, DateTime.UtcNow, null); return(started); }
public void ScoreClearTest() { // Arrange var b = new Entities.Game(); var plays = new[] { 10, 9, 1, 8, 2, 10, 7, 1, 10, 8, 2, 10, 10, 10, 8, 1 }; // Act SequencialPlaysMake(b, plays); var assert1 = b.GetScore(Alley, Player); b.GetPainel(Alley).Clear(); var assert2 = b.GetScore(Alley, Player); //Assert Assert.Equal(201, assert1); Assert.Equal(0, assert2); }
public void PerfectPlaySimulateAndPlayLimitReachedExceptionTest(int[] plays, int score) { var b = new Entities.Game(); try { SequencialPlaysMake(b, plays); } catch (Exception ex) { Assert.IsType <PlayLimitReachedException>(ex); Assert.NotEqual("", ex.Message); } finally { Assert.Equal(score, b.GetScore(Alley, Player)); } }
/// <summary> /// Selects a game based on supplied filter /// </summary> /// <param name="filter">Filter used to select game</param> /// <returns>A game that satisfy the supplied filter</returns> public Entities.Game Execute(Entities.Filters.Game.Select filter) { Entities.Game game = new Entities.Game(); using (DbCommand cmd = _db.GetStoredProcCommand("Game_Select")) { _db.AddInParameter(cmd, "@GameID", DbType.Int32, filter.GameID); using (IDataReader idr = _db.ExecuteReader(cmd)) { while (idr.Read()) { game = new Entities.Game(idr); } } } return(game); }
private void ExecuteAction(Entities.Game game, Entities.Enums.Hubs.Actions action, IEnumerable <Entities.ActiveConnection> connections, List <Entities.GamePlayer> users) { Entities.GamePlayer sendToPlayer = null; foreach (Entities.ActiveConnection connection in connections) { sendToPlayer = users.FirstOrDefault(player => player.User.UserId == connection.User_UserId); if (sendToPlayer != null) { if (action == Entities.Enums.Hubs.Actions.UpdateWaiting) { _hub.Clients.Client(connection.ActiveConnectionID) .UpdateWaiting(Entities.Models.Helpers.WaitingHeader.Build(game, connection.User_UserId, GetPlayerType(connection)), GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.UpdateGameView) { Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game); _hub.Clients.Client(connection.ActiveConnectionID) .UpdateGameView(model, GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.UpdateLobby) { _hub.Clients.Client(connection.ActiveConnectionID) .UpdateLobbyView(GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.CardPlayed) { Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(game, connection.User_UserId, GetPlayerType(connection)); _hub.Clients.Client(connection.ActiveConnectionID) .UpdateAnswers(model.AnswersViewModel, !model.ShowHand); } } } }
public Game(Entities.Game game, Int32 currentUserId = 0) { this.GameID = game.GameID; this.Title = game.Title; this.IsPrivate = game.IsPrivate; this.PointToWin = game.PointToWin; this.MaxNumberOfPlayers = game.MaxNumberOfPlayers; this.DateCreated = game.DateCreated; this.PlayedLast = game.PlayedLast; this.GameDecks = game.GameDecks; this.PlayerCount = game.PlayerCount; this.Players = game.Players; this.SpectatorCount = game.SpectatorCount; this.MaxNumberOfSpectators = game.MaxNumberOfSpectators; this.IsPersistent = game.IsPersistent; this.OfficialDeckCount = game.OfficialDeckCount; this.AllowSpectators = game.MaxNumberOfSpectators > 0; this.IsFull = game.IsFull(); this.IsCurrentPlayer = game.IsCurrentPlayer(currentUserId); this.MaxSpectatorsReached = game.MaxSpectatorsReached(); this.IsCurrentSpectator = game.IsCurrentSpectator(currentUserId); }
/// <summary> /// Alert the users that the round has been lost because the commander has left /// </summary> /// <param name="game">The game</param> /// <param name="commanderName">The commander's name</param> public void CommanderLeft(Entities.Game game, String commanderName) { Entities.Filters.ActiveConnection.SelectAll filter = new Entities.Filters.ActiveConnection.SelectAll(); filter.GroupName = String.Format("Game_{0}", game.GameID); List <Entities.ActiveConnection> connections = _selectActiveConnection.Execute(filter); Entities.GamePlayer sendToPlayer = null; foreach (Entities.ActiveConnection connection in connections) { sendToPlayer = game.Players.FirstOrDefault(player => player.User.UserId == connection.User_UserId); if (sendToPlayer != null) { Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game); _hub.Clients.Client(connection.ActiveConnectionID) .CommanderLeft(model, GetGameLobbyViewModel(connection, game), commanderName, game.IsWaiting()); } } }
/// <summary> /// Selects a game based on supplied filter /// </summary> /// <param name="filter">Filter used to select game</param> /// <returns>A game that satisfy the supplied filter</returns> public Entities.Game Execute(Entities.Filters.Game.Select filter) { Entities.Game game = new Entities.Game(); using (DbCommand cmd = _db.GetStoredProcCommand("Game_Select")) { _db.AddInParameter(cmd, "@GameID", DbType.Int32, filter.GameID); using (IDataReader idr = _db.ExecuteReader(cmd)) { while (idr.Read()) { game = new Entities.Game(idr); } } } return game; }
/// <summary> /// Default Constructor /// </summary> public CreateGame() { Game = new Entities.Game(); }