예제 #1
0
        // Loading Active Games To List, Player Can Choose What Game To Continue Playing
        public static void LoadGamesUI()
        {
            Console.Clear();

            List <Game>   games   = new LudoDbAccess().GetAllUnfinishedGames();
            List <Player> players = new LudoDbAccess().GetAllPlayers();

            UserInterface userInterface = new UserInterface();

            if (games.Count == 0)
            {
                Console.WriteLine("Sorry mate, no games to be found " +
                                  "\nPlease create a new game.");
                Thread.Sleep(2000);
                userInterface.MainMenu();
            }

            while (isRunning)
            {
                Console.WriteLine("What game do you want to load?\n");

                for (int i = 0; i < games.Count; i++)
                {
                    playerCounter = 0;
                    Console.WriteLine($"[{games[i].Id}]\nGame Id: {games[i].Id}\nLast Played: {games[i].LastTimePlayedDate}");
                    Console.Write($"Players:");


                    foreach (Player p in players)
                    {
                        if (p.GameId == games[i].Id)
                        {
                            Console.Write($"\nPlayer: {p.Name} | Color: {playerColors[playerCounter]}");
                            playerCounter++;
                        }
                    }


                    Console.WriteLine($"\n---------------------------------------------------------------------------\n");
                }

                int.TryParse(Console.ReadLine(), out userInput);

                foreach (var g in games)
                {
                    if (userInput == g.Id)
                    {
                        LoadGame loadGame = new LoadGame();

                        Console.WriteLine($"Loading game id {g.Id}...");
                        loadGame.LoadAnyGame(g.Id);
                    }
                }
            }
        }