2022 - When you start the game it automatically loads a saved game, adapt it to ask which game to load
Issue
When you currently start the game you are prompted "Enter L to load a game from a file, anything else to play a new game:> ". This can be found in the SetupGame method of the BreakThrough class. This is shown below:
private void SetupGame()
{
string Choice;
Console.Write("Enter L to load a game from a file, anything else to play a new game:> ");
Choice = Console.ReadLine().ToUpper();
if (Choice == "L")
{
if (!LoadGame("game1.txt"))
{
GameOver = true;
}
}
else
{
CreateStandardDeck();
Deck.Shuffle();
for (int Count = 1; Count <= 5; Count++)
{
MoveCard(Deck, Hand, Deck.GetCardNumberAt(0));
}
AddDifficultyCardsToDeck();
Deck.Shuffle();
CurrentLock = GetRandomLock();
}
}
When you choose to load a game, the program automatically loads "game1.txt".
What you need to do
- Add the code to ask for a file name & read it in from the keyboard
- Test if the file name exists, do this using File.Exists("test.txt") this will return true or false
- Create an if statement to use the File.Exists
- if true, load that file,
- if false, load "game1.txt"