Sha256: e1ccfa4fd3d45e39a263d6b0c432f9f2dc5d9d7541241bfa79c256df51b42524
Contents?: true
Size: 739 Bytes
Versions: 1
Compression:
Stored size: 739 Bytes
Contents
module Codebreaker module Marker def check_win if win? 'Congratulation! You win!' elsif @attempts.zero? @hint = 0 @game_start = false "Game over! Secret code is #{@secret_code}." else @attempts -= 1 '+' * pluses + '-' * (minuses - pluses) end end def pluses @player_code.to_s.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.to_s.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.1 | lib/codebreaker/modules/marker.rb |