Пример #1
0
        public void run()
        {
            try {
                while (snake.lives > 0)
                {
                    events();
                    update();
                    display();
                    Thread.Sleep(Settings.SPEED);
                }
            } catch (IndexOutOfRangeException) {
                Console.WriteLine("You hit a wall!");
            }

            Console.ForegroundColor = UI.GAMEOVERCOLOR;
            Console.WriteLine("GAMEOVER");

            ScoreTime theirGame = new ScoreTime {
                score    = snake.size,
                duration = time
            };

            if (theirGame.OnLeaderBoard(topGames))
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("CONGRATS!\nYou're made it on the leaderboard.\nWhat's your name?");
                theirGame.name = Console.ReadLine();
                topGames.Add(theirGame);
                Tools.saveTop3Games(topGames);
            }
            Console.WriteLine("Press a button to close the terminal");
            Console.ReadLine();
        }
Пример #2
0
 public bool Better(ScoreTime other)
 {
     if (score == other.score)
     {
         return(duration < other.duration);
     }
     return(score > other.score);
 }
Пример #3
0
        public static void saveTop3Games(List <ScoreTime> games)
        {
            games = ScoreTime.Sort(games);
            if (games.Count > 3)
            {
                games.RemoveAt(3);
            }

            SerializeNow(games);
        }
Пример #4
0
 public static List <ScoreTime> getTopGames()
 {
     try
     {
         return(ScoreTime.Sort(DeSerializeNow()));
     }
     catch (FileNotFoundException)
     {
         return(new List <ScoreTime>());
     }
 }