예제 #1
0
        static void DisplayHighScores()
        {
            //clear the console
            Console.Clear();
            Console.Title = "ΦHangman High ScoresΦ";
            Console.WriteLine("Hangman High Scores");
            Console.WriteLine("≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡");

            //create a new connection to the database
            CianEntities db = new CianEntities();
            //get the high score list
            List <HighScore> highScoreList = db.HighScores.Where(x => x.Game == "Hangman").OrderBy(x => x.Score).Take(10).ToList();

            foreach (HighScore highScore in highScoreList)
            {
                Console.WriteLine("{0}. {1} - {2}", highScoreList.IndexOf(highScore) + 1, highScore.Name, highScore.Score);
            }
        }
예제 #2
0
        static void AddHighScore(int playerScore)
        {
            //create a gateway to the database
            CianEntities db = new CianEntities();

            //create a new high score object
            // fill it with our user's data
            HighScore newHighScore = new HighScore();

            newHighScore.DateCreated = DateTime.Now;
            newHighScore.Game        = "Hangman";
            newHighScore.Name        = name;
            newHighScore.Score       = playerScore;

            //add it to the database
            db.HighScores.Add(newHighScore);

            //save our changes
            db.SaveChanges();
        }