/** * Drop an item to the room on the basis of second word */ private void dropItem(Command command) { if (!command.hasSecondWord()) { Console.WriteLine(GeneralDataLibrary.I() + "drop what?"); } else { int num; Item item = null; if (int.TryParse(command.getSecondWord(), out num)) { num--; if (num > -1 && num < player.Inventory.Items.Count) { item = player.Inventory.sendItem(player.CurrentRoom.Inventory, num); } else { Console.WriteLine(GeneralDataLibrary.I() + "index is out of bounds!"); } } else { item = player.Inventory.sendItem(player.CurrentRoom.Inventory, command.getSecondWord()); } if (item != null) { Console.WriteLine(GeneralDataLibrary.I(2) + "Dropped " + item.Name); } } }
/** * Show all items in the players bag, equip slots and tell them how much space they have left */ private void displayBag() { int iC = player.Inventory.Items.Count; string str = ""; if (iC > 1 || iC <= 0) { str = "s"; } Console.WriteLine(GeneralDataLibrary.I() + iC + " Item" + str + " found in bag."); if (iC > 0) { GeneralDataLibrary.ShortLine(GeneralDataLibrary.I()); GeneralDataLibrary.Break(); for (int i = 0; i < iC; i++) { Console.WriteLine(GeneralDataLibrary.I(2) + (i + 1) + ": " + player.Inventory.Items[i].Name); } } GeneralDataLibrary.Break(); Console.WriteLine(GeneralDataLibrary.I() + player.Inventory.SpaceLeft + " space left in bag."); GeneralDataLibrary.Break(); if (player.FirstHand != null) { Console.WriteLine(GeneralDataLibrary.I() + "hand: " + player.FirstHand.Name + " - " + player.FirstHand.Description); } else { Console.WriteLine(GeneralDataLibrary.I() + "hand: " + "<empty>"); } if (player.SecondHand != null) { Console.WriteLine(GeneralDataLibrary.I() + "offhand: " + player.SecondHand.Name + " - " + player.SecondHand.Description); } else { Console.WriteLine(GeneralDataLibrary.I() + "offhand: " + "<empty>"); } if (player.Armor != null) { Console.WriteLine(GeneralDataLibrary.I() + "armor: " + player.Armor.Name + " - " + player.Armor.Description); } else { Console.WriteLine(GeneralDataLibrary.I() + "armor: " + "<empty>"); } if (player.Special != null) { Console.WriteLine(GeneralDataLibrary.I() + "special: " + player.Special.Name + " - " + player.Special.Description); } else { Console.WriteLine(GeneralDataLibrary.I() + "special: " + "<empty>"); } }
/** * Try to go to one direction. If there is an exit, enter the new * room, otherwise print an error message. */ private void ClearConsole(Command command) { if (!command.hasSecondWord()) { Console.Clear(); Console.WriteLine(player.CurrentRoom.getLongDescription()); } else { Console.WriteLine(GeneralDataLibrary.I() + "The clear function does not use a second word!"); } }
/** * Go to another room check for status effect triggers that are triggered by that and let all enemies attack */ private void goRoom(Command command) { if (!command.hasSecondWord()) { // if there is no second word, we don't know where to go... Console.WriteLine(GeneralDataLibrary.I() + "Go where?"); return; } string direction = command.getSecondWord(); // Try to leave current room. Room nextRoom = player.CurrentRoom.getExit(direction); if (nextRoom == null) { Console.WriteLine(GeneralDataLibrary.I() + "You can not go there '" + direction + "' doesn't exist!"); } else { if (nextRoom.IsTutorialLocked) { Console.WriteLine(nextRoom.TutorialDescription); } else if (nextRoom.IsBarred) { Console.WriteLine(nextRoom.BarredDescription); } else if (nextRoom.IsCutable) { Console.WriteLine(nextRoom.CutableDescription); } else if (nextRoom.IsLocked) { Console.WriteLine("You will need a '" + nextRoom.KeyToUnlock + "' key!"); } else { if (player.CurrentRoom.ExitEvents.ContainsKey(direction)) { Console.WriteLine(player.CurrentRoom.ExitEvents[direction]); GeneralDataLibrary.Break(); } player.CurrentRoom = nextRoom; Console.WriteLine(player.CurrentRoom.getLongDescription()); player.CheckTriggers(0); } } }
/** * Used to trigger the attack on the enemy */ private void attackEnemy(Command command) { if (player.CurrentRoom.Enemies != null) { if (command.getSecondWord() != null) { for (int i = player.CurrentRoom.Enemies.Count - 1; i >= 0; i--) { if (player.CurrentRoom.Enemies[i].Name == command.getSecondWord()) { if (player.attack(player, player.CurrentRoom.Enemies[i])) { Console.WriteLine(GeneralDataLibrary.I() + player.CurrentRoom.Enemies[i].Name + " has died!"); if (player.CurrentRoom.Enemies[i].FirstHand != null) { player.CurrentRoom.Inventory.addItem(player.CurrentRoom.Enemies[i].FirstHand); } if (player.CurrentRoom.Enemies[i].SecondHand != null) { player.CurrentRoom.Inventory.addItem(player.CurrentRoom.Enemies[i].SecondHand); } if (player.CurrentRoom.Enemies[i].Armor != null) { player.CurrentRoom.Inventory.addItem(player.CurrentRoom.Enemies[i].Armor); } if (player.CurrentRoom.Enemies[i].Special != null) { player.CurrentRoom.Inventory.addItem(player.CurrentRoom.Enemies[i].Special); } player.CurrentRoom.Enemies.RemoveAt(i); } else { Console.WriteLine(GeneralDataLibrary.I() + player.CurrentRoom.Enemies[i].Name + " has: " + player.CurrentRoom.Enemies[i].Health + " health left!"); } GeneralDataLibrary.Break(); break; } } } } }
/** * Display information for the look command. displays player info, room info and enemies in room */ private void lookAround(Command command) { if (command.hasSecondWord()) { bool showDesc = true; if (player.CurrentRoom.getExit(command.getSecondWord()) != null) { if (player.CurrentRoom.getExit(command.getSecondWord()).IsBarred) { Console.WriteLine(player.CurrentRoom.getExit(command.getSecondWord()).BarredDescription); showDesc = false; } if (player.CurrentRoom.getExit(command.getSecondWord()).IsCutable) { Console.WriteLine(player.CurrentRoom.getExit(command.getSecondWord()).CutableDescription); showDesc = false; } if (player.CurrentRoom.getExit(command.getSecondWord()).IsLocked) { Console.WriteLine(GeneralDataLibrary.I() + "This room is locked!"); Console.WriteLine(player.CurrentRoom.getExit(command.getSecondWord()).KeyToUnlock); showDesc = false; } if (player.CurrentRoom.getExit(command.getSecondWord()).IsTutorialLocked) { Console.WriteLine(player.CurrentRoom.getExit(command.getSecondWord()).TutorialDescription); showDesc = false; } if (showDesc) { GeneralDataLibrary.Break(); Console.WriteLine(GeneralDataLibrary.I() + "There is nothing blocking the entrance to " + command.getSecondWord()); } } else { Console.WriteLine(GeneralDataLibrary.Note() + "Could not find exit!"); } } else { Console.WriteLine(player.CurrentRoom.getLongDescription()); GeneralDataLibrary.Break(); if (player.CurrentRoom.Inventory.Items.Count > 0) { Console.WriteLine(GeneralDataLibrary.I() + player.CurrentRoom.Inventory.Items.Count + " Item(s) in the room!"); GeneralDataLibrary.Break(); for (int i = 0; i < player.CurrentRoom.Inventory.Items.Count; i++) { Console.WriteLine(GeneralDataLibrary.I(2) + (i + 1) + " | " + player.CurrentRoom.Inventory.Items[i].Name + ": " + player.CurrentRoom.Inventory.Items[i].Description); } GeneralDataLibrary.Break(2); } Console.WriteLine(GeneralDataLibrary.I() + "health: " + player.Health.ToString()); Console.WriteLine(GeneralDataLibrary.I() + "room in bag: " + player.Inventory.SpaceLeft); } }
/** * Pick up an item from a room on the basis of second word */ private void takeItem(Command command) { if (!command.hasSecondWord()) { if (player.CurrentRoom.Inventory.Items.Count < player.Inventory.SpaceLeft) { if (player.CurrentRoom.Inventory.Items.Count > 0) { Console.WriteLine(GeneralDataLibrary.I() + "You take all items on the ground and put them in your bag."); GeneralDataLibrary.Break(); for (int i = player.CurrentRoom.Inventory.Items.Count - 1; i >= 0; i--) { Item currentItem = player.CurrentRoom.Inventory.Items[i]; Console.WriteLine(GeneralDataLibrary.I(2) + "Added " + currentItem.Name); player.CurrentRoom.Inventory.sendItem(player.Inventory, currentItem.Name); if (currentItem.HasPickupTutorialEvent) { currentItem.progressTutorial(); } if (player.checkBadItem(currentItem, 0)) { player.Inventory.Items.RemoveAt(i); currentItem = null; } } } else { Console.WriteLine(GeneralDataLibrary.I() + "Despite your hard work you find no item to pick up!"); } } else { Console.WriteLine(GeneralDataLibrary.I() + "Not enough space in inventory to take item(s)!"); } } else { if (player.Inventory.SpaceLeft > 0) { int num; Item item = null; if (int.TryParse(command.getSecondWord(), out num)) { num--; if (num > -1 && num < player.CurrentRoom.Inventory.Items.Count) { item = player.CurrentRoom.Inventory.sendItem(player.Inventory, num); } else { Console.WriteLine(GeneralDataLibrary.I() + "index is out of bounds!"); } } else { item = player.CurrentRoom.Inventory.sendItem(player.Inventory, command.getSecondWord()); } if (item != null) { Console.WriteLine(GeneralDataLibrary.I(2) + "Added " + item.Name); player.checkBadItem(item, 0); if (item.HasPickupTutorialEvent) { item.progressTutorial(); } } } else { Console.WriteLine(GeneralDataLibrary.I() + "Not enough space in inventory to take item!"); } } }
/** * Creates all the rooms used in the game including all the items and enemies inhabiting those rooms */ private void createRooms() { Room destroyedTower, mudCreek1, mudCreek2, mudCreekSide1, mudCreek3, mudCreek4, mudCreekEntrance, mudCreek5; // create the rooms // _________________________________________________ destroyedTower = new Room("in the remains of an old watchtower"); mudCreek1 = new Room("in a hidden cavern under the old watch tower"); mudCreekSide1 = new Room("in a small back area hidden at the side of the cave"); mudCreek2 = new Room("in a deeper part of the muddy cave"); mudCreek3 = new Room("at an crossroad in the cavern. A faint light pierces the cavern ceiling"); mudCreekEntrance = new Room("at the cave entrance. Bright light shines at you trough the opening"); mudCreek4 = new Room("in a colder part of the cave. You start to notice the mud getting deeper"); mudCreek5 = new Room("in smaller part of the cave. the mud is slowing down every step"); // initialise room exits // _________________________________________________ destroyedTower.setExit("down", mudCreek1, "As you jump down into the muddy cave below you realise you won't be able to get up again!"); mudCreek1.setExit("north", mudCreekSide1); mudCreek1.setExit("east", mudCreek2); mudCreekSide1.setExit("south", mudCreek1); mudCreek2.setExit("west", mudCreek1); mudCreek2.setExit("east", mudCreek3); mudCreek3.setExit("west", mudCreek2); mudCreek3.setExit("east", mudCreekEntrance); mudCreek3.setExit("north", mudCreek4); mudCreekEntrance.setExit("west", mudCreek3); mudCreek4.setExit("south", mudCreek3); mudCreek4.setExit("down", mudCreek5); mudCreek5.setExit("up", mudCreek4); // Set locked states // _________________________________________________ mudCreekSide1.setBarred("A pile of rocks block the entrance", "The rock formation shatters to pieces!"); mudCreek2.setTutorialLock("I should probably get a weapon first!"); // Set room items // _________________________________________________ // DestroyedTower destroyedTower.Inventory.addItem(new Rock()); destroyedTower.Inventory.addItem(new Apple()); // Mudcreek1 Weapon sword = new TutorialSword(); sword.setPickupTutorialUnlock(mudCreek2); mudCreek1.Inventory.addItem(sword); //mudcreekside1 mudCreekSide1.Inventory.addItem(new Apple()); mudCreekSide1.Inventory.addItem(new Apple()); mudCreekSide1.Inventory.addItem(new WoodArmor()); //mudcreek3 mudCreek3.Inventory.addItem(new Apple()); //mudcreek4 mudCreek4.Inventory.addItem(new Scroll("scribbled", "Leonerius Theran III (Conquest Legionaire)", "4th howl, 3rd of Bright, 3225", "GreyRock Conquest outpost", GeneralDataLibrary.I() + "Its been a week since we started seeing these strange creatures lurking around the camp.\n" + GeneralDataLibrary.I() + "I've decided to go on an investigation.\n" + GeneralDataLibrary.I() + "I can use this as a log for my findings.\n\n" + GeneralDataLibrary.I() + "I've found a cave entrance behind a hill it seems these creatures are housed there at day time.\n" + GeneralDataLibrary.I() + "I'm gathering some supplies to go check it out.\n\n" + GeneralDataLibrary.I() + "The cave is cold muddy and dark I've not yet found any of these weird beasts around.\n\n" + GeneralDataLibrary.I() + "I saw one enter the cavern, these may be Mantey's.\n" + GeneralDataLibrary.I() + "I read about those creatures somewhere, some form of cursed human's they say.\n\n" + GeneralDataLibrary.I() + "I just found one he cut my heel I have to get back to camp or else I'll bleed out.\n" + GeneralDataLibrary.I() + "If you read this send help immediately!")); //Set Enemies // _________________________________________________ //Mudcreek2 mudCreek2.addEnemy(new Enemy("Wounded-Mantey", "A crawling creep", 23, 4, "Raargh!")); //Mudcreek5 Enemy e = new Enemy("Mantey", "An angry human like monster", 39, 4, "Hearrgh!"); e.FirstHand = new HeelBlade(); e.Armor = new WoodArmor(); mudCreek5.addEnemy(e); // set starting room // _________________________________________________ player.CurrentRoom = destroyedTower; // start game outside }
/** * 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()) { Console.WriteLine(GeneralDataLibrary.I() + "I don't know what you mean..."); Console.WriteLine(GeneralDataLibrary.I() + "Type: 'help' if you need help."); return(false); } string commandWord = command.getCommandWord(); GeneralDataLibrary.Break(); switch (commandWord) { case "help": printHelp(command); break; case "go": triggerCharacterAI(); GeneralDataLibrary.Break(); GeneralDataLibrary.LongLine(); GeneralDataLibrary.Break(); goRoom(command); break; case "quit": wantToQuit = true; break; case "look": lookAround(command); break; case "clear": ClearConsole(command); break; case "take": triggerCharacterAI(); GeneralDataLibrary.Break(); GeneralDataLibrary.LongLine(); GeneralDataLibrary.Break(); takeItem(command); break; case "drop": triggerCharacterAI(); GeneralDataLibrary.Break(); GeneralDataLibrary.LongLine(); GeneralDataLibrary.Break(); dropItem(command); break; case "bag": displayBag(); break; case "use": triggerCharacterAI(); GeneralDataLibrary.Break(); GeneralDataLibrary.LongLine(); GeneralDataLibrary.Break(); useItem(command); break; case "equip": triggerCharacterAI(); GeneralDataLibrary.Break(); GeneralDataLibrary.LongLine(); GeneralDataLibrary.Break(); equipItem(command); break; case "unequip": triggerCharacterAI(); GeneralDataLibrary.Break(); GeneralDataLibrary.LongLine(); GeneralDataLibrary.Break(); unequipItem(command); break; case "attack": triggerCharacterAI(); GeneralDataLibrary.Break(); GeneralDataLibrary.LongLine(); GeneralDataLibrary.Break(); attackEnemy(command); break; } GeneralDataLibrary.Break(); GeneralDataLibrary.LongLine(); GeneralDataLibrary.Break(); return(wantToQuit); }