alex_codebreaker 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/alex_codebreaker.rb +1 -1
- data/lib/alex_codebreaker/game.rb +2 -26
- data/lib/alex_codebreaker/game_manager.rb +28 -0
- data/lib/alex_codebreaker/version.rb +1 -1
- metadata +3 -3
- data/lib/alex_codebreaker/id_generator.rb +0 -18
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 27cd5b4709e1ed372047a4ddb854b71afffea2ca579a37fae4b4047b5b9fd47b
         | 
| 4 | 
            +
              data.tar.gz: 2d87c18c9885633d9a96210dcf41b9dd391ed632495803d18ec067f1f108a254
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: eaf51702ae8b5704f84b16d6986d8cc8c7e47339f45f15053c2bd32a563db555a7004b64076d94959439badae83f474e278b51e4bf8041393d685a5fa45c1d6a
         | 
| 7 | 
            +
              data.tar.gz: d6dac500500615a3c9655bd1ff85c1571300968397b147e489eaef7557c780b7f3b1c0e70529bd6191c020be0e60c33a1c6d7e938884f19e891b1df58b58779e
         | 
    
        data/lib/alex_codebreaker.rb
    CHANGED
    
    | @@ -7,8 +7,8 @@ require_relative 'alex_codebreaker/modules/difficulty_levels' | |
| 7 7 | 
             
            require_relative 'alex_codebreaker/modules/validators'
         | 
| 8 8 | 
             
            require_relative 'alex_codebreaker/modules/arguments_validation'
         | 
| 9 9 | 
             
            require_relative 'alex_codebreaker/secret_code_generator'
         | 
| 10 | 
            -
            require_relative 'alex_codebreaker/id_generator'
         | 
| 11 10 | 
             
            require_relative 'alex_codebreaker/comparison'
         | 
| 12 11 | 
             
            require_relative 'alex_codebreaker/players_rating'
         | 
| 13 12 | 
             
            require_relative 'alex_codebreaker/session'
         | 
| 13 | 
            +
            require_relative 'alex_codebreaker/game_manager'
         | 
| 14 14 | 
             
            require_relative 'alex_codebreaker/game'
         | 
| @@ -1,34 +1,23 @@ | |
| 1 1 | 
             
            module AlexCodebreaker
         | 
| 2 2 | 
             
              class Game
         | 
| 3 3 | 
             
                include AlexCodebreaker::Modules::ArgumentsValidation
         | 
| 4 | 
            -
             | 
| 4 | 
            +
             | 
| 5 5 | 
             
                STATUS = { in_game: :in_game, win: :win, lose: :lose }.freeze
         | 
| 6 6 |  | 
| 7 7 | 
             
                attr_reader :secret_code, :session, :game_id, :status, :used_hints, :current_comparison
         | 
| 8 8 |  | 
| 9 | 
            -
                def initialize | 
| 10 | 
            -
                  @game_id = outer_id if outer_id
         | 
| 9 | 
            +
                def initialize
         | 
| 11 10 | 
             
                  @secret_code = AlexCodebreaker::SecretCodeGenerator.new.secret_code
         | 
| 12 11 | 
             
                  @secret_code_for_hint = @secret_code.clone.uniq
         | 
| 13 12 | 
             
                  @session = Session.new
         | 
| 14 13 | 
             
                  @used_hints = []
         | 
| 15 14 | 
             
                  @status = STATUS[:in_game]
         | 
| 16 | 
            -
                  save_game
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                def add_name(name)
         | 
| 20 | 
            -
                  save_game if @session.add_name(name)
         | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                def add_difficulty(difficulty)
         | 
| 24 | 
            -
                  save_game if @session.add_difficulty(difficulty)
         | 
| 25 15 | 
             
                end
         | 
| 26 16 |  | 
| 27 17 | 
             
                def hint
         | 
| 28 18 | 
             
                  return unless @session.check_hints
         | 
| 29 19 |  | 
| 30 20 | 
             
                  process_hint
         | 
| 31 | 
            -
                  save_game
         | 
| 32 21 | 
             
                end
         | 
