Class: MM::InputHelper
Instance Attribute Summary
#io
Instance Method Summary
collapse
#computer_choosing_graphic, #get_game, #get_player_1_name, #get_user_input, #initialize, #marching_dots, #new_game_starting_graphic
Instance Method Details
#computer_or_human_code_setter_inquiry(name) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/games/mastermind/input_helper.rb', line 5
def computer_or_human_code_setter_inquiry(name)
user_choice = get_user_input("#{name}, please enter \"1\" if you would like to be the code-guesser. Enter \"2\" if you would like to set the code and have the computer guess.", "Invalid entry. Please enter either 1(computer picks code) or 2 (you pick code)") do |input|
input == 1 || input == 2
end
if user_choice == 1
return :computer
elsif user_choice == 2
return :human
end
end
|
#custom_final_message(game) ⇒ Object
51
52
53
|
# File 'lib/games/mastermind/input_helper.rb', line 51
def custom_final_message(game)
io.present_with_new_line("The secret code was #{game.secret_code.join(",")}")
end
|
#draw_prompt ⇒ Object
30
31
32
|
# File 'lib/games/mastermind/input_helper.rb', line 30
def draw_prompt
io.present_with_new_line("No such luck! Please try again.")
end
|
#get_number_of_cols ⇒ Object
61
62
63
64
65
|
# File 'lib/games/mastermind/input_helper.rb', line 61
def get_number_of_cols
get_user_input("Please choose how many pegs you would like in each row, from 4 to 6.", "Please choose a number between 4 and 6.") do |input|
input.to_i >=4 && input.to_i <=6
end
end
|
#get_number_of_rows ⇒ Object
55
56
57
58
59
|
# File 'lib/games/mastermind/input_helper.rb', line 55
def get_number_of_rows
get_user_input("Please choose how many rows of pegs you would like, from 4 to 12.", "Please choose a number between 4 and 12.") do |input|
input.to_i >=4 && input.to_i <=12
end
end
|
#get_player_choice(game) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/games/mastermind/input_helper.rb', line 23
def get_player_choice(game)
user_choice = get_user_input("#{game.current_player_name}, please enter a secret code consisting of 4 numbers that correspond to the color of your guess. Do not separate with punctuation.", "Please re-enter a secret code guess, using exactly 4 numbers, each being a digit 1 through 6.") do |input|
input.to_s =~ /^[1-6]{4}$/
end
user_choice.to_s.chars.map(&:to_i)
end
|
#get_secret_code_from_user(name) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/games/mastermind/input_helper.rb', line 16
def get_secret_code_from_user(name)
user_choice = get_user_input("#{name}, please enter a secret code consisting of four numbers that each correspond to a color. Do not separate with punctuation. The computer will try to guess this code.", "Please re-enter a secret code, using only 4 numbers, 1 through 6.") do |input|
input.to_s =~ /^[1-6]{4}$/
end
user_choice.to_s.chars.map(&:to_i)
end
|
#initial_instructions ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/games/mastermind/input_helper.rb', line 34
def initial_instructions
io.present_with_new_line("MASTERMIND")
io.present_with_new_line("__________")
io.present_with_new_line("Game Instructions: Try to guess a 4 digit code that contains a collection of numbers 1-6 (\"6241\", for example).")
io.present_with_new_line("After each guess, the \"Result\" section will generate an \"X\" for each digit in the guess that is perfect(correct number and correct spot) and an \"O\" for each digit that is the correct number but in the wrong spot.")
io.present_with_new_line("Type \"Exit\" to quit the game.")
io.present_with_new_line("___________")
end
|
#no_winner_prompt ⇒ Object
47
48
49
|
# File 'lib/games/mastermind/input_helper.rb', line 47
def no_winner_prompt
io.present_with_new_line("Game over!")
end
|
#winning_prompt(current_player_name) ⇒ Object
43
44
45
|
# File 'lib/games/mastermind/input_helper.rb', line 43
def winning_prompt(current_player_name)
io.present_with_new_line("#{current_player_name} wins!")
end
|