public static void DoAction(string currentCommand, ref Player player, Location currentLocation, ref Dictionary <string, Location> locationdex, Dictionary <string, Pokemon> pokedex, Dictionary <string, Move> movedex) { if (currentCommand == "") { Console.Clear(); } //QUIT if (currentCommand == "quit" || currentCommand == "q") { //save stuff here player.gameRunning = false; } char[] charSeparators = new char[] { ' ' }; string[] splitCommand = currentCommand.ToLower().Split(charSeparators, 2); //LOOK if (splitCommand[0] == "look" || splitCommand[0] == "l") { try { Console.WriteLine(currentLocation.descriptions[splitCommand[1]]); } catch { Console.WriteLine("What are you looking at? There's nothing like that here."); return; } } //TALK if (splitCommand[0] == "talk" || splitCommand[0] == "t") { try { Console.WriteLine(currentLocation.dialogue[splitCommand[1]]); return; } catch { Console.WriteLine("Who are you talking to? There's no one here like that."); return; } } //EXIT/ENTER if (splitCommand[0] == "exit" || splitCommand[0] == "enter" || splitCommand[0] == "e") { try { if (locationdex[currentLocation.exitLocations[splitCommand[1]]].isLocked == true) { Console.WriteLine(locationdex[currentLocation.exitLocations[splitCommand[1]]].lockedText); } else { if (player.currentLocation.canHeal) { player.previousLocation = player.currentLocation; } player.currentLocation = locationdex[currentLocation.exitLocations[splitCommand[1]]]; Console.WriteLine(currentLocation.name.ToUpper()); Console.WriteLine("-------------------------------------------------------\n"); Console.WriteLine(currentLocation.description); } } catch { Console.WriteLine("Where are you exiting? Try using a direction ('north')."); } } //PARTY if (splitCommand[0] == "party" || splitCommand[0] == "p") { foreach (Pokemon pokemon in player.party) { if (pokemon.name != "Missingno") { pokemon.WriteName(); Console.Write($" | Lv. {pokemon.level} | {pokemon.currentHitPoints} / {pokemon.maxHitPoints}"); } } Console.ReadKey(); } //HEAL if (splitCommand[0] == "heal" && currentLocation.canHeal) { Console.WriteLine("The nice lady at the counter fully healed all your Pokémon!"); for (int i = 0; i < 3; i++) { player.party[i].currentHitPoints = player.party[i].maxHitPoints; player.party[i].isParalyzed = false; player.party[i].isBurned = false; player.party[i].isPoisoned = false; player.party[i].sleepCounter = 0; player.party[i].isFainted = false; } Console.ReadKey(); } //PC if (splitCommand[0] == "pc" && currentLocation.hasPc) { bool keepRunning = true; while (keepRunning) { Console.WriteLine("PARTY:"); foreach (Pokemon pokemon in player.party) { if (pokemon.name != "Missingno") { pokemon.WriteName(); Console.Write($" | Lv. {pokemon.level} | {pokemon.currentHitPoints} / {pokemon.maxHitPoints}\n"); } } Console.WriteLine("POKÉMON IN PC:"); for (int i = 0; i < player.pcPokemon.Count; i++) { Console.Write((i + 1) + ". "); player.pcPokemon[i].WriteName(); Console.WriteLine($" Lv. {player.pcPokemon[i].level}"); } Console.WriteLine("\nWhat would you like to do?"); Console.WriteLine("1. Withdraw Pokémon"); Console.WriteLine("2. Exit"); currentCommand = Console.ReadLine(); switch (currentCommand) { case "1": Console.WriteLine("Which Pokémon would you like to withdraw? (Type a number.)"); currentCommand = Console.ReadLine(); try { int pokemonId = int.Parse(currentCommand); Pokemon withdrawnPokemon = player.pcPokemon[pokemonId - 1]; player.pcPokemon.Remove(withdrawnPokemon); Console.WriteLine("Which party member would you like to deposit? (Type a number.)"); currentCommand = Console.ReadLine(); pokemonId = int.Parse(currentCommand); player.party[pokemonId - 1].Heal(); player.pcPokemon.Add(player.party[pokemonId - 1]); player.party[pokemonId - 1] = withdrawnPokemon; Console.Write("All done!"); Console.ReadKey(); Console.Clear(); } catch { Console.WriteLine("Something went wrong, please try again."); Console.ReadKey(); } break; case "2": Console.WriteLine("Ok, booting down."); Console.ReadKey(); keepRunning = false; break; } } } //BATTLE if (splitCommand[0] == "battle" || splitCommand[0] == "b") { if (currentLocation.trainerBattles.Count > 0) { if (!Methods.TrainerBattle(ref player, currentLocation.trainerBattles[0].trainer, movedex["struggle"])) { player.currentLocation = player.previousLocation; Console.WriteLine("You wake up in the last Pokémon center you visited, with all your Pokémon healed. Let's try again!"); foreach (Pokemon pokemon in player.party) { pokemon.Heal(); } } else { currentLocation.trainerBattles.Remove(currentLocation.trainerBattles[0]); Console.WriteLine(currentLocation.name.ToUpper()); Console.WriteLine("-------------------------------------------------------\n"); Console.WriteLine(currentLocation.description); } } } //GRASS if (splitCommand[0] == "grass" || splitCommand[0] == "g") { Random random = new Random(); Pokemon encounteredPokemon = new Pokemon(currentLocation.wildPokemon[0].pokemon, pokedex); int randomNumber = random.Next(0, 100); foreach (PokemonWrapper pokemon in currentLocation.wildPokemon) { if (randomNumber < pokemon.rate) { encounteredPokemon = new Pokemon(pokemon.pokemon, random.Next(pokemon.minLevel, pokemon.maxLevel + 1), pokedex); break; } } if (!Methods.WildBattle(ref player, encounteredPokemon, movedex["Struggle"])) { player.currentLocation = player.previousLocation; Console.WriteLine("You wake up in the last Pokémon center you visited, with all your Pokémon healed. Let's try again!"); foreach (Pokemon pokemon in player.party) { pokemon.Heal(); } } else { Console.WriteLine(currentLocation.name.ToUpper()); Console.WriteLine("-------------------------------------------------------\n"); Console.WriteLine(currentLocation.description); } } if (splitCommand[0] == "help") { Console.WriteLine("Commands you can use at anytime: \nenter [place]\nexit [direction]\ntalk [person]\nlook [object]/nparty"); Console.ReadKey(); } Console.Clear(); Console.WriteLine(player.currentLocation.name.ToUpper()); Console.WriteLine("-------------------------------------------------------\n"); Console.WriteLine(player.currentLocation.description); }
static void Main(string[] args) { bool shouldExit = false; string currentCommandOne; string path = @"C:\PokemonTextAdventure"; if (!File.Exists(path)) { Directory.CreateDirectory(path); } Dictionary <string, Pokemon> pokedex = new Dictionary <string, Pokemon>(); Dictionary <string, Move> movedex = new Dictionary <string, Move>(); Dictionary <int, Trainer> trainerdex = new Dictionary <int, Trainer>(); Dictionary <string, Location> locationdex = new Dictionary <string, Location>(); Player player = new Player(); Methods.Populate(ref movedex, ref pokedex); Methods.Populate(ref trainerdex, pokedex); Console.WriteLine(" ,'\\"); Console.WriteLine(" _.----. ____ ,' _\\ ___ ___ ____"); Console.WriteLine("_,-' `. | | /`. \\,-' | \\ / | | \\ |`."); Console.WriteLine("\\ __ \\ '-. | / `. ___ | \\/ | '-. \\ | |"); Console.WriteLine(" \\. \\ \\ | __ | |/ ,','_ `. | | __ | \\| |"); Console.WriteLine(" \\ \\/ /,' _`.| ,' / / / / | ,' _`.| | |"); Console.WriteLine(" \\ ,-'/ / \\ ,' | \\/ / ,`.| / / \\ | |"); Console.WriteLine(" \\ \\ | \\_/ | `-. \\ `' /| | || \\_/ | |\\ |"); Console.WriteLine(" \\ \\ \\ / `-.`.___,-' | |\\ /| \\ / | | |"); Console.WriteLine(" \\ \\ `.__,'| |`-._ `| |__| \\/ | `.__,'| | | |"); Console.WriteLine(" \\_.-' |__| `-._ | '-.| '-.| | |"); Console.WriteLine(" `' ' -._|"); Console.WriteLine(" R E D / B L U E D E M A K E"); Console.WriteLine(" by Daniel Sampson"); Console.WriteLine("\n (press enter to continue)"); Console.ReadLine(); Console.WriteLine("To start a new save, enter 'n'. To load a previous one, enter 'l'."); currentCommandOne = Console.ReadLine(); if (currentCommandOne == "debug") { player.party[0] = new Pokemon("Scyther", 50, pokedex); player.party[1] = new Pokemon("Missingno", 50, pokedex); player.party[2] = new Pokemon("Missingno", pokedex); Methods.WildBattle(ref player, new Pokemon("Mewtwo", 30, pokedex), movedex["Struggle"]); Console.ReadLine(); } if (currentCommandOne == "l") { bool shouldRun = true; while (shouldRun == true) { Console.WriteLine("Enter the name you used for your save file."); currentCommandOne = Console.ReadLine().ToLower(); path = path + "/" + currentCommandOne + ".txt"; if (File.Exists(path)) { shouldRun = false; string[] substrings = File.ReadAllText(path).Split(new string[] { "&&&" }, StringSplitOptions.None); player = JsonConvert.DeserializeObject <Player>(substrings[0]); locationdex = JsonConvert.DeserializeObject <Dictionary <string, Location> >(substrings[1]); player.gameRunning = true; Console.WriteLine("Game loaded!"); Console.ReadKey(); Console.Clear(); Console.WriteLine(player.currentLocation.name.ToUpper()); Console.WriteLine("-------------------------------------------------------\n"); Console.WriteLine(player.currentLocation.description); } else { Console.WriteLine("That name was not recognized. Check your spelling and try again."); } } } if (currentCommandOne == "n") { Console.WriteLine("OAK: Hello there! Welcome to the world of Pokémon! My name is Professor Oak."); Console.ReadLine(); Console.WriteLine("OAK: This world is inhabited by creatures called Pokémon! For some people, Pokémon are pets. Others use them for fights. \nMyself... I study Pokémon as a profession.\n"); Console.ReadLine(); Console.WriteLine("First, what is your name?"); player.name = Console.ReadLine(); if (player.name == "") { player.name = "Red"; } path = path + "/" + player.name.ToLower() + ".txt"; var fileCreate = File.Create(path); fileCreate.Close(); Console.WriteLine($"\nWelcome, {player.name}!"); Console.WriteLine("I'll give you a Pokémon to start you on your journey."); Console.ReadLine(); Console.Write("Would you like "); Methods.WriteType("Bulbasaur", "grass"); Console.Write(", a grass-type Pokémon, "); Methods.WriteType("Charmander", "fire"); Console.Write(", a fire-type Pokémon, or "); Methods.WriteType("Squirtle", "water"); Console.WriteLine(", a water-type Pokémon?"); string bluesStarter = ""; string bluesStarterType = ""; while (shouldExit == false) { currentCommandOne = Console.ReadLine(); switch (currentCommandOne.ToLower()) { case "squirtle": case "s": player.party[0] = new Pokemon("Squirtle", 5, pokedex); Methods.WriteType("Squirtle", "water"); Console.WriteLine("! A fine choice!"); bluesStarter = "Bulbasaur"; bluesStarterType = "grass"; shouldExit = true; break; case "charmander": case "c": player.party[0] = new Pokemon("Charmander", 5, pokedex); Methods.WriteType("Charmander", "fire"); Console.WriteLine("! A fine choice!"); bluesStarter = "Squirtle"; bluesStarterType = "water"; shouldExit = true; break; case "bulbasaur": case "b": player.party[0] = new Pokemon("Bulbasaur", 5, pokedex); Methods.WriteType("Bulbasaur", "grass"); Console.WriteLine("! A fine choice!"); bluesStarter = "Charmander"; bluesStarterType = "fire"; shouldExit = true; break; default: Console.WriteLine("I'm sorry, I didn't understand that. Could you tell me again?"); break; } } Console.WriteLine("OAK: Oh! Here's Blue, my grandson! He's been your rival since you were a baby."); Console.ReadLine(); Console.WriteLine("BLUE: What about me, Gramps?"); Console.ReadLine(); Console.WriteLine("OAK: Be patient! You can have one!"); Console.ReadLine(); Console.Write("BLUE: I'll choose "); Methods.WriteType(bluesStarter, bluesStarterType); Console.WriteLine(", then!"); trainerdex[1].trainerParty[2] = new Pokemon(bluesStarter, 5, pokedex); player.party[1] = new Pokemon("Missingno", pokedex); player.party[2] = new Pokemon("Missingno", pokedex); if (!Methods.TrainerBattle(ref player, trainerdex[1], movedex["Struggle"])) { Console.WriteLine("BLUE: Yeah! Am I great or what?"); player.party[0].Heal(); Console.ReadKey(); } Console.WriteLine($"I'll make my Pokémon battle to level it up! Smell ya later, {player.name}, Gramps!"); Console.ReadKey(); Console.WriteLine("OAK: That kid... Anyway, good luck on your adventure! Try training on Route 1!"); Console.ReadKey(); Methods.Populate(ref locationdex, trainerdex); player.currentLocation = locationdex["palletTown"]; player.previousLocation = locationdex["palletTown"]; player.gameRunning = true; using (StreamWriter sw = new StreamWriter(path)) { sw.Write(JsonConvert.SerializeObject(player)); sw.Write("&&&"); sw.Write(JsonConvert.SerializeObject(locationdex)); } Console.Clear(); Console.WriteLine(player.currentLocation.name.ToUpper()); Console.WriteLine("-------------------------------------------------------\n"); Console.WriteLine(player.currentLocation.description); } while (player.gameRunning) { string currentCommand = ""; currentCommand = Console.ReadLine(); Methods.DoAction(currentCommand, ref player, player.currentLocation, ref locationdex, pokedex, movedex); } using (StreamWriter sw = new StreamWriter(path)) { Console.WriteLine("Saving..."); sw.Write(JsonConvert.SerializeObject(player)); sw.Write("&&&"); sw.Write(JsonConvert.SerializeObject(locationdex)); Console.WriteLine("Saved. Quitting now."); Console.ReadKey(); } }