class StudioGame::Game

Attributes

title[R]

Public Class Methods

new(title) click to toggle source
# File lib/studio_game/game.rb, line 10
def initialize(title)
        @title = title
        @players = []
end

Public Instance Methods

add_player(player) click to toggle source
# File lib/studio_game/game.rb, line 15
def add_player(player)
        @players << player
end
grand_total(player) click to toggle source
# File lib/studio_game/game.rb, line 92
def grand_total(player)
  puts "#{player.points} grand total points"
end
high_score() click to toggle source
# File lib/studio_game/game.rb, line 98
def high_score
        sorted_players = @players.sort
        puts sorted_players
        puts "\n#{@title} High scores:"
        sorted_players.each do |player|
                puts player.format_score(player)
        end
end
load_players(file) click to toggle source
# File lib/studio_game/game.rb, line 19
def load_players(file)
        File.readlines(file).each do |line|
                add_player(Player.from_csv(line))
        end
end
play(rounds) click to toggle source
# File lib/studio_game/game.rb, line 35
def play(rounds)
        puts "There are #{@players.size} in #{@title}:"

        @players.each do |player|
                puts player
        end
        puts "\n"
        treasures = TreasureTrove::TREASURES

puts "There are #{treasures.size} treasures to be found:"
        treasures.each do |treasure|
                puts "A #{treasure.name} is worth #{treasure.points} points."
        end

        1.upto(rounds) do |round|
                puts "\nRound: #{round}"
              @players.each do |player|
                  GameTurn.take_turn(player)
            end
        end
end
print_name_and_health(player) click to toggle source
print_stats() click to toggle source
save_high_score(to_file = 'high_scores.txt') click to toggle source
# File lib/studio_game/game.rb, line 25
def save_high_score(to_file = 'high_scores.txt')
        File.open(to_file, "w") do |file|
                sorted_players = @players.sort
                file.puts "\n#{@title} High scores:"
                sorted_players.each do |player|
                        file.puts player.format_score(player)
                end
        end
end
treasure_details() click to toggle source
# File lib/studio_game/game.rb, line 82
def treasure_details
        @players.each do |player|
                puts "\n#{player.name}'s points total:"
                player.each_found_treasure do |treasure|
                        puts "#{treasure.points} total #{treasure.name} points."
                end
                grand_total(player)
        end
end