Sha256: 30b0930acdb071b60d0754b5a158e2e8d767d4bfdd32918f65efc7342229f894

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module AlexCodebreaker
  class Session
    include AlexCodebreaker::Modules::ArgumentsValidation

    INITIAL_ATTEMPTS_USED = 0
    INITIAL_HINTS_USED = 0

    attr_reader :hints_used, :attempts_used, :player_name, :hints_total,
                :difficulty_name, :attempts_total, :difficulty_level

    def initialize
      @attempts_used = INITIAL_ATTEMPTS_USED
      @hints_used = INITIAL_HINTS_USED
    end

    def add_name(given_name)
      @player_name = given_name if name_validation(given_name)
    end

    def add_difficulty(difficulty)
      difficulty_level = AlexCodebreaker::Modules::DifficultyLevels::DIFFICULTY_LEVELS[difficulty.downcase.to_sym]
      return unless difficulty_level

      @difficulty_name = difficulty_level[:name]
      @difficulty_level = difficulty_level[:level]
      @attempts_total = difficulty_level[:attempts_total]
      @hints_total = difficulty_level[:hints_total]
    end

    def check_hints
      @hints_used += 1 if @hints_used < @hints_total
    end

    def check_attempts
      @attempts_used += 1 if @attempts_used < @attempts_total - 1
    end

    def save_statistic
      File.open(AlexCodebreaker::Modules::Files::STATS_FILE, 'a') { |file| file.write(to_yaml) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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