Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 public void Init()
 {
     playerInput = new ParsedInput("quit", new ArrayList());
     thePlayer = new Player("greg");
     handler = new CommandHandler();
     quit = new QuitCommand();
 }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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());
                }
        }
Exemplo n.º 5
0
 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));
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 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();
 }
Exemplo n.º 10
0
 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)
        {
            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)
        {
            String itemName   = (String)userInput.Arguments[0];
            Item   itemObject = thePlayer.PlayerInventory.GetItemObject(itemName);

            thePlayer.CurrentLocation.GetInventory().AddItem(itemObject);
            if (thePlayer.PlayerInventory.RemoveItem(itemName))
            {
                return(new CommandResponse("Successfully dropped " + itemName));
            }
            else
            {
                return(new CommandResponse("You do not own a " + itemName));
            }
        }
Exemplo n.º 13
0
        public ParsedInput Parse(String rawInput)
        {
            ParsedInput parsedInput = new ParsedInput();
            ArrayList stringTokens = new ArrayList(rawInput.Split());

            foreach (string token in stringTokens)
            {

                if (validCommands.Contains(token))
                {
                    parsedInput.Command = token;
                }
                else if (!dropWords.Contains(token))
                    parsedInput.Arguments.Add(token);
            }
            return parsedInput;
        }
Exemplo n.º 14
0
        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());
        }
Exemplo n.º 15
0
        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());
        }
Exemplo n.º 16
0
        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];
            Exit   desiredExit = thePlayer.CurrentLocation.GetExitCollection().GetExit(exitLabel);

            if (desiredExit == null)
            {
                return(new CommandResponse("There is no exit there.. 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()));
        }
 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.GetExitCollection().ContainsExit(argument))
         {
             Exit theExit = thePlayer.CurrentLocation.GetExitCollection().GetExit(argument);
             return(new CommandResponse(theExit.Description));
         }
     }
     return(response);
 }
Exemplo n.º 18
0
        public override CommandResponse Execute(ParsedInput userInput, Player thePlayer)
        {
            String itemName = (String)userInput.Arguments[0];

            if (itemName == "money" || itemName == "gold")
            {
                int locationMoney = thePlayer.CurrentLocation.GetInventory().GetTotalGold();
                thePlayer.PlayerInventory.AddMoney(locationMoney);
                thePlayer.CurrentLocation.GetInventory().RemoveMoney(locationMoney);
                return(new CommandResponse("Added " + locationMoney + " gold to inventory"));
            }

            Item itemObject = thePlayer.CurrentLocation.GetInventory().GetItemObject(itemName);

            thePlayer.CurrentLocation.GetInventory().RemoveItem(itemName);
            thePlayer.PlayerInventory.AddItem(itemObject);
            return(new CommandResponse("Picked up " + itemName));
        }
        public ParsedInput Parse(String rawInput)
        {
            ParsedInput parsedInput    = new ParsedInput();
            String      lowercaseInput = rawInput.ToLower();
            ArrayList   stringTokens   = new ArrayList(lowercaseInput.Split());

            foreach (string token in stringTokens)
            {
                if (validCommands.Contains(token))
                {
                    parsedInput.Command = token;
                }
                else if (!dropWords.Contains(token))
                {
                    parsedInput.Arguments.Add(token);
                }
            }
            return(parsedInput);
        }
Exemplo n.º 20
0
        public override CommandResponse Execute(ParsedInput userInput,
                                                Player thePlayer)
        {
            String itemName    = (String)userInput.Arguments[0];
            Item   itemObject  = thePlayer.CurrentLocation.GetInventory().GetItemObject(itemName);
            int    playersGold = thePlayer.PlayerInventory.GetTotalGold();
            int    itemPrice   = itemObject.GetValue();

            if (playersGold >= itemPrice)
            {
                thePlayer.CurrentLocation.GetInventory().RemoveItem(itemName);
                thePlayer.PlayerInventory.AddItem(itemObject);
                thePlayer.PlayerInventory.RemoveMoney(itemPrice);
                return(new CommandResponse("Successfully purchased " + itemName));
            }
            else
            {
                return(new CommandResponse("Not Enough gold, you only have " + playersGold + " gold."));
            }
        }
