Sha256: 83daf03d32c817e8802421c41e2412993a78d8bed6b9b316499920c664662b2f

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

require_relative '../shared/game'

module MM
  class Game < Shared::Game
    attr_accessor :code_setter, :secret_code, :guess_evaluator, :current_guess, :current_result, :won_flag

    def local_setup
      self.code_setter = config.code_setter
      self.secret_code = config.secret_code
      print secret_code
      print "\n"
      self.guess_evaluator = MM::GuessEvaluator.new
      self.current_guess = []
      self.current_result = []
      self.won_flag = false
    end

    def over?
      won? || over_with_no_winner?
    end

    def over_with_no_winner?
      number_of_turns_taken >= 12
    end

    def won?
      #depends on evaluate_guess returning an array of all "X"s for perfect guess
      if won_flag
        return true
      end

      if current_result == ("X" * number_of_cols).chars
        self.won_flag = true
        true
      else
        false
      end
    end

    def change_peg(row, col, new_value)
      board.change_peg(row, col, new_value)
    end

    def evaluate_guess(secret_code, guess)
      guess_evaluator.evaluate_guess(secret_code, guess)
    end

    def pegs_current_row
      board.pegs_current_row(number_of_turns_taken)
    end

    def result_pegs_current_row
      board.result_pegs_current_row(number_of_turns_taken)
    end

    def number_of_cols
      board.number_of_cols
    end

    def set_secret_code
      config.set_secret_code
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
games_bfox-0.2.0 lib/games/mastermind/game.rb