Exemplo n.º 1
0
        public List <RpsPlayerStatsDataModel> SetPlayerStats(RpsGameObject concludedGame)
        {
            var listStats = new List <RpsPlayerStatsDataModel>();
            var p1        = new RpsPlayerStatsDataModel
            {
                Stats = new RpsPlayerStatsDataModel.PlayerStats()
            };

            var p2 = new RpsPlayerStatsDataModel
            {
                Stats = new RpsPlayerStatsDataModel.PlayerStats()
            };

            p1 = SetPlayerInfo(concludedGame.POne, p1);
            p1 = SetPlayerStatChoices(concludedGame.POne, p1);

            if (!SetDraw(concludedGame))
            {
                p1 = SetWinLoss(concludedGame.POne, p1);
                p2 = SetWinLoss(concludedGame.PTwo, p2);
            }
            else
            {
                p1.Stats.NumberDraws += 1;
                p2.Stats.NumberDraws += 1;
            }

            p2 = SetPlayerInfo(concludedGame.PTwo, p2);
            p2 = SetPlayerStatChoices(concludedGame.PTwo, p2);

            listStats.Add(p1);
            listStats.Add(p2);

            return(listStats);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Checks the game object to see if both players have provided an answer. If they have, we start the logic to determine who won then store their stats.
 /// </summary>
 /// <param name="game"></param>
 /// <returns></returns>
 private static RpsGameObject IsWinner(RpsGameObject game)
 {
     if (game.PTwo.Choice != null && game.POne.Choice != null)
     {
         var save     = new StatJsonController();
         var populate = new PopulateStatObject();
         var winner   = DetermineWinner(game);
         winner.RemoveGame();
         save.SaveStatsJson(populate.SetPlayerStats(winner));
         return(winner);
     }
     return(game);
 }
Exemplo n.º 3
0
        public static void RemoveInactiveGame(RpsGameObject game, IUser challenger)
        {
            var idleGameDuration = new TimeSpan(0, 0, 5, 0);
            var expirationTime   = game.StartTime.Add(idleGameDuration);
            var timeLeft         = expirationTime.Subtract(DateTime.UtcNow);

            if (expirationTime <= DateTime.UtcNow)
            {
                game.RemoveGame();
                throw new GameExpiredException($"There was a mighty battle between {game.POne.User.Username} and {game.PTwo.User.Username}, but it has expired. {challenger.Mention}, challenge your opponent again!");
            }

            throw new GameNotExpiredException($"{game.POne.User.Username} and {game.PTwo.User.Username} are battling it out. Their game started at {game.StartTime:hh:mm:ss} UTC, it will expire in {timeLeft.Minutes} minutes and {timeLeft.Seconds} seconds or if someone wins.");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks the answers provided by both players to determine the winner. After a winner is decided we set a boolean inside <see cref="RpsGameObject"/> associated with the winning or losing player.
        /// </summary>
        /// <see cref="RpsGameObject.POne"/>
        /// <see cref="RpsGameObject.PTwo"/>
        /// <returns></returns>
        private static RpsGameObject DetermineWinner(RpsGameObject game)
        {
            if (game.POne.Choice == game.PTwo.Choice)
            {
                game.POne.IsWinner = false;
                game.PTwo.IsWinner = false;
                return(game);
            }
            if (game.POne.Choice == "!scissors" && game.PTwo.Choice == "!paper" ||
                game.POne.Choice == "!paper" && game.PTwo.Choice == "!rock" ||
                game.POne.Choice == "!rock" && game.PTwo.Choice == "!scissors")
            {
                game.POne.IsWinner = true;
                return(game);
            }

            game.PTwo.IsWinner = true;
            return(game);
        }
Exemplo n.º 5
0
        public async Task <RestUserMessage> SendChallengedMessageAsync(RpsGameObject Results, SocketCommandContext Context)
        {
            if (Results == null)
            {
                return(await Context.Channel.SendMessageAsync("Waiting on your opponent!"));
            }

            if (Results.POne.IsWinner)
            {
                return(await Results.GameChannel.SendMessageAsync(null, false, AnnounceWinnerMessageEmbed.RpsWinner(Results.POne, Results.PTwo).Build()));
            }

            if (Results.PTwo.IsWinner)
            {
                return(await Results.GameChannel.SendMessageAsync(null, false, AnnounceWinnerMessageEmbed.RpsWinner(Results.PTwo, Results.POne).Build()));
            }

            if (Results.POne.IsWinner == false && Results.PTwo.IsWinner == false && Results.POne.Choice != null && Results.PTwo.Choice != null)
            {
                return(await Results.GameChannel.SendMessageAsync($"{Results.POne.User.Mention} and {Results.PTwo.User.Mention}, I'm lazy.. you've both picked the same thing. Draw!"));
            }
            return(await Context.Channel.SendMessageAsync(null, false, WaitingPlayerMessageEmbed.WaitingForOpponent().Build()));
        }
Exemplo n.º 6
0
 private static bool SetDraw(RpsGameObject player)
 {
     return(!player.POne.IsWinner && !player.PTwo.IsWinner);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Kicks off an instance of the game when a player is challenged by another player. We use <see cref="IUser"/> to store both player's Discord Name and Discord unique ID.
 /// <see cref="ISocketMessageChannel"/> is passed in to make sure we display the results in the channel where the game was initated.
 /// </summary>
 /// <param name="POne"></param>
 /// <param name="PTwo"></param>
 /// <param name="channel"></param>
 public void GameRunChallenge(IUser POne, IUser PTwo, ISocketMessageChannel channel)
 {
     var activeGame = new RpsGameObject(PopulatePlayerObject(POne), PopulatePlayerObject(PTwo), channel)
                      .InitializeGame();
 }
Exemplo n.º 8
0
 public static RpsGameObject InitializeGame(this RpsGameObject game)
 {
     RpsGameManager.ActiveGames.TryAdd(game.POne.User.Id, game);
     return(game);
 }
Exemplo n.º 9
0
 public static void RemoveGame(this RpsGameObject game)
 {
     RpsGameManager.ActiveGames.TryRemove(game.PTwo.User.Id, out var removedGameObject);
 }