Exemplo n.º 21
0
        public override CommandResponse Execute(ParsedInput userInput, Player thePlayer)
        {
            Random chance = new Random();
            int n = chance.Next(2);
            if (n == 1)
            {
                if (userInput.Arguments.Count > 0)
                   return takeExit((String)userInput.Arguments[0], thePlayer);
                else
                {
                   return RandomExit(thePlayer);
                }

            }
            else
            {
                StringBuilder returnMsg = new StringBuilder();
                returnMsg.Append(" Flee is failed\n");
                returnMsg.Append(AttackPerform(RandomCharacter(), thePlayer));
                return new CommandResponse(returnMsg.ToString());
            }
        }
        public override CommandResponse Execute(ParsedInput userInput,
                                                Player thePlayer)
        {
            String itemName   = (String)userInput.Arguments[0];
            Item   itemObject = thePlayer.PlayerInventory.GetItemObject(itemName);

            thePlayer.CurrentLocation.GetInventory().AddItem(itemObject);
            double itemPriceCalc = itemObject.GetValue() * 0.8;

            int itemPrice = Convert.ToInt32(itemPriceCalc);


            if (thePlayer.PlayerInventory.RemoveItem(itemName))
            {
                thePlayer.PlayerInventory.AddMoney(itemPrice);
                return(new CommandResponse("Successfully sold " + itemName + " for " + itemPrice + " gold" + itemPriceCalc));
            }
            else
            {
                return(new CommandResponse("You do not own a " + itemName));
            }
        }
Exemplo n.º 23
0
        public override CommandResponse Execute(ParsedInput userInput, Player thePlayer)
        {
            if (thePlayer.CurrentLocation is Shop)
            {
                Shop shop = (Shop)thePlayer.CurrentLocation;
                shop.ToString();
                if (userInput.Arguments.Count == 0)
                {
                return new CommandResponse("If you want to buy something need to tell me what");
                }
                String itemLabel = (String)userInput.Arguments[0];

                shop = (Shop)thePlayer.CurrentLocation;
                Item desiredItem = (Item)shop.Items[itemLabel];

                if (desiredItem == null)
                {
                    return new CommandResponse("There is no such item. Try buying something else");
                }

                if (thePlayer.Capacity < desiredItem.Weight)
                {
                    return new CommandResponse("You cannot carry any more. You have "+thePlayer.Capacity+" lb capacity left");
                }
                else if (thePlayer.Gold >= desiredItem.Worth)
                {
                    thePlayer.Inventory.Add(itemLabel, desiredItem);
                    thePlayer.Gold -= desiredItem.Worth;
                    thePlayer.Capacity -= desiredItem.Weight;
                    shop.Items.Remove(itemLabel);
                    thePlayer.CurrentLocation = shop;
                    return new CommandResponse("Your have "+thePlayer.Gold+" gold left \n" +"You can carry "+thePlayer.Capacity+" lb more \nYou successfully bought "
                        + itemLabel + " and find yourself somewhere else\n\n" + thePlayer.CurrentLocation.ToString() + thePlayer.ToString());
                }
                else return new CommandResponse("You have no enough money. You have "+thePlayer.Gold+" gold");
            }

            return new CommandResponse("You're not in a shop. You can't buy");
        }
Exemplo n.º 24
0
        public override CommandResponse Execute(ParsedInput userInput, Player thePlayer)
        {
            Hashtable inventory = new Hashtable();
            Shop shop = new Shop();

            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];
            shop = (Shop)thePlayer.CurrentLocation;
            Item desiredItem = (Item)thePlayer.Inventory[itemLabel];

            if (desiredItem == null)
            {
                return new CommandResponse("There is no such item. Try buying something else!!");
            }

            shop.Items.Add(itemLabel, desiredItem);
            return new CommandResponse("You successfully sold " + itemLabel + " and find yourself somewhere else\n\n" + thePlayer.CurrentLocation.ToString());
        }
 public abstract CommandResponse Execute(ParsedInput userInput,
                                         Player thePlayer);
Exemplo n.º 26
0
 public override CommandResponse Execute(ParsedInput userInput,
                                         Player thePlayer)
 {
     return(new CommandResponse("You entered the equip command"));
 }
Exemplo n.º 27
0
 public override CommandResponse Execute(ParsedInput userInput,
                                         Player thePlayer)
 {
     return(new CommandResponse(thePlayer.ToString()));
 }
Exemplo n.º 28
0
 public abstract CommandResponse Execute(ParsedInput userInput,
     Player thePlayer);
 public override CommandResponse Execute(ParsedInput userInput, Player thePlayer)
 {
     return(new CommandResponse("Thanks for playing -- Goodbye", true));
 }
Exemplo n.º 30
0
 public override CommandResponse Execute(ParsedInput userInput,
     Player thePlayer)
 {
     return new CommandResponse("You entered the sell command");
 }
Exemplo n.º 31
0
 public override CommandResponse Execute(ParsedInput userInput, Player thePlayer)
 {
     return new CommandResponse("Thanks for playing -- Goodbye",true);
 }