public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { if (userInput.Arguments.Count == 0) { return new CommandResponse("Specify a name to attack"); } StringBuilder returnMsg = new StringBuilder(); NonPlayerCharacter npc = CheckNPC((string)userInput.Arguments[0], thePlayer); if (npc == null) return new CommandResponse("There is no such NPC"); if (!npc.Hostile) return new CommandResponse(npc.Name+" is not hostile"); else { returnMsg.Append(AttackPerform(thePlayer, npc)); thePlayer.CurrentLocation.CharacterList = RemoveCharacter(thePlayer.CurrentLocation); } returnMsg.Append(NPCattackNPC(thePlayer)); if (thePlayer.CurrentLocation.CharacterList.ContainsValue(npc)) { returnMsg.Append(AttackPerform(npc, thePlayer)); if (thePlayer.LifePoints < 0) return new CommandResponse(returnMsg.ToString()+"\n\nYou're dead", true); } return new CommandResponse(returnMsg.ToString()); }
private CommandResponse UseItem(String label, Player player) { Item item = null; foreach (String key in player.CurrentLocation.Items.ItemList.Keys) if (key == label) item = player.CurrentLocation.Items.ItemList[key]; if (item is Weapon) { if (player.Weapon != null) player.Inventory.ItemList.Add(player.Weapon.GetLabel(), player.Weapon); player.Weapon = (Weapon)item; return new CommandResponse("You now hold: " + player.Weapon.ToString()); } if (item is Shield) { if (player.Shield != null) player.Inventory.ItemList.Add(player.Shield.GetLabel(), player.Shield); player.Shield = (Shield)item; return new CommandResponse("You now hold: " + player.Weapon.ToString()); } if (item is Armor) { if (player.Armor != null) player.Inventory.ItemList.Add(player.Armor.GetLabel(), player.Armor); player.Shield = (Shield)item; return new CommandResponse("You now wear: " + player.Armor.ToString()); } return new CommandResponse("No effect"); }
public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { response = new CommandResponse("Can't find that to look at here!"); if (userInput.Arguments.Count == 0) { response.Message = thePlayer.CurrentLocation.ToString(); return response; } foreach (string argument in userInput.Arguments) { if (thePlayer.CurrentLocation.ExitCollection.ContainsExit(argument)) { Exit theExit = thePlayer.CurrentLocation.ExitCollection.GetExit(argument); return new CommandResponse(theExit.Description); } if (argument == "me" | argument == "myself") { return new CommandResponse(thePlayer.ToString()); } if (thePlayer.CurrentLocation.CharacterList.ContainsKey(argument)) { return new CommandResponse (thePlayer.CurrentLocation.CharacterList[argument].ToString()); } } return response; }
public void Init() { playerInput = new ParsedInput("quit", new ArrayList()); thePlayer = new Player("greg"); handler = new CommandHandler(); quit = new QuitCommand(); }
private String FailedFlee(Player player) { StringBuilder returnMsg = new StringBuilder(); returnMsg.Append(AttackPerform(player.CurrentLocation.CharacterList.GetRandomHostileNPC(), player)); returnMsg.Append(NPCattackNPC(player)); return returnMsg.ToString(); }
public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { if (userInput.Arguments.Count == 0) { return new CommandResponse("If you want to take something need to tell me what"); } String itemLabel = (String)userInput.Arguments[0]; Item desiredItem = (Item)thePlayer.CurrentLocation.Items.GetItem(itemLabel); if (desiredItem == null) { return new CommandResponse("There is no such item. Try something else"); } if (thePlayer.Capacity < desiredItem.Weight) { return new CommandResponse("You cannot carry any more. You have " + thePlayer.Capacity + " lb capacity left"); } else { thePlayer.Inventory.AddItem(desiredItem); thePlayer.Capacity -= desiredItem.Weight; thePlayer.CurrentLocation.Items.RemoveItem(desiredItem.GetLabel()); thePlayer.CurrentLocation.Items.ItemList.Remove(desiredItem.GetLabel()); return new CommandResponse("Your have " + thePlayer.Inventory.GetGold().Total + " gold \n" + "You can carry " + thePlayer.Capacity + " lb more \nYou took " + itemLabel + " and find yourself somewhere else\n\n" + thePlayer.CurrentLocation.ToString()); } }
private double GetItemWeight(String itemLabel, Player player) { if (itemLabel == "gold") { return player.CurrentLocation.Items.GetGold().GetWeight(); } return player.CurrentLocation.Items.GetItem(itemLabel).Weight; }
public override CommandState Update(Player thePlayer) { if (thePlayer.CurrentLocation.CheckHostileNPC()) return new AttackState(); if (thePlayer.CurrentLocation is Shop) return this; return new MovementState(); }
private CommandResponse DropItem(string itemLabel, Inventory locationItems, Player player) { if (itemLabel != "gold" && player.Inventory.ItemList.ContainsKey(itemLabel) == false) return new CommandResponse("There is no such item"); else { return AddItemToLocation(itemLabel, locationItems, player); } }
public void SetupPlayer() { String playerName = gameClient.GetReply("What name do you choose to be known by?"); thePlayer = new Player(playerName); thePlayer.CurrentLocation = gameData.GetStartingLocation(); gameClient.PlayerMessage("Welcome " + playerName + "\n\n"); gameClient.PlayerMessage("You find yourself looking at "); gameClient.PlayerMessage(thePlayer.CurrentLocation.Description); }
public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { if (userInput.Arguments.Count == 0) { return new CommandResponse("If you want to use something, tell me what"); } return new CommandResponse( HideItem((String)userInput.Arguments[0],thePlayer)); }
private void HoldItem(Item item, Player player) { if (item is Armor) player.Armor = (Armor)item; if (item is Shield) player.Shield =(Shield)item; if (item is Weapon) player.Weapon = (Weapon)item; }
public CommandResponse ProcessTurn(String userInput, Player thePlayer) { availableCommands = availableCommands.Update(thePlayer); ParsedInput validInput = parse(userInput); Command theCommand = availableCommands.GetCommand(validInput.Command); if (theCommand == null) return new CommandResponse("Not a valid command"); return theCommand.Execute(validInput, thePlayer); }
public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { thePlayer.CurrentLocation.ToString(); if (userInput.Arguments.Count == 0) { return new CommandResponse("If you want to drop something need to tell me what"); } String itemLabel = (String)userInput.Arguments[0]; return DropItem(itemLabel, thePlayer.CurrentLocation.Items, thePlayer); }
public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { thePlayer.CurrentLocation.ToString(); if (userInput.Arguments.Count == 0) { return new CommandResponse("If you want to sell something need to tell me what"); } String itemLabel = (String)userInput.Arguments[0]; Item desiredItem = (Item)thePlayer.Inventory.GetItem(itemLabel); return SellItem(itemLabel, thePlayer.CurrentLocation.Items, thePlayer); }
public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { StringBuilder returnMsg = new StringBuilder(); Random chance = new Random(); int n = chance.Next(2); if (n == 0) { return new CommandResponse("Flee is failed\n" + FailedFlee(thePlayer)); } return RandomExit(thePlayer); }
private CommandResponse TakeItem(string itemLabel, Inventory locationItems, Player player) { if (itemLabel!="gold" && locationItems.ItemList.ContainsKey(itemLabel)==false) return new CommandResponse("There is no such item"); if (player.Inventory.GetWeightLimit() - player.Inventory.GetWeight() < GetItemWeight(itemLabel, player)) return new CommandResponse("The item's too heavy"); else { return AddItemToInventory(itemLabel, locationItems, player); } }
public void Init() { playerInput = new ParsedInput("move", new ArrayList()); thePlayer = new Player("greg"); t127 = new Location("a lecture theatre", "T127"); gregsoffice = new Location("a spinning vortex of terror", "Greg's Office"); t127.ExitCollection.AddExit("south", new Exit("you see a mound of paper to the south", gregsoffice)); gregsoffice.ExitCollection.AddExit("north", new Exit("you see a bleak place to the north", t127)); thePlayer.CurrentLocation = t127; handler = new CommandHandler(); move = new MoveCommand(); }
public void Init() { playerInput = new ParsedInput("look", new ArrayList()); thePlayer = new Player("greg"); t127 = new Location("a lecture theatre", "T127"); Location gregsoffice = new Location("a spinning vortex of terror", "Greg's Office"); southExit = new Exit("you see a mound of paper to the south", gregsoffice); t127.ExitCollection.AddExit("south", southExit ); thePlayer.CurrentLocation = t127; handler = new CommandHandler(); look = new LookCommand(); }
public CommandResponse ProcessTurn(String userInput, Player thePlayer) { ParsedInput validInput = theParser.Parse(userInput); try { Command theCommand = (Command) availableCommands[validInput.Command]; return theCommand.Execute(validInput, thePlayer); } catch (NullReferenceException) { return new CommandResponse("Not a valid command"); } }
public CommandResponse takeExit(String input, Player player) { Exit desiredExit = player.CurrentLocation.ExitCollection.GetExit(input); if (desiredExit == null) { return new CommandResponse("There is no exit there.. Trying moving someplace moveable!!"); } else if (desiredExit.Destination.Locked == true) return new CommandResponse("The exit is locked.. Trying moving someplace moveable!!"); player.CurrentLocation = desiredExit.Destination; return new CommandResponse("You successfully move " + input + " and find yourself somewhere else\n\n" + player.CurrentLocation.ToString()); }
private CommandResponse SellItem(string itemLabel, Inventory locationItems, Player player) { if (!(player.Inventory.ItemList.ContainsKey(itemLabel))) return new CommandResponse("There is no such item"); else { Item item = player.Inventory.GetItem(itemLabel); player.Inventory.RemoveItem(item); locationItems.AddItem(item); player.Inventory.GetGold().Total += item.Value; return new CommandResponse("You've sold the item: " + itemLabel); } }
private CommandResponse AddItemToLocation(String itemLabel, Inventory locationItems, Player player) { if (itemLabel == "gold") { int amount = player.Inventory.GetGold().Total; player.CurrentLocation.Items.AddMoney(amount); player.Inventory.RemoveMoney(amount); return new CommandResponse("You dropped " + amount + " gold"); } Item item = locationItems.GetItem(itemLabel); player.Inventory.AddItem(item); locationItems.RemoveItem(item); return new CommandResponse("You dropped the item: " + itemLabel); }
private CommandResponse UseItem(String label, Player player) { Item item = null; foreach (String key in player.Inventory.ItemList.Keys) if (key == label) item = player.Inventory.ItemList[key]; if (item == null) { return new CommandResponse("There is no such an item"); } return ItemEffect(item, player); }
protected string NPCattackNPC(Player player) { StringBuilder returnMsg = new StringBuilder(); player.CurrentLocation.CharacterList = RemoveCharacter(player.CurrentLocation); foreach (NonPlayerCharacter npc in player.CurrentLocation.CharacterList.Values) { NonPlayerCharacter hostile = null; if (npc.Hostile == false) hostile = player.CurrentLocation.CharacterList.GetRandomHostileNPC(); if (hostile!=null) returnMsg.Append(AttackPerform(npc, player.CurrentLocation.CharacterList.GetRandomHostileNPC())); } return returnMsg.ToString(); }
public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { if (userInput.Arguments.Count == 0) { return new CommandResponse("If you want to unlock tell me what"); } String exitLabel = (String)userInput.Arguments[0]; Exit desiredExit = thePlayer.CurrentLocation.GetExit(exitLabel); Key desiredKey = null; foreach (String key in thePlayer.Inventory.Keys) { Key temp; if (thePlayer.Inventory[key] is Key) { temp = (Key)thePlayer.Inventory[key]; if (temp.Location == desiredExit.Destination) desiredKey = temp; } } try { if (desiredKey.Location == desiredExit.Destination) { thePlayer.CurrentLocation = desiredExit.Destination; return new CommandResponse("The exit is unlocked\nYou successfully move " + exitLabel + " and find yourself somewhere else\n\n" + thePlayer.CurrentLocation.ToString()); } else if (desiredExit == null) { return new CommandResponse("There is no exit there.. Trying moving someplace moveable!!"); } else { return new CommandResponse("You have no right key. Try finding one"); } } catch (NullReferenceException) { return new CommandResponse("You have no right key. Try finding one"); } //return new CommandResponse("You successfully move " + exitLabel + " and find yourself somewhere else\n\n" + thePlayer.CurrentLocation.ToString()); }
public static String displayItems(Player player, Shop shop) { StringBuilder returnMsg = new StringBuilder(); foreach (String key in shop.Items) { returnMsg.Append(key + " " + shop.Items[key].ToString()); } returnMsg.Append("\n\nItems in inventory:\n\n"); foreach (String key in player.Inventory) { returnMsg.Append(key + " " + player.Inventory[key].ToString()); } return returnMsg.ToString(); }
public override CommandResponse Execute(ParsedInput userInput, Player thePlayer) { if (userInput.Arguments.Count == 0) { return new CommandResponse("If you want to move you need to tell me where"); } String exitLabel = ((String) userInput.Arguments[0]).ToLower(); Exit desiredExit = thePlayer.CurrentLocation.ExitCollection.GetExit(exitLabel); if (desiredExit == null) { return new CommandResponse("There is no exit there.. Trying moving someplace moveable!!"); }else if (desiredExit.Destination.Locked == true) return new CommandResponse("The exit is locked.. Trying moving someplace moveable!!"); thePlayer.CurrentLocation = desiredExit.Destination; return new CommandResponse("You successfully move " + exitLabel + " and find yourself somewhere else\n\n" + thePlayer.CurrentLocation.ToString()); }
private CommandResponse BuyItem(string itemLabel, Inventory locationItems, Player player) { if (! (locationItems.ItemList.ContainsKey(itemLabel))) return new CommandResponse("There is no such item"); else if (player.Inventory.GetWeightLimit() - player.Inventory.GetWeight() < locationItems.GetItem(itemLabel).Weight) return new CommandResponse("The item's too heavy"); else if (player.Inventory.GetGold().Total < locationItems.GetItem(itemLabel).Value) return new CommandResponse("You have no enough gold"); else { Item item = locationItems.GetItem(itemLabel); player.Inventory.AddItem(item); locationItems.RemoveItem(item); player.Inventory.GetGold().Total -= item.Value; return new CommandResponse("You've bought the item: " + itemLabel); } }
public CommandResponse RandomExit( Player player) { List<string> keys = new List<string>(); foreach (String key in player.CurrentLocation.ExitCollection.Exits.Keys) keys.Add(key); Random rand = new Random(); int rndNum = rand.Next(keys.Count); string randomKey = keys[rndNum]; if (player.CurrentLocation.ExitCollection.GetExit(randomKey).Destination.Locked == true) { StringBuilder returnMsg = new StringBuilder(); returnMsg.Append("Flee is unsuccessful. The exit to "+randomKey+" is locked "+rndNum+"\n"); returnMsg.Append(FailedFlee(player)); return new CommandResponse(returnMsg.ToString()); } player.CurrentLocation = player.CurrentLocation.ExitCollection.GetExit(randomKey).Destination; return new CommandResponse(" You successfully flee to " + randomKey + " and find yourself somewhere else\n\n" + player.CurrentLocation.ToString()); }