예제 #1
0
        private static void LoadSavedGame()
        {
            var loadGameMenu = new Menu(1);

            var savedGames = SavedGameHandler.GetSavedGames();

            if (!savedGames.Any())
            {
                Console.WriteLine("No saved games found!");
                return;
            }

            var i = 1;

            foreach (var existingSavedGame in savedGames)
            {
                loadGameMenu.addMenuItem(i.ToString(), new MenuItem()
                {
                    Title            = existingSavedGame.DateTime.ToString(),
                    CommandToExecute = () =>
                    {
                        _savedGame = existingSavedGame;
                        return("X");
                    }
                });
                i++;
            }

            loadGameMenu.Run();
            Play();
        }
예제 #2
0
        public IActionResult OnGetSaveGame()
        {
            var game = DeSerializeGame();

            if (SavedGameId == null)
            {
                SavedGameHandler.SaveGame(game);
            }
            else
            {
                var existingSavedGame = GetSavedGames().First(sg => sg.SavedGameId == SavedGameId);
                SavedGameHandler.SaveGame(game, existingSavedGame);
            }

            return(Redirect("./Game"));
        }
예제 #3
0
 public DbSet <SavedGame> GetSavedGames()
 {
     return(SavedGameHandler.GetSavedGames());
 }
예제 #4
0
        private static void SaveGame(Game game)
        {
            if (game.GameStatus == GameStatus.NotStarted)
            {
                Console.WriteLine("Please make the first move before saving!");
                return;
            }
            var saveActionMenu = new Menu()
            {
                Title = "Save Game",
                MenuItemsDictionary = new Dictionary <string, MenuItem>()
                {
                    { "1", new MenuItem()
                      {
                          Title            = "Save a new game",
                          CommandToExecute = () => SaveGame(false)
                      } },
                    { "2", new MenuItem()
                      {
                          Title            = "Overwrite an existing saved game",
                          CommandToExecute = () => SaveGame(true)
                      } }
                }
            };

            String SaveGame(Boolean overrideExistingSave)
            {
                var saveGameSelectMenu = new Menu();

                if (overrideExistingSave)
                {
                    var savedGames = SavedGameHandler.GetSavedGames();

                    if (!savedGames.Any())
                    {
                        Console.WriteLine("No saved games found!");
                        return("");
                    }

                    var i = 1;
                    foreach (var existingSavedGame in savedGames)
                    {
                        saveGameSelectMenu.addMenuItem(i.ToString(), new MenuItem()
                        {
                            Title            = existingSavedGame.DateTime.ToString(),
                            CommandToExecute = () =>
                            {
                                SavedGameHandler.SaveGame(game, existingSavedGame);
                                return("X");
                            }
                        });
                        i++;
                    }

                    return(saveGameSelectMenu.Run());
                }

                SavedGameHandler.SaveGame(game);
                return("X");
            }

            saveActionMenu.Run();
        }