Class: Bridge::Player
- Inherits:
-
Object
- Object
- Bridge::Player
- Defined in:
- lib/bridge/player.rb
Instance Method Summary collapse
- #get_hand ⇒ Object (also: #hand)
-
#initialize(game) ⇒ Player
constructor
A new instance of Player.
- #make_call(call) ⇒ Object
- #play_card(card) ⇒ Object
- #start_next_game ⇒ Object
Constructor Details
#initialize(game) ⇒ Player
Returns a new instance of Player.
3 4 5 |
# File 'lib/bridge/player.rb', line 3 def initialize(game) @game = game # Access to game is private to this object. end |
Instance Method Details
#get_hand ⇒ Object Also known as: hand
7 8 9 10 |
# File 'lib/bridge/player.rb', line 7 def get_hand position = game.players[self] return game.get_hand(position) end |
#make_call(call) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bridge/player.rb', line 13 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. end end |
#play_card(card) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bridge/player.rb', line 25 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. end end |
#start_next_game ⇒ Object
37 38 39 40 |
# File 'lib/bridge/player.rb', line 37 def start_next_game raise GameError, "Not ready to start game" unless game.next_game_ready? game.start! end |