/// <summary> /// Loads the game from the given save file /// </summary> /// <param name="saveFile">the path to the save file</param> private static void LoadGame(string saveFile) { // Reset the random generator RandomFactory.Reset(); // Reset the id factory IdFactory.ResetIdFactory(); // Create the GamePlay simulator GamePlay sim = new GamePlay(saveFile); // Replace this instance of Game with the simulated one game = sim.GetLoadedGame(); }
static void Main(string[] args) { PrettyPrintLogo(); InitGame(); _gameConfiguration = RandomGameConfig(_gameConfiguration); RandomFactory.Reset(); // Reset the random generator, for easier saving/loading game = CreateGame(_gameConfiguration); SaveHelper.RecordConfig(_gameConfiguration); // Record the game configuration bool gameover = false; while (!gameover && !game.Gameover) { // Check which actions the player can take CheckPossibleActions(); sb.Clear(); // Fill the stringbuilder with some fitting flavortext sb.Append($"** HP: ").Append(game.Player.Hp).Append("/").Append(game.Player.HpMax).Append(", location: ").Append(game.Player.Location.Id).Append("\n"); sb.Append("You enter a cold and damp room "); switch (_gameConfiguration.difficultyMode) { case DifficultyMode.NEWBIEmode: sb.Append("and you see "); break; case DifficultyMode.NORMALmode: sb.Append("and with the light from your torch you see "); break; case DifficultyMode.ELITEmode: sb.Append("and in the darkness you can barely make out "); break; } if (_possibleActions.CanMove) // canMove means no combat { sb.Append("an empty room"); if (_possibleActions.CanPickup) { sb.Append($" with {game.Player.Location.Items.Count.ToString()} items laying on the ground"); } sb.Append(".\n"); } else { sb.Append($"{game.Player.Location.Monsters.Count.ToString()} horrible monsters coming towards you"); if (_possibleActions.CanPickup) { sb.Append( $" with {game.Player.Location.Items.Count.ToString()} items laying on the ground behind them"); } sb.Append(".\n"); } sb.Append("What do you do?").Append("\n"); Console.WriteLine(sb.ToString()); sb.Clear(); // Print the options PrintPossibleActions(); // Read the input var input = ReadValidInput(); switch (input) { case 'm': // Move PrintMoveTargets(); game.Update(new Command(CommandType.MOVE, GetMoveTarget())); break; case 'a': // Attack PrintAttackTargets(); game.Update(new Command(CommandType.ATTACK, GetAttackTarget())); break; case 'u': // Use PrintUseTargets(); game.Update(new Command(CommandType.USE, GetUseTarget())); break; case 'p': // Pickup game.Update(new Command(CommandType.PICKUP, "")); break; case 'f': // Flee game.Update(new Command(CommandType.FLEE, "")); break; case ' ': // Do nothing game.Update(new Command(CommandType.DoNOTHING, "")); break; case 's': // Save SaveHelper.SaveToFile("save.txt"); break; case 'l': // Load LoadGame("save.txt"); break; case 'q': // Quit SaveHelper.Quit(); gameover = true; break; } } sb.Append("\n"); if (game.Gameover && game.Player.Location == game.Dungeon.ExitRoom) { sb.Append("You run through the door and are greeted with mountains of treasure in front of you").Append("\n"); sb.Append("Next to the seemingly endless piles of gold and silver you spot some old, but beautiful and powerful, weapons and armor.").Append("\n"); sb.Append("As you stuff your pockets with loot you see a small hatch leading outside").Append("\n"); sb.Append( "After you've left, loot in hand, standing in the fresh breeze, you hear that old familiar voice echo from the mountains again:") .Append("\n"); sb.Append($"\"Good job, {_gameConfiguration.playerName}. You have found the treasure of the ancients, may it serve you well\"").Append("\n"); sb.Append($"Score: {game.Player.Kp.ToString()}"); } else { sb.Append($"As you fall to the ground, you feel your life slip away until everything fades to black").Append("\n"); sb.Append($"Your score: {game.Player.Kp.ToString()}"); } Console.WriteLine(sb.ToString()); Console.ReadLine(); }