Class: BlackJack::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/black_jack/game.rb

Overview

this is a fairly self-explanitory section

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

#playersObject (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

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