| 33 22 |  | 
| 34 23 | 
             
                def guess(user_input)
         | 
| @@ -36,7 +25,6 @@ module AlexCodebreaker | |
| 36 25 |  | 
| 37 26 | 
             
                  compare_codes(user_input)
         | 
| 38 27 | 
             
                  check_win_lose
         | 
| 39 | 
            -
                  save_game
         | 
| 40 28 | 
             
                end
         | 
| 41 29 |  | 
| 42 30 | 
             
                private
         | 
| @@ -66,17 +54,5 @@ module AlexCodebreaker | |
| 66 54 |  | 
| 67 55 | 
             
                  @status = STATUS[:lose] unless checking_result
         | 
| 68 56 | 
             
                end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
                def save_game
         | 
| 71 | 
            -
                  @game_id ||= AlexCodebreaker::IDGenerator.new.unique_id
         | 
| 72 | 
            -
                  unless File.directory?(AlexCodebreaker.configuration.games_folder_path)
         | 
| 73 | 
            -
                    FileUtils.mkdir_p(AlexCodebreaker.configuration.games_folder_path)
         | 
| 74 | 
            -
                  end
         | 
| 75 | 
            -
                  File.open(save_game_path, 'w') { |file| file.write(to_yaml) }
         | 
| 76 | 
            -
                end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                def save_game_path
         | 
| 79 | 
            -
                  "#{AlexCodebreaker.configuration.games_folder_path}#{@game_id}#{FILENAME_EXTENSION}"
         | 
| 80 | 
            -
                end
         | 
| 81 57 | 
             
              end
         | 
| 82 58 | 
             
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            module AlexCodebreaker
         | 
| 2 | 
            +
              class GameManager
         | 
| 3 | 
            +
                FILENAME_EXTENSION = '.yml'.freeze
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(game_id)
         | 
| 6 | 
            +
                  @game_id = game_id
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def save(game)
         | 
| 10 | 
            +
                  unless File.directory?(AlexCodebreaker.configuration.games_folder_path)
         | 
| 11 | 
            +
                    FileUtils.mkdir_p(AlexCodebreaker.configuration.games_folder_path)
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                  File.open(game_file_path, 'w') { |file| file.write(game.to_yaml) }
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def load
         | 
| 17 | 
            +
                  return unless File.exist?(game_file_path)
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  YAML.load_file(game_file_path)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                private
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def game_file_path
         | 
| 25 | 
            +
                  "#{AlexCodebreaker.configuration.games_folder_path}#{@game_id}#{FILENAME_EXTENSION}"
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: alex_codebreaker
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Oleksandr Loza
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020-04- | 
| 11 | 
            +
            date: 2020-04-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -163,7 +163,7 @@ files: | |
| 163 163 | 
             
            - lib/alex_codebreaker/comparison.rb
         | 
| 164 164 | 
             
            - lib/alex_codebreaker/configuration.rb
         | 
| 165 165 | 
             
            - lib/alex_codebreaker/game.rb
         | 
| 166 | 
            -
            - lib/alex_codebreaker/ | 
| 166 | 
            +
            - lib/alex_codebreaker/game_manager.rb
         | 
| 167 167 | 
             
            - lib/alex_codebreaker/modules/arguments_validation.rb
         | 
| 168 168 | 
             
            - lib/alex_codebreaker/modules/difficulty_levels.rb
         | 
| 169 169 | 
             
            - lib/alex_codebreaker/modules/settings.rb
         | 
| @@ -1,18 +0,0 @@ | |
| 1 | 
            -
            module AlexCodebreaker
         | 
| 2 | 
            -
              class IDGenerator
         | 
| 3 | 
            -
                MIN_NUMBER = 1
         | 
| 4 | 
            -
                MAX_NUMBER = 9_999_999_999
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                attr_reader :unique_id
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                def initialize
         | 
| 9 | 
            -
                  @unique_id = generate_id
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                private
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                def generate_id
         | 
| 15 | 
            -
                  rand(MIN_NUMBER..MAX_NUMBER)
         | 
| 16 | 
            -
                end
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
            end
         |