Class: Bridge::Player
Overview
Instance Attribute Summary
Attributes inherited from RedisModel
#id
Instance Method Summary
collapse
Methods inherited from RedisModel
#<=>, all, #destroy!, exists?, expire_in, #expires_in, load, #namespaced_id, namespaced_id, #persist, #persist!, #reload, #to_array, #to_hash, use_timestamps, #use_timestamps?
Constructor Details
#initialize(game) ⇒ Player
Returns a new instance of Player.
5
6
7
|
# File 'lib/bridge/player.rb', line 5
def initialize(game)
@game = game end
|
Instance Method Details
#get_hand ⇒ Object
Also known as:
hand
9
10
11
12
|
# File 'lib/bridge/player.rb', line 9
def get_hand
position = game.players[self]
return game.get_hand(position)
end
|
#make_call(call) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/bridge/player.rb', line 15
def make_call(call)
begin
return game.make_call(call, player = self)
rescue Exception => e
if Bridge::DEBUG
puts e.backtrace.first(8).join("\n").red
puts "\n"
end
raise GameError, e.message
end
end
|
#play_card(card) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/bridge/player.rb', line 27
def play_card(card)
begin
return self.game.play_card(card, self)
rescue Exception => e
if Bridge::DEBUG
puts e.backtrace.first(8).join("\n").red
puts "\n"
end
raise GameError, e.message
end
end
|
#start_next_game ⇒ Object
39
40
41
42
|
# File 'lib/bridge/player.rb', line 39
def start_next_game
raise GameError, "Not ready to start game" unless game.next_game_ready?
game.start!
end
|