Class: BlackJack::Game
- Inherits:
-
Object
- Object
- BlackJack::Game
- Defined in:
- lib/black_jack/game.rb
Overview
this is a fairly self-explanitory section
Instance Attribute Summary collapse
-
#game_name ⇒ Object
readonly
Returns the value of attribute game_name.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Instance Method Summary collapse
-
#add_player(a_player) ⇒ Object
adds a player to the game, doesn’t really work the way I want it to :(.
- #hit(deck) ⇒ Object
-
#initialize(game_name, num_players = 2) ⇒ Game
constructor
A new instance of Game.
-
#print_players(players = @players) ⇒ Object
a method to easily print out the player.
-
#take_card(deck = @deck, player = @player) ⇒ Object
we don’t use the two methods below (they are also in player) I feel like they should be here.
Constructor Details
#initialize(game_name, num_players = 2) ⇒ Game
Returns a new instance of Game.
10 11 12 13 14 |
# File 'lib/black_jack/game.rb', line 10 def initialize game_name, num_players=2 @game_name = game_name @num_players = num_players @players = [] end |
Instance Attribute Details
#game_name ⇒ Object (readonly)
Returns the value of attribute game_name.
9 10 11 |
# File 'lib/black_jack/game.rb', line 9 def game_name @game_name end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
9 10 11 |
# File 'lib/black_jack/game.rb', line 9 def players @players end |
Instance Method Details
#add_player(a_player) ⇒ Object
adds a player to the game, doesn’t really work the way I want it to :(
19 20 21 |
# File 'lib/black_jack/game.rb', line 19 def add_player a_player @players.push(a_player) end |
#hit(deck) ⇒ Object
40 41 42 |
# File 'lib/black_jack/game.rb', line 40 def hit deck self.take_card (deck) end |
#print_players(players = @players) ⇒ Object
a method to easily print out the player
25 26 27 28 29 |
# File 'lib/black_jack/game.rb', line 25 def print_players(players=@players) players.each do |player| puts "#{player.name} has #{player.hand}" end end |
#take_card(deck = @deck, player = @player) ⇒ Object
we don’t use the two methods below (they are also in player) I feel like they should be here
34 35 36 37 38 |
# File 'lib/black_jack/game.rb', line 34 def take_card deck=@deck, player=@player @hand = [] @hand << deck.deal_a_card @hand end |