public void GetAverageScores_Player_PlayersAverageScore()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();

            Game playerGame1 = testPlayer.AddGame();

            playerGame1.Play(0.6m, 5, testPlayer);
            decimal game1Score = testPlayer.GetMoney();

            testPlayer.SaveScore();

            Game playerGame2 = testPlayer.AddGame();

            playerGame2.Play(0.6m, 5, testPlayer);
            decimal game2Score = testPlayer.GetMoney();

            testPlayer.SaveScore();

            Game playerGame3 = testPlayer.AddGame();

            playerGame3.Play(0.6m, 5, testPlayer);
            decimal game3Score = testPlayer.GetMoney();

            testPlayer.SaveScore();

            decimal expected = (game3Score + game2Score + game1Score) / 3m;

            Dictionary <string, object> actual = testPlayer.GetAverageScore();

            Assert.Equal(expected, actual["averageScoreDecimal"]);
        }
        public void AddGame_WhenPlayerPlaysThreeTimes_ReturnCount3()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();

            Game playerGame1 = testPlayer.AddGame();

            Game playerGame2 = testPlayer.AddGame();

            Game playerGame3 = testPlayer.AddGame();

            Assert.Equal(3, testPlayer.GetCount());
        }
Exemple #3
0
        public void Play_PlayerGame_RemainingMoneyLessThanStartingMoney()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();
            decimal startingMoney = testPlayer.GetMoney();

            Console.WriteLine(startingMoney);

            Game playerGame = testPlayer.AddGame();
            Dictionary <string, object> results = playerGame.Play(20m, 1, testPlayer);

            decimal endingMoney = testPlayer.GetMoney();

            Console.WriteLine("forecast " + playerGame.GetForecast());
            Console.WriteLine("temp " + playerGame.GetTemperature());
            Console.WriteLine("cupsSold " + results["cupsSold"]);
            Console.WriteLine("profitString " + results["profitString"]);
            Console.WriteLine("availableString " + results["availableString"]);

            Console.WriteLine(startingMoney);
            Console.WriteLine(endingMoney);

            bool testBool = (startingMoney > endingMoney);

            Assert.Equal(true, testBool);
        }
        public void Find_FindPlayerByIdReturnsCount_ReturnsCorrectCount()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();

            Game playerGame1 = testPlayer.AddGame();

            playerGame1.Play(0.6m, 5, testPlayer);
            Game playerGame2 = testPlayer.AddGame();

            playerGame2.Play(0.6m, 5, testPlayer);
            Game playerGame3 = testPlayer.AddGame();

            playerGame3.Play(0.6m, 5, testPlayer);

            Player foundPlayer = Player.Find(testPlayer.GetId());

            Assert.Equal(testPlayer.GetCount(), foundPlayer.GetCount());
        }
        public void AddGame_Player_AddGameToPlayer()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();

            Game playerGame = testPlayer.AddGame();

            Player gamePlayer = playerGame.GetPlayer();

            Assert.Equal(gamePlayer, testPlayer);
        }
