Module: Codebreaker

Defined in:
lib/codebreaker.rb,
lib/codebreaker/version.rb,
lib/codebreaker/bll/comands.rb,
lib/codebreaker/bll/statistic.rb,
lib/codebreaker/helpers/error.rb,
lib/codebreaker/bll/game_engine.rb,
lib/codebreaker/dal/modules/dal_module.rb,
lib/codebreaker/helpers/helpers_module.rb,
lib/codebreaker/bll/modules/error_module.rb,
lib/codebreaker/bll/modules/rules_module.rb,
lib/codebreaker/dal/modules/error_module.rb,
lib/codebreaker/helpers/validation_module.rb

Defined Under Namespace

Modules: BLL, DAL, Helpers Classes: UnexpectedActionError

Constant Summary collapse

NoAttamptsError =
Class.new(ArgumentError)
VERSION =
'0.1.7'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(**diffucult) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/codebreaker.rb', line 8

def start(**diffucult)
  BLL::GameEngine.new(**diffucult).tap do |breaker|
    loop do
      input = CLI::UI.ask("Enter ur guesse. (`hint` - total #{breaker.hints}, `attempts - #{breaker.attempts}`)")

      p breaker.secret_number.to_s

      if input == 'hint'
        puts breaker.hint

        next
      end

      break if breaker.input_guess?(input.chars.map(&:to_i))
    end

    save_statistic(diffucult_name: diffucult[:diffucult_name], attempts: breaker.attempts, hints: breaker.hints)
  end

  private

  def save_statistic(**stats)
    UI::SuccessesPage.save_statistic(
      diffucult_name: stats[:diffucult_name],
      attempts: stats[:attempts],
      hints: stats[:hints]
    )
  end
end

Instance Method Details

#save_statistic(**stats) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/codebreaker.rb', line 29

def save_statistic(**stats)
  UI::SuccessesPage.save_statistic(
    diffucult_name: stats[:diffucult_name],
    attempts: stats[:attempts],
    hints: stats[:hints]
  )
end