Class: NewSuperCodebreaker2021::Game
Constant Summary
collapse
- GUESS_COMMANDS =
%i[hint rules exit].freeze
- START_COMMANDS =
%i[start rules stats exit].freeze
- DIFFICULTY_COMMANDS =
%i[easy medium hell exit].freeze
- AFTER_GAME_COMMANDS =
%i[start save exit].freeze
- YES_NO_COMMANDS =
%i[yes no].freeze
Instance Method Summary
collapse
Methods included from DBMethods
#load_file, #save
#show_stats
Methods included from Validate
#check_input, #validate_name, #validate_user_code
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
12
13
14
|
# File 'lib/game.rb', line 12
def initialize
@code = generate_code
end
|
Instance Method Details
#after_game_commands(command) ⇒ Object
57
58
59
|
# File 'lib/game.rb', line 57
def after_game_commands(command)
check_input(command, AFTER_GAME_COMMANDS)
end
|
#attempt_to_start(command) ⇒ Object
61
62
63
|
# File 'lib/game.rb', line 61
def attempt_to_start(command)
check_input(command, YES_NO_COMMANDS)
end
|
#chose_command(command) ⇒ Object
22
23
24
|
# File 'lib/game.rb', line 22
def chose_command(command)
check_input(command, START_COMMANDS)
end
|
#chose_difficulty(difficulty) ⇒ Object
34
35
36
|
# File 'lib/game.rb', line 34
def chose_difficulty(difficulty)
check_input(difficulty, DIFFICULTY_COMMANDS)
end
|
#compare_codes(user_code) ⇒ Object
65
66
67
68
|
# File 'lib/game.rb', line 65
def compare_codes(user_code)
matches, u_char = number_on_right_place(user_code)
number_in_secret_code(user_code, matches, u_char)
end
|
#take_hint(user, code, used_hints) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/game.rb', line 47
def take_hint(user, code, used_hints)
if user.hints_total > user.hints_used
user.hints_used += 1
used_hints.each { |hint| code.delete(hint) }
code.sample
else
false
end
end
|
#take_name(input_name) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/game.rb', line 26
def take_name(input_name)
if input_name == 'exit'
:exit
else
validate_name(input_name)
end
end
|
#user_guess(code) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/game.rb', line 38
def user_guess(code)
if code.to_i != 0
validate_user_code(code)
elsif GUESS_COMMANDS.include?(code.to_sym)
code.to_sym
else false
end
end
|