Exemple #6
0
        public void GetPlayer_PlayerMaintainsCount_CorrectCount()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();

            Game playerGame1 = testPlayer.AddGame();

            playerGame1.Play(0.6m, 5, testPlayer);
            Game playerGame2 = testPlayer.AddGame();

            playerGame2.Play(0.6m, 5, testPlayer);
            Game playerGame3 = testPlayer.AddGame();

            playerGame3.Play(0.6m, 5, testPlayer);

            int expected = testPlayer.GetCount();

            Player foundPlayer = playerGame3.GetPlayer();
            int    actual      = foundPlayer.GetCount();

            Assert.Equal(expected, actual);
        }
        public void SaveScore_PlayerMoneyResetTo20_20()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();

            while (testPlayer.GetCount() < 8)
            {
                Game playerGame = testPlayer.AddGame();
            }
            testPlayer.SaveScore();

            Assert.Equal(20m, testPlayer.GetMoney());
        }
        public void SaveScore_WhenPlayerPlaysEightTimes_ReturnZero()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();

            while (testPlayer.GetCount() < 8)
            {
                Game playerGame = testPlayer.AddGame();
            }
            testPlayer.SaveScore();

            Assert.Equal(0, testPlayer.GetCount());
        }
        public void SaveScore_SavesScoreInDatabase_GetScores()
        {
            Player testPlayer = new Player("coolgurl123", "password123");

            testPlayer.Save();

            Game playerGame = testPlayer.AddGame();

            playerGame.Play(0.6m, 5, testPlayer);
            //ExpectedScores needs to be declared and captured before SaveScore method because SaveScore method resets player's money to 20m
            List <decimal> ExpectedScores = new List <decimal> {
                testPlayer.GetMoney()
            };

            testPlayer.SaveScore();

            List <decimal> ActualScores = testPlayer.GetScores();

            Assert.Equal(ExpectedScores, ActualScores);
        }
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            //if player is a new user:
            Post["/new-user/game"] = _ => {
                Player foundPlayer = Player.Search(Request.Form["username"], Request.Form["password"]);
                if (foundPlayer.GetUsername() == null)
                {
                    Dictionary <string, object> model = new Dictionary <string, object> {
                    };
                    Player newPlayer = new Player(Request.Form["username"], Request.Form["password"]);
                    newPlayer.Save();
                    Game    playerGame      = newPlayer.AddGame();
                    decimal pricePerPitcher = playerGame.GetPitcherPrice();
                    decimal playerMoney     = newPlayer.GetMoney();
                    int     limit           = Convert.ToInt32(playerMoney / pricePerPitcher);
                    model.Add("limit", limit);
                    model.Add("game", playerGame);
                    model.Add("player", newPlayer);
                    model.Add("count", newPlayer.GetCount());
                    return(View["Game.cshtml", model]);
                }
                else
                {
                    string model = "duplicate";
                    return(View["index.cshtml", model]);
                }
            };
            //if player is returning player
            Post["/returning-user/game"] = _ => {
                //TODO: fix this code so that page only displays and game is only created if foundPlayer exists; maybe catch certain cases
                Player foundPlayer = Player.Search(Request.Form["username"], Request.Form["password"]);
                if (foundPlayer.GetUsername() != null || foundPlayer.GetPassword() != null)
                {
                    Dictionary <string, object> model = new Dictionary <string, object> {
                    };
                    foundPlayer.ResetMoneyAndCount();
                    Game    playerGame      = foundPlayer.AddGame();
                    decimal pricePerPitcher = playerGame.GetPitcherPrice();
                    decimal playerMoney     = foundPlayer.GetMoney();
                    int     limit           = Convert.ToInt32(playerMoney / pricePerPitcher);
                    model.Add("limit", limit);
                    model.Add("game", playerGame);
                    model.Add("player", foundPlayer);
                    model.Add("count", foundPlayer.GetCount());
                    return(View["Game.cshtml", model]);
                }
                else
                {
                    //this is for a failed login
                    string model = "login-fail";
                    return(View["index.cshtml", model]);
                }
            };

            Post["/results"] = _ => {
                Game   foundGame                  = Game.Find(Request.Form["game-id"]);
                Player foundGamePlayer            = foundGame.GetPlayer();
                Dictionary <string, object> model = foundGame.Play(Request.Form["cup"], Request.Form["pitcher"], foundGamePlayer);
                model.Add("game", foundGame);
                model.Add("count", foundGamePlayer.GetCount());

                //average score below
                List <decimal> allScores = foundGamePlayer.GetScores();
                if (allScores.Count > 0)
                {
                    Dictionary <string, object> averageScore = foundGamePlayer.GetAverageScore();
                    model.Add("averageScore", averageScore["averageScoreString"]);
                }
                else
                {
                    model.Add("averageScore", model["remainingMoney"]);
                }
                return(View["results.cshtml", model]);
            };


            Post["/another/game"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Player foundPlayer = Player.Find(Request.Form["player-id"]);
                if (foundPlayer.GetCount() >= 7)
                {
                    foundPlayer.SaveScore();
                    foundPlayer.ResetMoneyAndCount();
                    Game playerGame = foundPlayer.AddGame();
                    model.Add("count", foundPlayer.GetCount());
                    decimal pricePerPitcher = playerGame.GetPitcherPrice();
                    decimal playerMoney     = foundPlayer.GetMoney();
                    int     limit           = Convert.ToInt32(playerMoney / pricePerPitcher);
                    model.Add("limit", limit);
                    model.Add("game", playerGame);
                    model.Add("player", foundPlayer);
                    return(View["Game.cshtml", model]);
                }
                else
                {
                    Game    playerGame      = foundPlayer.AddGame();
                    decimal pricePerPitcher = playerGame.GetPitcherPrice();
                    decimal playerMoney     = foundPlayer.GetMoney();
                    int     limit           = Convert.ToInt32(playerMoney / pricePerPitcher);
                    model.Add("limit", limit);
                    model.Add("game", playerGame);
                    model.Add("player", foundPlayer);
                    model.Add("count", foundPlayer.GetCount());
                    return(View["Game.cshtml", model]);
                }
            };

            Post["/start-over"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Player foundPlayer = Player.Find(Request.Form["player-id"]);
                foundPlayer.ResetMoneyAndCount();
                Game    playerGame      = foundPlayer.AddGame();
                decimal pricePerPitcher = playerGame.GetPitcherPrice();
                decimal playerMoney     = foundPlayer.GetMoney();
                int     limit           = Convert.ToInt32(playerMoney / pricePerPitcher);
                model.Add("limit", limit);
                model.Add("game", playerGame);
                model.Add("player", foundPlayer);
                model.Add("count", foundPlayer.GetCount());
                return(View["Game.cshtml", model]);
            };
        }