// commented since it is simply List.Add
		/*
		public bool addItemForSale(ItemForSale itemForSale)
		{

				itemsForSale.Add(itemForSale);
	
		}
		*/

		// can not check the input item since it is an instance
		// use a newly created enum class ItemForSale
		/*
        public bool buyItemForSale(Hero hero, Item item)
		{
			if (hero != null && item != null && itemsForSale.ContainsKey(item))
			{
				int price = itemsForSale[item];

                if(hero.getGold() >= price)
				{
					itemsForSale.Remove(item);
					hero.setGold(hero.getGold() - price);
					hero.addItem(item);
					return true;
				}
			}

			return false;
		}
		*/
		public bool buyItemForSale(Hero hero, ItemForSale item)
		{
			if (hero != null && itemsForSale.Contains(item))
			{
				int price = 2;
				if (isMine && hero.getHeroKind() == HeroKind.Dwarf && item == ItemForSale.SP) price = 1; // dwarf get a discount
				if (hero.getGold() >= price)
				{
					Item newItem=new Item(ItemWeight.Light);        //ItemWeight.Light as placehoder for initialization
					if (item== ItemForSale.SP)
                    {
						hero.setGold(hero.getGold() - price);
						hero.setStrengthPoints(hero.getStrengthPoints() + 1);
						return true; 
                    }
                    else
                    {
						if (item == ItemForSale.Wineskin) newItem = new Wineskin(ItemWeight.Light);
						if (item == ItemForSale.Falcon) newItem = new Falcon(ItemWeight.Heavy);
						if (item == ItemForSale.Telescope) newItem = new Telescope(ItemWeight.Light);
						if (item == ItemForSale.Helm) newItem = new Helm(ItemWeight.Light);
						if (item == ItemForSale.Shield) newItem = new Shield(ItemWeight.Heavy);
						if (item == ItemForSale.Bow) newItem = new Bow(ItemWeight.Heavy);
					}
					hero.setGold(hero.getGold() - price);
					hero.addItem(newItem);
					return true;
				}
			}
			return false;
		}
コード例 #2
0
 public Trade(Hero hero1, Hero hero2, int goldToHero1, List <Item> itemsToHero1, int goldToHero2, List <Item> itemsToHero2, Falcon falcon)
 {
     this.hero1        = hero1;
     this.hero2        = hero2;
     this.goldToHero1  = goldToHero1;
     this.itemsToHero1 = itemsToHero1;
     this.goldToHero2  = goldToHero2;
     this.itemsToHero2 = itemsToHero2;
     this.falcon       = falcon;
     tradeStatus       = TradeStatus.Hero2;
 }
コード例 #3
0
        //returns success status of action
        public static bool ProposeTrade(Hero sender, Hero recipient, int goldToSend, List <Item> itemsToSend, int goldToReceive, List <Item> itemsToReceive, Falcon falcon)
        {
            if (falcon != null && falcon.getUsedToday())
            {
                //falcon was already used today
                return(false);
            }

            Trade trade = new Trade(sender, recipient, goldToReceive, itemsToReceive, goldToSend, itemsToSend, falcon);

            activeTrades.Add(trade);

            return(true);
        }