Sha256: fc14b34794ff51add4cdbec20078ed548a98b5a3389f6f5671d8670cf99e7e3c

Contents?: true

Size: 708 Bytes

Versions: 1

Compression:

Stored size: 708 Bytes

Contents

module Codebreaker
  module Marker
    def check_win
      if win?
        puts 'Congratulation! You win!'
      elsif @attempts == 0
        puts "Game over! Secret code is #{@secret_code}."
        @hint = 0
      else
        puts "+"*pluses + '-'*(minuses-pluses)
        @attempts -= 1
      end
    end

    def pluses
      @player_code.chars.to_a.map.with_index { |num, index| '+' if num == @secret_code[index] }.compact.size
    end

    def minuses
      secret_code = @secret_code.chars.to_a
      @player_code.chars.to_a.map{ |num| secret_code[secret_code.find_index(num)] = '-' if secret_code.include?(num) }.count('-')
    end

    def win?
      @secret_code == @player_code
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Codebreaker_RG2016-0.2.0 lib/codebreaker/modules/marker.rb