Method: Monotony::BasicProperty#initialize

Defined in:
lib/monotony/basicproperty.rb

#initialize(opts) ⇒ BasicProperty

Returns a new instance of BasicProperty.

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :rent (Array<Integer>)

    An array of six elements containing rent values for an property with no houses, one house, two houses, three houses, four houses, and a hotel.

  • :house_cost (Integer)

    The cost of purchasing a house on this property.

  • :hotel_cost (Integer)

    The cost of purchasing a hotel on this property. Traditionally equal to house_cost.

  • :set (Symbol)

    A symbol identifying this property as a member of a set of properties.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/monotony/basicproperty.rb', line 24

def initialize(opts)
	super
	@rent = opts[:rent]
	@house_cost = opts[:house_cost]
	@hotel_cost = opts[:hotel_cost]
	@set = opts[:set]
	@num_houses = 0
	@num_hotels = 0
	@action = Proc.new do |game, owner, player, property|
		if owner
			if set_owned?
				rent_to_pay = (property.num_hotels  == 1 ? property.rent[5] : ( property.num_houses == 0 ? (@rent[0] * 2) :  property.rent[property.num_houses] ) )
			else
				rent_to_pay = property.rent[0]
			end
			if owner != player
				if not owner.is_out? and not is_mortgaged?
					puts '[%s] Due to pay £%d rent to %s for landing on %s with %s' % [ player.name, rent_to_pay, owner.name, property.name, ( property.num_hotels == 1 ? 'a hotel' : '%d houses' % property.num_houses) ]
					player.pay(owner, rent_to_pay)
				end
			end
		else
			player.behaviour[:purchase_possible].call(game, player, self) if player.currency >= cost
		end
	end
end