public void Fight(TextAdventure _TA) { ForegroundColor = ConsoleColor.Cyan; WriteLine("Choose your weapon:"); ForegroundColor = ConsoleColor.White; Write(">"); string inputItem = ReadLine(); if (_TA.Player.CheckInventory(inputItem)) { Item weapon = null; foreach (Item item in _TA.Player.Inventory) { if (item.Name == inputItem) { weapon = item; } } this.Health -= weapon.Damage; _TA.Player.Health -= this.Damage; if (_TA.Player.Health <= 0) { ForegroundColor = ConsoleColor.Red; WriteLine("You died."); _TA.GameOver = true; return; } if (this.Health <= 0) { ForegroundColor = ConsoleColor.Green; WriteLine(this.Name + " died."); WriteLine("Your Health: " + _TA.Player.Health + "hp"); if (this.Loot != null) { _TA.CurrentRoom.Items.Add(this.Loot); WriteLine(this.Name + " dropped a " + this.Loot.Name + "."); } _TA.CurrentRoom.RemoveNPC(this); return; } ForegroundColor = ConsoleColor.Green; WriteLine("Your Health: " + _TA.Player.Health + "hp"); ForegroundColor = ConsoleColor.Red; WriteLine(this.Name + "'s Health: " + this.Health + "hp"); return; } else { ForegroundColor = ConsoleColor.Red; WriteLine("This item is not in your inventory."); return; } }
private static void StartGame(TextAdventure _TA) { _TA.DisplayCommands(); ForegroundColor = ConsoleColor.Magenta; WriteLine(_TA.Player.GameStartText); _TA.CurrentRoom.DisplayRoom(); _TA.PlayGame(); }
private void GoThrough(TextAdventure _TA) { if (this.LeadsTo == "GameEnd") { ForegroundColor = ConsoleColor.Magenta; WriteLine(_TA.Player.GameEndText); _TA.GameOver = true; } foreach (Room r in _TA.Rooms) { if (this.LeadsTo == r.Name) { _TA.CurrentRoom = r; _TA.CurrentRoom.DisplayRoom(); } } }
public void FightNPC(TextAdventure _TA) { ForegroundColor = ConsoleColor.Cyan; WriteLine("Who do you want to fight?"); ForegroundColor = ConsoleColor.White; Write(">"); string inputNPC = ReadLine(); foreach (NPC npc in _TA.CurrentRoom.NPCs) { if (inputNPC == npc.Name) { npc.Fight(_TA); return; } } ForegroundColor = ConsoleColor.Red; WriteLine(inputNPC + " is not here."); }
public void TryToGoThrough(TextAdventure _TA) { if (this.isOpen) { this.GoThrough(_TA); } else { ForegroundColor = ConsoleColor.Magenta; WriteLine(this.LockedText); if (this.OpenedBy != null) { ForegroundColor = ConsoleColor.Cyan; WriteLine("Choose the item you want to open the door with (it will be removed from your inventory):"); ForegroundColor = ConsoleColor.White; Write(">"); string input = ReadLine(); if (input == this.OpenedBy.Name) { if (_TA.Player.CheckInventory(this.OpenedBy.Name)) { _TA.Player.RemoveFromInventory(this.OpenedBy); this.isOpen = true; this.GoThrough(_TA); } else { ForegroundColor = ConsoleColor.Red; WriteLine("This item is not in your inventory."); } } else { ForegroundColor = ConsoleColor.Red; WriteLine("This item doesn't open the door."); } } } }
private static void LoadGame() { TextAdventure TA; ForegroundColor = ConsoleColor.Cyan; WriteLine("Type a number to choose your start settings:"); ForegroundColor = ConsoleColor.White; WriteLine("1. New Game"); WriteLine("2. Load Game"); WriteLine("3. Quit"); Write(">"); string input = ReadLine(); if (input == "1") { List <Room> rooms = new List <Room>(); using (StreamReader r = new StreamReader(@"../Softwaredesign_Abschlussaufgabe/Code/GameBuilder/Rooms.json")) { string json = r.ReadToEnd(); rooms = JsonConvert.DeserializeObject <List <Room> >(json); } Room currentRoom = rooms[0]; Player player; using (StreamReader r = new StreamReader(@"../Softwaredesign_Abschlussaufgabe/Code/GameBuilder/Player.json")) { string json = r.ReadToEnd(); player = JsonConvert.DeserializeObject <Player>(json); } TA = new TextAdventure(rooms, currentRoom, player); StartGame(TA); } else if (input == "2") { ForegroundColor = ConsoleColor.Cyan; WriteLine("Whats the name of your save file? (Don't add the path or file type)"); ForegroundColor = ConsoleColor.White; Write(">"); string inputFile = ReadLine(); try { using (StreamReader r = new StreamReader(@"../Softwaredesign_Abschlussaufgabe/Code/SaveFiles/" + inputFile + ".json")) { string json = r.ReadToEnd(); TA = JsonConvert.DeserializeObject <TextAdventure>(json); } StartGame(TA); } catch (Exception e) { WriteLine(e.Message); ForegroundColor = ConsoleColor.Red; WriteLine("Failed to load save file. Did you type the name correctly?"); LoadGame(); } } else if (input == "3") { return; } else { ForegroundColor = ConsoleColor.Red; WriteLine("Invalid input. Please try again."); LoadGame(); } }