Ejemplo n.º 1
0
        public void AddScoreTest()
        {
            Player target = new Player("Link");
            int score1 = 10,
                score2 = 25,
                score3 = 6,
                score4 = 14;
            target.AddScore(score1);
            target.AddScore(score2);
            target.AddScore(score3);
            target.AddScore(score4);

            //Test if expected score was added
            // Method adds, and then sorts value so should be at top
            for (int i = 0; i < target.NumberOfScores; i++)
            {
                Console.Write(" " + target.ScoreList[i] + " ");
            }
            Console.WriteLine("");
            Assert.AreEqual(target.ScoreList[0], score3);
            //Test if number of scores has been incremented
            Assert.AreEqual(target.NumberOfScores, 4);
        }
Ejemplo n.º 2
0
        public Player GetPlayerFromDb(string PlayerName)
        {
            Player getPlayer = null;

            // Holding Entity Object
            PlayerDb holdPlayer = new PlayerDb();

            // Get data from database
            // Get a context to the db
            using (var db = new PlayerDbContext())
            {

                foreach (PlayerDb findPlayer in db.PlayersDb)
                {
                    if (findPlayer.PlayerName == PlayerName)
                    {
                        getPlayer = new Player();
                        getPlayer.PlayerName = findPlayer.PlayerName;
                        getPlayer.GameStatus = findPlayer.GameStatus;
                        // Set number of scores to 0, and let value be built when loading
                        getPlayer.NumberOfScores = 0;

                        // If there are scores, need to load up player
                        // Get a context to the DB
                        using (var db1 = new PlayerDbContext())
                        {
                            if (findPlayer.NumScores > 0)
                            {
                                foreach (PlayerScore findScore in db.PlayerScores)
                                {
                                    if (findScore.PlayerDbID == findPlayer.PlayerDbID)
                                    {
                                        getPlayer.AddScore(findScore.Score);
                                    }
                                }
                            }
                            // Close DB
                            db1.Dispose();
                        }
                    }
                }
                // Close DB
                db.Dispose();
            }

            // Check to see if player was loaded, and if not throw exception
            if (getPlayer == null)
            {
                throw new PlayerNotFoundException("Player not found in DB");
            }
            return getPlayer;
        }
Ejemplo n.º 3
0
 public void AddPlayerScore(Player player, int score)
 {
     // Update player object with score
     player.AddScore(score);
 }