Class: StudioGame::Game
- Inherits:
-
Object
- Object
- StudioGame::Game
- Defined in:
- lib/studio_game/game.rb
Instance Attribute Summary collapse
-
#players ⇒ Object
readonly
Returns the value of attribute players.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #add_player(player) ⇒ Object
-
#initialize(title = "Game", players = []) ⇒ Game
constructor
A new instance of Game.
- #play(rounds = 1) ⇒ Object
- #remove_player(player) ⇒ Object
Methods included from HandleCSV
#load_players, #save_high_scores
Methods included from Printable
#print_health_status, #print_player_information, #print_score, #print_treasure_trove, #print_treasures
Methods included from GameStats
#print_high_scores, #print_stats, #print_strength_stats, #print_treasure_stats, #total_points
Methods included from Formatting
#format_dot_spacing, #format_section_title
Constructor Details
#initialize(title = "Game", players = []) ⇒ Game
Returns a new instance of Game.
13 14 15 16 |
# File 'lib/studio_game/game.rb', line 13 def initialize(title = "Game", players = []) @title = title.capitalize @players = players end |
Instance Attribute Details
#players ⇒ Object (readonly)
Returns the value of attribute players.
12 13 14 |
# File 'lib/studio_game/game.rb', line 12 def players @players end |
#title ⇒ Object
Returns the value of attribute title.
12 13 14 |
# File 'lib/studio_game/game.rb', line 12 def title @title end |
Instance Method Details
#add_player(player) ⇒ Object
22 23 24 |
# File 'lib/studio_game/game.rb', line 22 def add_player(player) @players << player end |
#play(rounds = 1) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/studio_game/game.rb', line 30 def play(rounds = 1) print_player_information print_treasure_trove 1.upto(rounds) do |round| if block_given? break if yield end puts "\nROUND #{round}:" @players.each do |player| GameTurn.take_turn(player) end end end |
#remove_player(player) ⇒ Object
26 27 28 |
# File 'lib/studio_game/game.rb', line 26 def remove_player(player) @players.delete(player) end |