public void MainMenu() { bool finished = false; string choice; bool picked = false; while (!finished) { DisplayRoom(); Console.Write("\nWhat do you want to edit? 'help' for commands, 'done' to save & exit."); choice = Console.ReadLine(); picked = false; if (Utility.NotBlank(choice)) { if (Utility.WordMatch(choice, "north", picked)) { nextroom = game.rooms[currentroom].northexit; if (nextroom == -1) { //Make new room, moving to it in the create/link subroutine if requested? Console.Write("\nThere is not a room to the north. 'new' room or 'link' to a roomID?"); choice = Console.ReadLine(); picked = false; if (Utility.WordMatch(choice, "new", picked)) { CreateRoom("north"); } if (Utility.WordMatch(choice, "link", picked)) { LinkRoom("north"); } } else { //Move to this room. currentroom = nextroom; Console.WriteLine("OK\n"); } picked = true; } if (Utility.WordMatch(choice, "east", picked)) { nextroom = game.rooms[currentroom].eastexit; if (nextroom == -1) { //Make new room, moving to it in the create/link subroutine if requested? Console.Write("\nThere is not a room to the east. 'new' room or 'link' to a roomID?"); choice = Console.ReadLine(); picked = false; if (Utility.WordMatch(choice, "new", picked)) { CreateRoom("east"); } if (Utility.WordMatch(choice, "link", picked)) { LinkRoom("east"); } } else { //Move to this room. currentroom = nextroom; Console.WriteLine("OK\n"); } picked = true; } if (Utility.WordMatch(choice, "west", picked)) { nextroom = game.rooms[currentroom].westexit; if (nextroom == -1) { //Make new room, moving to it in the create/link subroutine if requested? Console.Write("\nThere is not a room to the west. 'new' room or 'link' to a roomID?"); choice = Console.ReadLine(); picked = false; if (Utility.WordMatch(choice, "new", picked)) { CreateRoom("west"); } if (Utility.WordMatch(choice, "link", picked)) { LinkRoom("west"); } } else { //Move to this room. currentroom = nextroom; Console.WriteLine("OK\n"); } picked = true; } if (Utility.WordMatch(choice, "south", picked)) { nextroom = game.rooms[currentroom].southexit; if (nextroom == -1) { //Make new room, moving to it in the create/link subroutine if requested? Console.Write("\nThere is not a room to the south. 'new' room or 'link' to a roomID?"); choice = Console.ReadLine(); picked = false; if (Utility.WordMatch(choice, "new", picked)) { CreateRoom("south"); } if (Utility.WordMatch(choice, "link", picked)) { LinkRoom("south"); } } else { //Move to this room. currentroom = nextroom; Console.WriteLine("OK\n"); } picked = true; } if (Utility.WordMatch(choice, ".", picked) || Utility.WordMatch(choice, ">", picked)) //Next Creature { if (game.creatureindex + 1 >= game.creatures.Count()) { game.ccreature = game.creatures.First(); game.creatureindex = game.creatures.IndexOf(game.ccreature); } else { game.creatureindex += 1; game.ccreature = game.creatures.ElementAt(game.creatureindex); } picked = true; } if (Utility.WordMatch(choice, ",", picked) || Utility.WordMatch(choice, "<", picked)) //Last Creature { if (game.creatureindex - 1 < 0) { game.ccreature = game.creatures.Last(); game.creatureindex = game.creatures.IndexOf(game.ccreature); } else { game.creatureindex -= 1; game.ccreature = game.creatures.ElementAt(game.creatureindex); } picked = true; } if (Utility.WordMatch(choice, "place", picked)) { Console.WriteLine("Placing " + game.ccreature.name + " in room"); game.rooms[currentroom].creatures.Add((Creature)game.ccreature.Clone()); picked = true; } if (Utility.WordMatch(choice, "spawn", picked)) { game.rooms[currentroom].spawnindex.Add(game.ccreature.templateindex); picked = true; } if (Utility.WordMatch(choice, "cspawn", picked)) { game.rooms[currentroom].spawnindex.Clear(); picked = true; } if (Utility.WordMatch(choice, "kill", picked)) { if (Utility.NotBlank(Utility.GetKeyWord(choice))) { temp = Utility.GetKeyWord(choice); } else { Console.WriteLine("Kill what?"); temp = Console.ReadLine(); } found = false; for (int i = 0; i < game.rooms[currentroom].creatures.Count(); i++) { if (Utility.AnyMatch(temp, game.rooms[currentroom].creatures[i].name, picked)) { Console.WriteLine("Killing " + game.rooms[currentroom].creatures[i].name); game.rooms[currentroom].creatures.Remove(game.rooms[currentroom].creatures[i]); break; } else { Console.WriteLine(game.rooms[currentroom].creatures[i].name + " does not match " + temp); } } picked = true; } if (Utility.WordMatch(choice, "cfile", picked)) { if (Utility.NotBlank(Utility.GetKeyWord(choice))) { tempcfile = Utility.GetKeyWord(choice); tempcfile += ".creatures"; } else { Console.Write("\nWhat creature file will you load?"); tempcfile = Console.ReadLine(); tempcfile += ".creatures"; } if (File.Exists(tempcfile)) { try { game.creatures = saver.LoadCreatures(game.creatures, tempcfile); game.ccreature = game.creatures.First(); game.creatureindex = game.creatures.IndexOf(game.ccreature); game.creaturefile = tempcfile; Console.WriteLine("Creature file " + game.creaturefile + " loaded. Currently viewing " + game.ccreature.name + " at index " + game.ccreature.templateindex); } catch { Console.WriteLine(filename + " is not a valid creature file!"); } } else { Console.WriteLine("File does not exist"); } picked = true; } if (Utility.WordMatch(choice, "name", picked)) { if (Utility.NotBlank(Utility.GetKeyWord(choice))) { game.rooms[currentroom].name = Utility.GetKeyWord(choice); } else { Console.Write("\nWhat should the rooms name be?"); game.rooms[currentroom].name = Console.ReadLine(); } picked = true; } if (Utility.WordMatch(choice, "description", picked)) { if (game.rooms[currentroom].description == "New Room Description") { game.rooms[currentroom].description = ""; } Console.Write(game.rooms[currentroom].description); Console.Write("\nType lines for the rooms description? use /d for done and /c to clear."); choice = Console.ReadLine(); while (choice != "/d") { if (choice == "/c") { game.rooms[currentroom].description = ""; } else { if (game.rooms[currentroom].description == "") { game.rooms[currentroom].description += choice; } else { game.rooms[currentroom].description += "\n" + choice; } } Console.Write(game.rooms[currentroom].description); Console.Write("\nType lines for the rooms description? use /d for done and /c to clear."); choice = Console.ReadLine(); } picked = true; } if (Utility.WordMatch(choice, "help", picked)) { Console.WriteLine("Save = save game file"); Console.WriteLine("Name = change room name"); Console.WriteLine("Desc = change room description"); Console.WriteLine("North, East, West, South = More to adjascent room with option to create new"); } if (Utility.WordMatch(choice, "save", picked)) { if (Utility.NotBlank(Utility.GetKeyWord(choice))) { filename = Utility.GetKeyWord(choice) + ".game"; game.filename = Utility.GetKeyWord(choice) + ".game"; } saver.SaveGameData(game, filename); Console.WriteLine("Game File " + filename + " saved!"); } if (Utility.WordMatch(choice, "done", picked)) { Console.Write("\nBe done with you!.\n"); picked = true; finished = true; } if (picked) { } else { Console.WriteLine("That did not register, please try again.\n"); } } } saver.SaveGameData(game, filename); }
public void LaunchEditor() { picked = false; while (!picked) { Console.Write("\nWelcome to the creature editor. NEW file or LOAD file? EXIT to exit."); choice = Console.ReadLine(); if (Utility.NotBlank(choice)) { if (Utility.WordMatch(choice, "new", picked)) { Console.Write("\nWhat file name?"); choice = Console.ReadLine(); if (Utility.NotBlank(choice)) { filename = choice; filename += ".creatures"; if (File.Exists(filename)) { Console.Write("\nFile " + filename + " already exists. Overwrite?"); choice = Console.ReadLine(); if (Utility.WordMatch(choice, "yes", picked)) { creatures.Clear(); creatures.Add(new Garlos.Creature("goblin", "a small goblin fuddles about", 1, 5, 5, 5, 3, 2)); ccreature = creatures.Last(); currentindex = creatures.IndexOf(ccreature); ccreature.templateindex = currentindex; csaver.SaveCreatures(creatures, filename); Console.WriteLine("New file " + filename + " created. Currently editing " + ccreature.name + " at index " + ccreature.templateindex); picked = true; } else { Console.WriteLine("New file not created"); } } else { creatures.Clear(); creatures.Add(new Garlos.Creature("goblin", "a small goblin fuddles about", 1, 5, 5, 5, 3, 2)); ccreature = creatures.Last(); currentindex = creatures.IndexOf(ccreature); ccreature.templateindex = currentindex; csaver.SaveCreatures(creatures, filename); Console.WriteLine("New file " + filename + " created. Currently editing " + ccreature.name + " at index " + ccreature.templateindex); picked = true; } } else { Console.WriteLine("No file selected"); } } if (Utility.WordMatch(choice, "load", picked)) { Console.Write("\nWhat file name?"); choice = Console.ReadLine(); if (Utility.NotBlank(choice)) { filename = choice; filename += ".creatures"; if (File.Exists(filename)) { try { creatures = csaver.LoadCreatures(creatures, filename); ccreature = creatures.First(); currentindex = creatures.IndexOf(ccreature); Console.WriteLine("Creature file " + filename + " loaded. Currently editing " + ccreature.name + " at index " + ccreature.templateindex); picked = true; } catch { Console.WriteLine(filename + " is not a valid creature file!"); } } else { Console.WriteLine("File " + filename + " does not exist"); } } } if (Utility.WordMatch(choice, "exit", picked)) { picked = true; } } } }