class GamalielPelino::Game
Public Class Methods
new(playlist)
click to toggle source
# File lib/GamalielPelino/Agam11_split2.rb, line 27 def initialize(playlist) @playlist = playlist @players = [] end
Public Instance Methods
add_player(player)
click to toggle source
# File lib/GamalielPelino/Agam11_split2.rb, line 32 def add_player(player) @players << player end
call_items()
click to toggle source
# File lib/GamalielPelino/Agam11_split2.rb, line 104 def call_items items = Item::PIECE puts "\n There are #{items.size} treasure to be found:" items.each do |call| puts "A #{call.item} is worth #{call.points} points" end end
load_players(default_player_file)
click to toggle source
# File lib/GamalielPelino/Agam11_split2.rb, line 52 def load_players(default_player_file) File.readlines(default_player_file).each do |line| add_player(Player.from_csv(line)) end end
play(rounds)
click to toggle source
# File lib/GamalielPelino/Agam11_split2.rb, line 36 def play(rounds) puts "There are #{@players.size} players in #{@playlist}:" @players.each do |player| puts player end 1.upto(rounds) do |count| puts "\n rounds #{count}" @players.each do |player| GameTurn.take_turn(player) puts player end end end
print_stats()
click to toggle source
def save_high_scores(to_file=“Agam19_save.csv”)
File.open(to_file, "w") do |file| file.puts "#{@title} High Scores:" @players.sort.each do |player| file.puts player.to_csv end end
end
# File lib/GamalielPelino/Agam11_split2.rb, line 68 def print_stats strong_players, wimpy_players = @players.partition { |player| player.strong? } puts "\n#{@title} Statistics:" puts "#{strong_players.size} strong players:" strong_players.each do |player| puts "#{player.name} (#{player.health})" end puts "\n#{wimpy_players.size} wimpy players:" wimpy_players.each do |player| puts "#{player.name} (#{player.health})" end sorted_players = @players.sort { |a, b| b.score <=> a.score } puts "\n#{@title} High Scores:" sorted_players.each do |player| formatted_name = player.name.ljust(20, '.') puts "#{formatted_name} #{player.score}" end # puts "\n#{@title} High Scores:" # @players.sort.each do |player| # puts high_score_entry(player) # end end
title()
click to toggle source
# File lib/GamalielPelino/Agam11_split2.rb, line 100 def title "==#{@playlist}==" end