/** * Print out the opening message for the player. */ private void PrintWelcome() { Console.WriteLine(); Console.WriteLine("Welcome to Zuul!"); Console.WriteLine("Zuul is a new, incredibly boring adventure game."); Console.WriteLine("Type 'help' if you need help."); Console.WriteLine(); Console.WriteLine(player.CurrentRoom.GetLongDescription()); TextEffects.ColoredMessage("You have " + player.Health + " health!\n", "Red"); }
/** * Print all valid commands to Console.WriteLine. */ public void ShowAll() { for (int i = 0; i < validCommands.Length; i++) { Console.WriteLine("╟─ " + validCommands[i]); string[] thisDescription = commandDescription[i].Split(new string[] { "<br>" }, StringSplitOptions.None); string output = ""; for (int i_ = 0; i_ < thisDescription.Length; i_++) { output += "║ <S>" + thisDescription[i_] + "<S>\n"; } TextEffects.SecondaryColoredMessage(output, "White", "DarkGray"); } }
private void InitiateCombat(Room room) { inCombat = true; player.FightingInRoom = room; Random RNG = new Random(); while (room.Enemies.Count > 0) { Console.WriteLine("An enemy engages you in combat!"); Console.WriteLine(room.Enemies[0].DisplayName + " appeared to fight you!"); while (room.Enemies[0].Health > 0) { Console.WriteLine("What do you do?"); Command command = parser.GetCommand(); ProcessCommand(command); if (command.CommandWord == "attack" || command.CommandWord == "use" || command.CommandWord == "equip" || command.CommandWord == "unequip") { if (room.Enemies[0].Health > 0) { player.Damage(room.Enemies[0].AttackPlayer()); TextEffects.ColoredMessage(room.Enemies[0].attackDesc, "DarkRed"); } } if (!player.IsAlive()) { break; } } Console.WriteLine("You've successfully defeated the " + room.Enemies[0].DisplayName + "!"); switch (RNG.Next(2)) { case 0: room.inventory.AddItem(room.Enemies[0].DropWeapon()); break; case 1: room.inventory.AddItem(room.Enemies[0].DropHealthPotion()); break; case 3: Console.WriteLine(room.Enemies[0].DisplayName + " has not dropped anything!"); break; } room.Enemies.RemoveAt(0); } inCombat = false; player.FightingInRoom = null; }
/** * Try to go to one direction. If there is an exit, enter the new * room, otherwise print an error message. */ private void GoRoom(Command command) { if (!command.HasSecondWord()) { // if there is no second word, we don't know where to go... TextEffects.ColoredMessage("Go where?\n", "DarkRed"); return; } string direction = command.SecondWord; // Try to leave current room. Room nextRoom = player.CurrentRoom.GetExit(direction); if (direction.ToLower() == "back") { nextRoom = player.LastRoom; } if (nextRoom == null) { TextEffects.ColoredMessage("There is no door to " + direction + "!\n", "DarkRed"); } else if (nextRoom.IsLocked()) { TextEffects.ColoredMessage("This door is locked.\n", "DarkRed"); } else { if (nextRoom.Enemies.Count > 0) { InitiateCombat(nextRoom); } player.LastRoom = player.CurrentRoom; player.CurrentRoom = nextRoom; Console.WriteLine(player.CurrentRoom.GetLongDescription()); } }
/** * Given a command, process (that is: execute) the command. * If this command ends the game, true is returned, otherwise false is * returned. */ private bool ProcessCommand(Command command) { bool wantToQuit = false; if (command.IsUnknown()) { TextEffects.ColoredMessage("I don't know what you mean...\n", "DarkRed"); return(false); } string commandWord = command.CommandWord; switch (commandWord) { case "help": PrintHelp(); break; case "go": if (inCombat) { TextEffects.ColoredMessage("You can't do that in combat!\n", "DarkRed"); break; } GoRoom(command); break; case "quit": if (inCombat) { TextEffects.ColoredMessage("You can't do that in combat!\n", "DarkRed"); break; } wantToQuit = true; break; case "look": if (inCombat) { TextEffects.ColoredMessage("You can't do that in combat!\n", "DarkRed"); break; } TextEffects.CheckNullWriteLine(player.CurrentRoom.GetLongDescription()); break; case "inventory": TextEffects.ColoredMessage(player.GetHealth(), "Red"); TextEffects.SecondaryColoredMessage(player.GetInventoryDesc(), "White", "DarkGray"); break; case "take": if (inCombat) { TextEffects.ColoredMessage("You can't do that in combat!\n", "DarkRed"); break; } TextEffects.CheckNullWriteLine(player.PickupItem(command)); break; case "drop": if (inCombat) { TextEffects.ColoredMessage("You can't do that in combat!\n", "DarkRed"); break; } TextEffects.CheckNullWriteLine(player.DropItem(command)); break; case "use": TextEffects.CheckNullWriteLine(player.UseItem(command)); break; case "attack": if (inCombat) { TextEffects.CheckNullWriteLine(player.AttackEnemy()); break; } TextEffects.CheckNullWriteLine(player.Attack()); break; case "equip": TextEffects.CheckNullWriteLine(player.EquipItem(command)); break; case "unequip": TextEffects.CheckNullWriteLine(player.Unequip()); break; } return(wantToQuit); }