lib/games/shared/io_helpers.rb in games_bfox-0.4.0 vs lib/games/shared/io_helpers.rb in games_bfox-0.6.0
- old
+ new
@@ -10,10 +10,21 @@
def initial_instructions
raise 'Called abstract method: initial_instructions'
end
+ def choose_game
+ user_choice = get_user_input("Please enter " + Paint["\"1\" ", :blue, :bold] + "if you would like to play " + Paint["tictactoe. ", :blue, :bold] + "Enter " + Paint["\"2\" ", :red, :bold] + "if you would like to play " + Paint["mastermind.", :red, :bold], "Invalid entry. Please enter either 1(tictactoe) or 2 (mastermind)") do |input|
+ input == 1 || input == 2
+ end
+ if user_choice == 1
+ :tictactoe
+ elsif user_choice == 2
+ :mastermind
+ end
+ end
+
def get_player_1_name
user_choice = get_user_input("Player 1, please enter your name:", "Please re-enter your name, using only letters") do |input|
input =~ /^[a-zA-Z]+$/
end
user_choice.capitalize
@@ -54,12 +65,10 @@
def custom_final_message(game)
#hook
end
- private
-
def get_user_input(prompt, reprompt, &block_validation)
io.present_with_new_line(prompt)
user_choice = nil
while true
user_choice = io.receive
@@ -71,9 +80,11 @@
break if block_validation.call(user_choice)
puts reprompt
end
user_choice
end
+
+ private
def marching_dots
sleep(0.2)
io.present(".")
sleep(0.2)
\ No newline at end of file