class StudioGame::Game

Attributes

title[R]

Public Class Methods

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

Public Instance Methods

add_player(player) click to toggle source
# File lib/studio_game/game.rb, line 13
def add_player(player)
  @players.push(player)
end
load_players(from_file) click to toggle source
# File lib/studio_game/game.rb, line 77
def load_players(from_file)
  File.readlines(from_file).each do |line|
    name, health = line.split(',')
    yungplayer = Player.new(name,health.to_i)
    add_player(yungplayer)
  end
end
play(rounds) click to toggle source
# File lib/studio_game/game.rb, line 54
def play(rounds)
  puts "Welcome to #{@title}!"
  puts "There are 6 treasures to be found:"
  treasures = TreasureTrove::TREASURES
  treasures.each do |treasure|
    puts "A #{treasure.name} is worth #{treasure.points} points!"
  end
  puts "There are #{@players.size} players in #{@title}. We will play #{rounds} rounds:"
  puts
  @players.each do |player|
    puts player
  end
  1.upto(rounds) do |round|
    puts
    puts "----ROUND #{round} ------"
    @players.each do |player|
      GameTurn.take_turn(player)
      puts player
    end
  end
  print_stats
end
pop_players() click to toggle source
# File lib/studio_game/game.rb, line 17
def pop_players
  @players.pop
end
print_final(player) click to toggle source
print_stats() click to toggle source
save_high_scores(to_file="high_scores.txt") click to toggle source
# File lib/studio_game/game.rb, line 85
def save_high_scores(to_file="high_scores.txt")
  File.open(to_file, "w") do |file|
    file.puts "#{@title} high scores:"
    @players.sort!
    @players.each do |playa|
      file.puts "#{playa.name.ljust(15, '.')} #{playa.points}"
    end
  end
end