Class: TTT::InputHelper

Inherits:
Shared::InputHelper show all
Defined in:
lib/games/tictactoe/input_helper.rb

Instance Attribute Summary

Attributes inherited from Shared::InputHelper

#io

Instance Method Summary collapse

Methods inherited from Shared::InputHelper

#computer_choosing_graphic, #custom_final_message, #get_game, #get_player_1_name, #get_user_input, #initialize, #marching_dots, #new_game_starting_graphic

Constructor Details

This class inherits a constructor from Shared::InputHelper

Instance Method Details

#draw_promptObject



75
76
77
# File 'lib/games/tictactoe/input_helper.rb', line 75

def draw_prompt
  io.present_with_new_line("Draw! Please try again.")
end

#get_computer_difficulty_levelObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/games/tictactoe/input_helper.rb', line 43

def get_computer_difficulty_level
  user_choice = get_user_input("Please enter \"E\" if you would like to play an easy Computer. Enter \"D\" if you would like to play an extremely difficult computer.", "Invalid character. Please enter either E (Easy) or D (Difficult).") do |input|
    input == 'd' || input == 'D' || input == 'e' || input == 'E'
  end
  user_choice = user_choice.upcase
  if user_choice == "D"
    :difficult
  elsif user_choice == "E"
    :easy
  end
end

#get_number_of_rows_cols_max_3Object



5
6
7
8
9
# File 'lib/games/tictactoe/input_helper.rb', line 5

def get_number_of_rows_cols_max_3
  get_user_input("Please choose how many squares you would like in each row.", "Please choose number between 2 and 3.") do |input|
    input.to_i >=2 && input.to_i <=3
  end
end

#get_number_of_rows_cols_max_9Object



11
12
13
14
15
# File 'lib/games/tictactoe/input_helper.rb', line 11

def get_number_of_rows_cols_max_9
  get_user_input("Please choose how many squares you would like in each row.", "Please choose number between 2 and 3.") do |input|
    input.to_i >=2 && input.to_i <=9
  end
end

#get_player_1_value(player_name = "Player 1") ⇒ Object



17
18
19
20
21
22
# File 'lib/games/tictactoe/input_helper.rb', line 17

def get_player_1_value(player_name = "Player 1")
  user_choice = get_user_input("#{player_name}, please enter a value of either X or O", "Must be X or O. Please re-enter.") do |input|
    input == 'x' || input == 'X' || input == 'o' || input == 'O'
  end
  user_choice.upcase
end

#get_player_2_nameObject



24
25
26
27
28
29
# File 'lib/games/tictactoe/input_helper.rb', line 24

def get_player_2_name
  user_choice = get_user_input("Player 2, please enter your name", "Please re-enter your name, using only letters") do |input|
    input =~ /^[a-zA-Z]+$/
  end
  user_choice.capitalize
end

#get_player_2_typeObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/games/tictactoe/input_helper.rb', line 31

def get_player_2_type
  user_choice = get_user_input("Please enter \"C\" if you would like to play the Computer. Enter \"H\" if you would like to play the human sitting next to you.", "Invalid character. Please enter either C(Computer) or H(Human).") do |input|
    input == 'c' || input == 'C' || input == 'h' || input == 'H'
  end
  user_choice = user_choice.upcase
  if user_choice == "C"
    :computer
  elsif user_choice == "H"
    :human
  end
end

#get_player_2_value(taken_value) ⇒ Object



55
56
57
58
59
60
# File 'lib/games/tictactoe/input_helper.rb', line 55

def get_player_2_value(taken_value)
  user_choice = get_user_input("Player 2, please enter your value", "Must not be #{taken_value}, please re-enter") do |input|
    input.upcase != taken_value.upcase
  end
  user_choice.upcase
end

#get_player_choice(game) ⇒ Object



62
63
64
65
66
# File 'lib/games/tictactoe/input_helper.rb', line 62

def get_player_choice(game)
  get_user_input("#{game.current_player_name}, please enter the number of the square that you would like to change.", "Invalid entry. Please try again.") do |input|
    game.available_choices.include?(input)
  end
end

#initial_instructionsObject



68
69
70
71
72
73
# File 'lib/games/tictactoe/input_helper.rb', line 68

def initial_instructions
  io.present_with_new_line("TIC TAC TOE")
  io.present_with_new_line("___________")
  io.present_with_new_line("Type \"Exit\" to quit the game.")
  io.present_with_new_line("___________")
end

#no_winner_promptObject



83
84
85
# File 'lib/games/tictactoe/input_helper.rb', line 83

def no_winner_prompt
  io.present_with_new_line("Draw!")
end

#winning_prompt(current_player_name) ⇒ Object



79
80
81
# File 'lib/games/tictactoe/input_helper.rb', line 79

def winning_prompt(current_player_name)
  io.present_with_new_line("#{current_player_name} wins!")
end