コード例 #1
0
ファイル: DropCommand.cs プロジェクト: Kais120/7201a2
 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);
 }
コード例 #2
0
ファイル: BuyCommand.cs プロジェクト: Kais120/7201a2
 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);
         }
 }