Sha256: c6553e45a087f6745fea8d6075727cff087c497a83494090cca19f5a1eb1c914

Contents?: true

Size: 930 Bytes

Versions: 1

Compression:

Stored size: 930 Bytes

Contents

class Session
  INITIAL_ATTEMPTS_USED = 0
  INITIAL_HINTS_USED = 0

  attr_reader :difficulty_name, :difficulty_level, :attempts_total, :hints_total

  attr_accessor :player_name, :attempts_used, :hints_used

  def initialize
    @attempts_used = INITIAL_ATTEMPTS_USED
    @hints_used = INITIAL_HINTS_USED
  end

  def difficulty_manager(difficulty)
    if DifficultyLevels::DIFFICULTY_LEVELS.include?(difficulty)
      add_difficulty(DifficultyLevels::DIFFICULTY_LEVELS[difficulty])
    end
    return false unless DifficultyLevels::DIFFICULTY_LEVELS.include?(difficulty)
  end

  def save_session_statistic
    File.open(Files::STATS_FILE, 'a') do |file|
      file.write(to_yaml)
    end
  end

  private

  def add_difficulty(difficulty)
    @difficulty_name = difficulty[:name]
    @difficulty_level = difficulty[:level]
    @attempts_total = difficulty[:attempts_total]
    @hints_total = difficulty[:hints_total]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alex_codebreaker-0.1.5 lib/alex_codebreaker/session.rb