Sha256: 7b8c07598c03252ff316a359ebfc011fbc0223783b1979c33cc6573a245441a4

Contents?: true

Size: 869 Bytes

Versions: 2

Compression:

Stored size: 869 Bytes

Contents

module MM
  class GameStateChanger
    attr_accessor :game

    def change_game_state(guess, game)
      @game = game
      game.current_guess = guess
      game.current_result = game.evaluate_guess(secret_code, current_guess)
      change_pegs(guess, game.current_result)
      if !game.won?
        game.move_forward_one_turn
      end
    end

    def change_pegs(guess, current_result)
      current_row.each_with_index do |peg, index|
        peg.change_value(guess[index])
      end

      result_pegs_current_row.each_with_index do |peg, index|
        peg.change_value(current_result[index])
      end
    end

    def current_row
      game.pegs_current_row
    end

    def result_pegs_current_row
      game.result_pegs_current_row
    end

    def secret_code
      game.secret_code
    end

    def current_guess
      game.current_guess
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
games_bfox-0.3.0 lib/games/mastermind/game_state_changer.rb
games_bfox-0.2.0 lib/games/mastermind/game_state_changer.rb