class Game

Attributes

players[R]
title[R]

Public Class Methods

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

Public Instance Methods

add_player(player) click to toggle source
# File lib/game.rb, line 25
def add_player(player)
  @players.push(player)
end
load_player(file_path) click to toggle source
# File lib/game.rb, line 15
 def load_player(file_path)
  File.open(file_path) do |aFile|
    aFile.each_line do |line|
     @files<<line
    end
  end
  @files.each do |i|
    add_player(Player.from_csv(i))
  end
end
play(count) click to toggle source
# File lib/game.rb, line 60
def play(count)
  1.upto(count.to_i) do |time|
    puts "Round #{time}"
    @players.each do |player|
      GameTurn.take_turn(player)
      puts player
    end
  end
  treasure = TreasureTrove::TREASURES
  puts "There are #{treasure.size} treasures to be found"
  treasure.each do |treasure|
    puts "A #{treasure.name} is worth #{treasure.point} points"
  end
end
print_name_and_health(player) click to toggle source
print_stats() click to toggle source
save_high_score(file_name = "high_score.txt") click to toggle source
# File lib/game.rb, line 82
def save_high_score(file_name = "high_score.txt")
   file = File .open(file_name,"a")
   file.puts "knucleheads high scores!!!!"
   players.sort.each do |player|
    file.puts "#{player.name.ljust(10,".")}#{player.score}"
  end
end
total_points() click to toggle source
# File lib/game.rb, line 74
def total_points
  @players.each do |player|
    player.found_treasures.each do |key,value|
       $total_points += value
    end
  end
  $total_points
end