Example #1
0
        static void DisplayHighScore()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("==================== HIGH SCORES ====================");
            Console.WriteLine("=====================================================");
            Console.WriteLine("\n");
            Console.ResetColor();

            LoganEntities1   db            = new LoganEntities1();
            List <HighScore> highScoreList = db.HighScores.Where(x => x.Game == "Battleship").OrderBy(x => x.Score).Take(10).ToList();

            foreach (HighScore highScore in highScoreList)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("{0}. {1} - Took {2} turns to sink all ships  - {3}", highScoreList.IndexOf(highScore) + 1, highScore.Name, highScore.Score, highScore.DateCreated.Value.ToShortDateString());
                Console.ResetColor();
            }
        }
Example #2
0
        static void AddHighScore(int playerScore)
        {
            Console.WriteLine("Add your name to the highscores: ");
            string playerName = Console.ReadLine();

            LoganEntities1 db = new LoganEntities1();

            HighScore newHighScore = new HighScore();

            newHighScore.DateCreated = DateTime.Now;
            newHighScore.Name        = playerName;
            newHighScore.Game        = "Battleship";
            newHighScore.Score       = playerScore;

            db.HighScores.Add(newHighScore);

            db.SaveChanges();
        }