Class: Monotony::CommunityChest

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

Overview

A community chest square.

Instance Attribute Summary

Attributes inherited from Square

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

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ CommunityChest

Returns a new instance of CommunityChest.

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :name (String)

    the name of the square. As community chest squares are traditionally all called ‘Community Chest’, in the default layout we are calling these squares ‘Community Chest 1’, ‘Community Chest 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
52
53
54
55
# File 'lib/monotony/communitychest.rb', line 10

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

    case this_cc
    when /It is your birthday/
      game.players.reject { |p| p.name == player.name }.each do |other_player|
        other_player.pay(player, 10)
      end
    when /Old Kent Road/
      player.move('Old Kent Road', :backwards)
    when /Go to jail/
      player.in_jail = true
      player.move('Jail')
      puts '[%s] Got sent to jail!' % player.name
    when /Annuity matures/
      game.pay_player(player, 150)
    when /sale of stock/
      game.pay_player(player, 50)
    when /preference shares/
      game.pay_player(player, 25)
    when /tax refund/
      game.pay_player(player, 20)
    when /insurance premium/
      player.pay(:free_parking, 50, 'insurance')
    when /Doctor/
      player.pay(:free_parking, 50, "doctor's fees")
    when /Bank error/
      game.pay_player(player, 200)
    when /hospital/
      player.pay(:free_parking, 100, 'hospital fees')
    when /beauty contest/
      game.pay_player(player, 10)
    when /inherit/
      game.pay_player(player, 100)
    when 'Advance to GO'
      player.move('GO')
    when /jail free/
      player.jail_free_cards = player.jail_free_cards + 1
    when /take a chance/
      player.pay(:free_parking, 10, 'avoiding a chance')
    end
  end
end