private static void ProcessEquipCommand(string[] parts) //write to equip from backpack { string itemName = parts[1]; Item item; if (CurrentArea.HasItem(parts[1])) { item = CurrentArea.GetItem(parts[1]); // turn into backpack if (item is IEquippableItem) { try { ((IEquippableItem)item).Equip(); } catch (WorldException) { return; } } else { throw new WorldException("You can't equip that!"); } } else { throw new WorldException("That's not in your backpack!"); } }
/// <summary> /// Enter Combat mode. /// </summary> /// <param name="parts">Command as typed by the user split into individual words.</param> private static void ProcessFightCommand(string[] parts) { Creature creature; try { creature = CurrentArea.GetCreature(parts[1]); } catch (WorldException e) { if (CurrentArea.HasItem(parts[1])) { PrintLineWarning("You can't fight with that..."); } else { PrintLineDanger(e.Message); } return; } // This method is part of the MainClass but is defined in a different file. // Check out the Combat.cs file. CombatResult result = DoCombat(creature); switch (result) { case CombatResult.Win: PrintLinePositive("You win!"); Player.Stats.Exp += creature.Stats.Exp; CurrentArea.RemoveCreature(parts[1]); // TODO: Part of a larger achievement // After you gain Exp, how do you improve your stats? // there should be some rules to how this works. // But, you are the god of this universe. You make the rules. // TODO: Part of a larger achievement // After defeating an Enemy, they should drop their Inventory // into the CurrentArea so that the player can then PickUp those Items. break; case CombatResult.Lose: PrintLineDanger("You lose!"); // TODO: Easy Achievement: // What happens when you die? Deep questions. break; case CombatResult.RunAway: // TODO: Moderate Achievement // Handle running away. What happens if you run from a battle? break; default: break; } }
private static void ProcessUseCommand(string[] parts) { if (parts.Length == 1) { PrintLineWarning("Please specify which item."); return; } if (parts.Length == 2) { CurrentArea.GetItem(parts[1]); IUseableItem itemToUse = CurrentArea.GetItem(parts[1]) as IUseableItem; if (itemToUse != null) { try { ((IUseableItem)itemToUse).Use(); PrintLinePositive("Neat thing!"); } catch (ItemDepletedException ide) { PrintLineSpecial(ide.Message); } catch (WorldException we) { PrintLineDanger(we.Message); } } else { PrintLineWarning("This item cannot be used..."); return; } } string targetName = parts[3]; object target; if (CurrentArea.HasItem(targetName)) { target = CurrentArea.GetItem(targetName); } else if (CurrentArea.CreatureExists(targetName)) { target = CurrentArea.GetCreature(targetName); } else { PrintLineWarning("I don't see any of that around here..."); return; } }
/// <summary> /// Parses the command and do any required actions. /// </summary> /// <param name="command">Command as typed by the user.</param> private static void ParseCommand(string command) { // Break apart the command into individual words: // This is why command words and unique names for objects cannot contain spaces. string[] parts = command.Split(' '); // The first word is the command. string cmdWord = parts.First(); if (!_commands.ContainsKey(cmdWord)) { if (parts.Length > 1) { string target = parts[1]; if (CurrentArea.HasItem(target)) { Item item = CurrentArea.GetItem(target); if (item is IInteractable && ((IInteractable)item).Interactions.ContainsKey(cmdWord)) { ((IInteractable)item).Interactions[cmdWord](parts); return; } } else if (CurrentArea.CreatureExists(target)) { Creature creature = CurrentArea.GetCreature(target); if (creature is IInteractable && ((IInteractable)creature).Interactions.ContainsKey(cmdWord)) { ((IInteractable)creature).Interactions[cmdWord](parts); return; } } } PrintLineWarning("I don't understand...(type \"help\" to see a list of commands I know.)"); return; } // execute the command associated with the given command word! _commands[cmdWord](parts); // TODO: Many Achievements // Implement more commands like "use" and "get" and "talk" }
//VM: Ultimately, this talk command allows you to talk to creatures with the ITalkingCreature interface implemented //And funny stuff happens when you try to talk to unvalid things, like talking to no one and talking to boulders private static void ProcessTalkCommand(string[] parts) { // This is where the talk command runs not quite so successfully //this is the scenario where you kinda just talk to yourself (since there's no target creature you're talking with) if (parts.Length == 1) { PrintLinePositive("You BELLOW at the top of your lungs."); PrintLinePositive("Since no one knows who you're talking to, no one responds..."); } //this is when the player types more than 2 words, and we're just letting them know that they shouldn't do that //there are two scenarios: the player typed in multiple REAL creatures, or AT LEAST ONE creature that ISN'T REAL //this block of code below tests which of the two cases (listed in line directly above) is true :) else if (parts.Length > 2) { bool validCreatures = true; int i = 1; while (validCreatures == true && i <= parts.Length - 1) { validCreatures = CurrentArea.CreatureExists(parts[i]); i++; } if (validCreatures == true) { PrintLinePositive("You try to talk to multiple creatures, which are all real, thankfully. But it's hard to keep up a conversation with even one, so you decide it's best to try to talk to just one creature at a time!"); } else { PrintLinePositive("You try to talk to multiple creatures. Some weren't real. Even hearing you address just 1 imaginary creature scared off all the other, real creatures..."); } } //This block below allows us to have a continual conversation with the intern (there's always a "goodbye" option though) //this continual conversation aspect makes it easier for the player to talk //the player doesn't need to keep typing intern after talk and before the conversation word //also helps simulate a "real/normal" conversation with normal people haha ;p else if (parts.Length == 2 && Intern.convoIntern == true) { Creature creature = CurrentArea.GetCreature("intern"); ((ITalkingCreature)creature).Talk(parts[1]); } //this is when the player's typed in two words, "talk" and parts[1], and we're going to check whether parts[1] is a valid creature that we can talk to. else if (parts.Length == 2) { try { if (CurrentArea.CreatureExists(parts[1])) { Creature creature = CurrentArea.GetCreature(parts[1]); if (creature is ITalkingCreature) { //SUCCESS! //This is the scenario where the player has succesfully typed in a creature that they can actually talk to //(checked to see whether the creature has the ITalkingCreature interface fully implemented) //now we can call this specific creature's Talk method so we can engage in unique dialogue with them ((ITalkingCreature)creature).Talk(); } else { //we know that either the creature has the ITalkingCreature interface, or it doesn't //this case below is the scenario that the player wants to talk to a NON-TALKING creature... PrintLinePositive("...the {0} can't speak human...", parts[1]); } } //this is when the player tries to talk to an item... else if (CurrentArea.HasItem(parts[1])) { PrintLinePositive("You try to talk to the {0}... It doesn't respond, obviously. And then you realize that you're just growing slightly less sane by the second...", parts[1]); } else { PrintLinePositive("You try to talk to the '{0},' a creature that doesn't exist. Hmmm...is any of this actually real?", parts[1]); } } catch (WorldException e) { PrintLineDanger(e.Message); return; } } }
/// <summary> /// Enter Combat mode. /// </summary> /// <param name="parts">Command as typed by the user split into individual words.</param> public static void ProcessFightCommand(string[] parts) { Creature creature; try { creature = CurrentArea.GetCreature(parts[1]); } catch (WorldException e) { if (CurrentArea.HasItem(parts[1])) { PrintLineWarning("You can't fight with that..."); } else { PrintLineDanger(e.Message); } return; } // This method is part of the MainClass but is defined in a different file. // Check out the Combat.cs file. CombatResult result = DoCombat(ref creature); switch (result) { case CombatResult.Win: PrintLinePositive("You win!"); Player.Stats.Exp += creature.Stats.Exp; CurrentArea.RemoveCreature(parts[1]); // TODO: Part of a larger achievement // After you gain Exp, how do you improve your stats? // there should be some rules to how this works. // But, you are the god of this universe. You make the rules. // TODO: Part of a larger achievement // After defeating an Enemy, they should drop their Inventory // into the CurrentArea so that the player can then PickUp those Items. break; case CombatResult.Lose: // TODO: VM Easy Achievement: // What happens when you die? Deep questions. //below is basically just an overly-dramatic narrative about your DEMISE. Enjoy! PrintLineDanger("As the {0} deals the fatal blow, you see your life flash before your eyes.", parts[1]); //Thread.Sleep(#OfMilliSeconds) allows us to pause the program for a specified amount of time Thread.Sleep(4000); PrintLineDanger("You see the best parts of your childhood..."); Thread.Sleep(3000); PrintLineDanger("Your friends. The ice-cream truck. Your school's robotics club. The 2-ply toilet paper."); Thread.Sleep(4000); PrintLineDanger("But you also see your arch-nemesis, BIG 'RONA, cackling away at your demise."); Thread.Sleep(4000); PrintLineDanger("And you slowly feel yourself fading away into the light..."); Thread.Sleep(5000); PrintLineWarning("THE END"); Thread.Sleep(5000); //this line below allows us to force the player to quit our game and start a new one (basically emphasises the whole-death-part of this all...) System.Environment.Exit(1); break; case CombatResult.RunAway: // TODO: VM Moderate Achievement // Handle running away. What happens if you run from a battle? PrintLineWarning("You feel your heart jump into your throat. You are scared that you're going to die here. That you're going to die to the {0}", parts[1]); Thread.Sleep(2000); PrintLineWarning("So you run away as fast and as far as you can."); Thread.Sleep(2000); PrintLineWarning("You scream: AAAAAaaaaaAAAAAaaaAAAAAAaaAAAAAAAaaAAAAAaaaAAAAAAAHHHHHHhhhhhHHHHhhHhhhhhhHHHHHHHHHHHH!!!!!"); Thread.Sleep(4000); PrintLineWarning("...It's not a dignified retreat..."); Thread.Sleep(3000); PrintLineDanger("And as you flee, the {0} takes one, last, nearly-deadly, swipe at you.", parts[1]); Thread.Sleep(2000); PrintLineDanger("You are down to 1 HP."); break; default: break; } }