public static void gameStart() { Player player = new Player(); while (runProgram == true) { StandardMessages.IntroductionMessage(); string startGame = Console.ReadLine().ToUpper(); // Lets the user enter input to either start the game or load a previous save if (startGame == "START") { player = CharacterCreation.createCharacter(); Console.Write("\nYou move into the Entrance of the dungeon.\n"); moveThroughDungeon(); } else if (startGame == "LOAD") { bool saveGame = false; bool loadGame = true; // Loads the player's information from a method that reads a file. player = CharacterCreation.storePlayerInfo(saveGame, loadGame); moveThroughDungeon(); } else { Console.Write(startGame + " is not a valid option, please try again.\n\n"); gameStart(); } } }
public static void saveGame() { // Method that saves the player's game bool saveGame = true; bool loadGame = false; Player player = new Player(); player = CharacterCreation.storePlayerInfo(saveGame, loadGame); SqliteDataAccess.savePlayer(player); // Old version of saving that was used when text files what stored information /* * StreamWriter playerFile; * string playerName = player.name; * * // Variable that creates a file with the same name as the player character * string playerFileName = playerName + ".txt"; * * // Writes player information to a file * playerFile = File.CreateText(playerFileName); * playerFile.WriteLine(playerName.ToString()); * playerFile.WriteLine(player.password.ToString()); * playerFile.WriteLine(player.playerClass); * playerFile.WriteLine(player.playerRace); * playerFile.WriteLine(player.health); * playerFile.WriteLine(player.agility); * playerFile.WriteLine(player.armorValue); * playerFile.Close(); */ }
public static Player storePlayerInfo(bool saveGame, bool loadGame) { // Saves the game if (saveGame == true) { // Method for storing player info to use later on. Player playerInfo = new Player(); playerInfo.name = player.name; playerInfo.password = player.password; playerInfo.playerClass = player.playerClass; playerInfo.playerRace = player.playerRace; playerInfo.health = player.health; playerInfo.agility = player.agility; playerInfo.armorValue = player.armorValue; playerInfo.playerInventory = player.playerInventory; return(player); } // Loads the game else { Console.WriteLine("Please enter the name of your character: "); string playerName = Console.ReadLine(); // Try-catch that will prevent the user from messing up the program by entering a name not in the database try { player = SqliteDataAccess.loadPlayer(playerName); Console.WriteLine("Please enter in your password to confirm it is you: "); string userPassword = Console.ReadLine(); while (player.password != userPassword) { Console.WriteLine("Invalid password entered, please try again:"); userPassword = Console.ReadLine(); } return(player); } catch { Console.WriteLine("File not found, aborting load..."); CharacterCreation.storePlayerInfo(saveGame, loadGame); return(player); } } }
public static Player getCurrentPlayer() { Player player = CharacterCreation.currentPlayer(); return(player); }