Class: Monotony::Chance

Inherits:
Square
  • Object
show all
Defined in:
lib/monotony/chance.rb

Overview

A chance square.

Instance Attribute Summary

Attributes inherited from Square

#action, #colour, #name, #owner, #set

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Chance

Returns a new instance of Chance.

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :name (String)

    The name of the square. As chance squares are traditionally all called ‘Chance’, in the default layout we are calling these squares ‘Chance 1’, ‘Chance 2’, etc.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
50
51
# File 'lib/monotony/chance.rb', line 10

def initialize(opts)
	@name = opts[:name]
	@action = Proc.new do |game, owner, player, property|
		this_chance = game.chance
		puts '[%s] Drew a chance: %s' % [ player.name, this_chance ]

		case this_chance
		when /Go to jail/
		when 'Go back three spaces'
			moved_to = player.move(-3)
			puts '[%s] Moved back to %s' % [ player.name, moved_to ]
		when 'Take a trip to Marylebone Station'
			player.move('Marylebone Station')
		when 'Advance to Mayfair'
			player.move('Mayfair')
		when 'Advance to Trafalgar Square'
			player.move('Trafalgar Square')
		when 'Advance to GO'
			player.move('GO')
		when 'Advance to Pall Mall'
			player.move('Pall Mall')
		when /Your building loan matures/
			game.pay_player(player, 100)
		when /Speeding fine/
			player.pay(:free_parking, 15, 'speeding fine')
		when /school fees/
			player.pay(:free_parking, 150, 'school fees')
		when /Bank pays you/
			game.pay_player(player, 50)
		when /Drunk in charge/
			player.pay(:free_parking, 50, 'being drunk in charge')
		when /crossword/
			game.pay_player(player, 100)
		when /general repairs/
			player.pay(:free_parking, (25 * player.num_houses) + (100 * player.num_hotels), 'general repairs')
		when /street repairs/
			player.pay(:free_parking, (40 * player.num_houses) + (115 * player.num_hotels), 'street repairs')
		when /jail free/
			player.jail_free_cards = player.jail_free_cards + 1
		end
	end
end