Module: PaitinHangman::SimpleMethods
- Included in:
- GameEngine, Levels, Paitin, Player
- Defined in:
- lib/paitin_hangman/simple_methods.rb
Instance Method Summary collapse
- #choice_integrity ⇒ Object
- #decide(choice) ⇒ Object
- #length_one?(parameter) ⇒ Boolean
- #number?(parameter) ⇒ Boolean
-
#option_integrity ⇒ Object
> The method makes sure a valid option is picked.
- #unique?(parameter) ⇒ Boolean
-
#verify_name_integrity ⇒ Object
> This method verifies the integrity of names.
Instance Method Details
#choice_integrity ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/paitin_hangman/simple_methods.rb', line 53 def choice_integrity choice = gets.chomp.downcase until choice == "r" || choice == "q" || choice == "quit" puts "You must enter either a 'r' or 'q' or type 'quit'" choice = STDIN.gets.chomp.downcase end decide(choice) end |
#decide(choice) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/paitin_hangman/simple_methods.rb', line 62 def decide(choice) if choice == "r" @player1 ? Paitin.new.play(@player1) : Paitin.new.play(@player2) else exit end end |
#length_one?(parameter) ⇒ Boolean
26 27 28 29 30 31 32 33 |
# File 'lib/paitin_hangman/simple_methods.rb', line 26 def length_one?(parameter) if parameter.length == 1 return true else puts "Enter just one letter or an hyphen or an apostrophe" return false end end |
#number?(parameter) ⇒ Boolean
44 45 46 47 48 49 50 51 |
# File 'lib/paitin_hangman/simple_methods.rb', line 44 def number?(parameter) if parameter.scan(/\d/).empty? return true else puts "You cannot enter a number! Try again" return false end end |
#option_integrity ⇒ Object
> The method makes sure a valid option is picked
17 18 19 20 21 22 23 24 |
# File 'lib/paitin_hangman/simple_methods.rb', line 17 def option_integrity @option = gets.chomp until @option == "1" || @option == "2" puts "Enter either a '1' or a '2'" @option = STDIN.gets.chomp end @option end |
#unique?(parameter) ⇒ Boolean
35 36 37 38 39 40 41 42 |
# File 'lib/paitin_hangman/simple_methods.rb', line 35 def unique?(parameter) if @misses.include?(parameter) || @right_guesses.include?(parameter) puts "You have used #{parameter} already, try again" return false else return true end end |
#verify_name_integrity ⇒ Object
> This method verifies the integrity of names
6 7 8 9 10 11 12 13 |
# File 'lib/paitin_hangman/simple_methods.rb', line 6 def verify_name_integrity name = gets.chomp.upcase.strip while name.scan(/[^A-Z\s-]/).empty? == false || name.empty? # => It scans for anything other than a letter, a space or a dash Message.verify_name name = STDIN.gets.chomp.upcase.strip end name end |