Sha256: 84bdb022c86b359761cab4ac6add2a394ac92470b83c3538feb6b07601786b60

Contents?: true

Size: 552 Bytes

Versions: 1

Compression:

Stored size: 552 Bytes

Contents

module Codebreaker
  module Score
    def score
      @player.score += 250 if win?
      @player.score += @hint * 100 + @attempts * 50
      puts "#{player.name}, your score: #{@player.score}!"
    end

    def save_score?
      puts 'Do you want to save your score in score file?(y/n)'
      save_score_file if @player.agree?
      exit
    end

    private
    def save_score_file
      File.open("lib/codebreaker/score/#{@player.name}_score.txt", 'a') do |file|
        file.puts "#{@player.score} - #{Time.now.asctime}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Codebreaker_RG2016-0.1.0 lib/codebreaker/modules/score.rb