class ToccoStudioGame::Game
Attributes
title[R]
Public Class Methods
new(title)
click to toggle source
# File lib/tocco_studio_game/game.rb, line 7 def initialize(title) @title = title @players = [] end
Public Instance Methods
add_player(aPlayer)
click to toggle source
# File lib/tocco_studio_game/game.rb, line 32 def add_player(aPlayer) @players << aPlayer end
high_score_entry(player)
click to toggle source
# File lib/tocco_studio_game/game.rb, line 35 def high_score_entry(player) "#{player.name} ....... #{player.score}" end
load(file_name)
click to toggle source
# File lib/tocco_studio_game/game.rb, line 12 def load(file_name) File.open(file_name) do |file| file.each_line do |line| player,health = line.split(/[\s,]/) playerAdd = Player.new(player, Integer(health)) add_player(playerAdd) end end def save(file_name = "high_scores.txt") File.open(file_name, 'w') do |file| file.puts "#{@title} High Scores:" @players.sort.each do |player| file.puts high_score_entry(player) end end end end
play(rounds)
click to toggle source
# File lib/tocco_studio_game/game.rb, line 38 def play(rounds) winCheck = false puts "There are #{@players.size} players in #{title}:" @players.each do |player| puts player end treasures = TreasureTrove::TREASURES puts "There are #{treasures.length} treasures to be found." treasures.each do |item| puts "A #{item.name} is worth #{item.points} points" end rounds.times do |count| puts "Round #{count+1} \n----------------------------------------" @players.each do |player| GameTurn.take_turn(player) puts player if player.score >= 500000 winCheck = true end end break if winCheck == true end print_stats end
print_stats()
click to toggle source
# File lib/tocco_studio_game/game.rb, line 62 def print_stats puts "#{@title} Statistics:" strongPlayers = [] wimpyPlayers =[] @players.each do |player| if player.strong? == true strongPlayers << "#{player.name}(#{player.health})" else wimpyPlayers << "#{player.name}(#{player.health})" end end puts "#{strongPlayers.length} Strong Players:" puts strongPlayers puts "#{wimpyPlayers.length} Wimpy Players" puts wimpyPlayers puts "#{title} High Scores:" highScores = @players.sort highScores.each do |player| puts high_score_entry(player) end puts "\n" @players.each do|player| puts "#{player.name}'s Point Totals:" player.each_found_treasure do |treasure| puts "#{treasure.points} total #{treasure.name} points" end puts "#{player.score} grand total points \n" end end
save(file_name = "high_scores.txt")
click to toggle source
# File lib/tocco_studio_game/game.rb, line 21 def save(file_name = "high_scores.txt") File.open(file_name, 'w') do |file| file.puts "#{@title} High Scores:" @players.sort.each do |player| file.puts high_score_entry(player) end end end