Class: PaitinHangman::Levels
- Inherits:
-
Object
- Object
- PaitinHangman::Levels
- Includes:
- SimpleMethods
- Defined in:
- lib/paitin_hangman/levels.rb
Instance Attribute Summary collapse
-
#chances ⇒ Object
readonly
Returns the value of attribute chances.
-
#game_word ⇒ Object
readonly
Returns the value of attribute game_word.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#player1 ⇒ Object
readonly
Returns the value of attribute player1.
-
#player2 ⇒ Object
readonly
Returns the value of attribute player2.
Instance Method Summary collapse
- #challenge_word(min, max) ⇒ Object
-
#initialize(player, min, max, chances, another_player = nil) ⇒ Levels
constructor
A new instance of Levels.
- #initialize_specs(player, min, max, chances, another_player) ⇒ Object
- #word_generator(min, max) ⇒ Object
Methods included from SimpleMethods
#choice_integrity, #decide, #length_one?, #number?, #option_integrity, #unique?, #verify_name_integrity
Constructor Details
#initialize(player, min, max, chances, another_player = nil) ⇒ Levels
Returns a new instance of Levels.
11 12 13 14 15 16 17 |
# File 'lib/paitin_hangman/levels.rb', line 11 def initialize(player, min, max, chances, another_player = nil) initialize_specs(player, min, max, chances, another_player) puts "\t\tWelcome #{@player2}, In this level, you will have #{@chances} chances to guess the word correctly" word_generator(min, max) if @player1.nil? challenge_word(min, max) if @player1 end |
Instance Attribute Details
#chances ⇒ Object (readonly)
Returns the value of attribute chances.
9 10 11 |
# File 'lib/paitin_hangman/levels.rb', line 9 def chances @chances end |
#game_word ⇒ Object (readonly)
Returns the value of attribute game_word.
9 10 11 |
# File 'lib/paitin_hangman/levels.rb', line 9 def game_word @game_word end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
9 10 11 |
# File 'lib/paitin_hangman/levels.rb', line 9 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
9 10 11 |
# File 'lib/paitin_hangman/levels.rb', line 9 def min @min end |
#player1 ⇒ Object (readonly)
Returns the value of attribute player1.
9 10 11 |
# File 'lib/paitin_hangman/levels.rb', line 9 def player1 @player1 end |
#player2 ⇒ Object (readonly)
Returns the value of attribute player2.
9 10 11 |
# File 'lib/paitin_hangman/levels.rb', line 9 def player2 @player2 end |
Instance Method Details
#challenge_word(min, max) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/paitin_hangman/levels.rb', line 36 def challenge_word(min, max) puts "Now, enter your challenge_word #{@player1}, it will be hidden" @game_word = STDIN.noecho(&:gets).chomp.downcase.delete(" ") until @game_word.length >= min && @game_word.length <= max && number?(@game_word) puts "Word length not correct! Make it between #{min} & #{max} characters" @game_word = STDIN.noecho(&:gets).chomp.downcase.delete(" ") end puts "The stage is set #{@player2}" GameEngine.new.trials(@chances, @game_word, @player2, @player1) end |
#initialize_specs(player, min, max, chances, another_player) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/paitin_hangman/levels.rb', line 19 def initialize_specs(player, min, max, chances, another_player) @player2 = player @min = min @max = max @chances = chances @player1 = another_player end |
#word_generator(min, max) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/paitin_hangman/levels.rb', line 27 def word_generator(min, max) file_name = File.join(File.dirname(File.(__FILE__)), '../../dictionary.txt') words = File.open(file_name, "r").readlines.map!(&:chomp) level_words = words.select { |i| i.length >= min && i.length <= max } random_index = rand(level_words.length) @game_word = level_words[random_index] GameEngine.new.trials(@chances, @game_word, @player2, @player1) end |