paitin_hangman 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,80 +0,0 @@
1
- require_relative "messages"
2
-
3
- module PaitinHangman
4
- module SimpleMethods
5
-
6
- def verify_name_integrity
7
- name = gets.chomp.upcase.strip
8
- while name.scan(/[^A-Z\s-]/).empty? == false || name.empty?
9
- Message.verify_name
10
- name = STDIN.gets.chomp.upcase.strip
11
- end
12
- name
13
- end
14
-
15
- # => This technically begins the game
16
- def play(name)
17
- Message.game_type
18
- option_integrity
19
- if @option == "2"
20
- Computer.new.level_integrity(name)
21
- else
22
- Player.new.first_player_name(name)
23
- end
24
- end
25
- # => The method makes sure a valid option is picked
26
-
27
- def option_integrity
28
- @option = gets.chomp
29
- until @option == "1" || @option == "2"
30
- puts "Enter either a '1' or a '2'"
31
- @option = STDIN.gets.chomp
32
- end
33
- @option
34
- end
35
-
36
- def length_one?(parameter)
37
- if parameter.length == 1
38
- return true
39
- else
40
- puts "Enter just one letter or an hyphen or an apostrophe"
41
- return false
42
- end
43
- end
44
-
45
- def unique?(parameter)
46
- if @misses.include?(parameter) || @right_guesses.include?(parameter)
47
- puts "You have used #{parameter} already, try again"
48
- return false
49
- else
50
- return true
51
- end
52
- end
53
-
54
- def number?(parameter)
55
- if parameter.scan(/\d/).empty?
56
- return true
57
- else
58
- puts "You cannot enter a number! Try again"
59
- return false
60
- end
61
- end
62
-
63
- def choice_integrity
64
- choice = gets.chomp.downcase
65
- until choice == "r" || choice == "q" || choice == "quit"
66
- puts "You must enter either a 'r' or 'q' or type 'quit'"
67
- choice = STDIN.gets.chomp.downcase
68
- end
69
- decide(choice)
70
- end
71
-
72
- def decide(choice)
73
- if choice == "r"
74
- @player1 ? play(@player1) : play(@player2)
75
- else
76
- exit
77
- end
78
- end
79
- end
80
- end
@@ -1,89 +0,0 @@
1
- require_relative "levels"
2
- module PaitinHangman
3
- class GameResumption
4
- def initialize
5
- @all_games = YAML.load_stream(File.open("games.yml", "a+"))
6
- puts "Enter the name you used to store the game"
7
- name = STDIN.gets.chomp.upcase
8
- @saved_game = @all_games.select do |game|
9
- game.player_name == name
10
- end
11
- initialize_cont(name)
12
- end
13
-
14
- def initialize_cont(name)
15
- if @saved_game.empty?
16
- puts "You have no saved game with that name".red
17
- puts "START A NEW GAME INSTEAD".yellow
18
- exit
19
- end
20
- puts "Here are the saved games found for #{name}\n\n"
21
- print_function
22
- choice_integrity
23
- end
24
-
25
- def choice_integrity
26
- puts "Now enter the number for the game you want to play"
27
- @choice = STDIN.gets.chomp.to_i
28
- until @choice > 0 && @choice <= @saved_game.length
29
- puts "Enter a number that has a game please"
30
- @choice = STDIN.gets.chomp.to_i
31
- end
32
- @choice -= 1
33
- load_properties
34
- end
35
-
36
- def load_properties
37
- @game_object = @saved_game[@choice]
38
- @name = @game_object.player_name
39
- @misses = @game_object.misses
40
- @right_guesses = @game_object.right_guesses
41
- @chances = @game_object.chances
42
- @word_control = @game_object.word_control
43
- @game_word = @game_object.game_word
44
- load_properties_cont
45
- end
46
-
47
- def load_properties_cont
48
- count = @game_object.count
49
- Saved.new(@name, @chances, @word_control, @game_word,
50
- @misses, @right_guesses, count).trials(@chances)
51
- end
52
-
53
- def print_function
54
- @saved_game.length.times do |index|
55
- print "#{index + 1}.\t"
56
- puts @saved_game[index], "\n"
57
- end
58
- end
59
- end
60
-
61
- class Saved < Levels
62
- def initialize(name, chances, word_control, game_word, misses, right_guesses,
63
- count)
64
- @player_name = name
65
- @chances = chances
66
- @word_control = word_control
67
- @game_word = game_word
68
- @misses = misses
69
- @right_guesses = right_guesses
70
- @count = count
71
- end
72
-
73
- def trials(chances)
74
- setup
75
- chances.times do |counter|
76
- @counter = counter
77
- verify_guess
78
- compare_guess
79
- win_game(chances, counter, @player_name)
80
- end
81
- end_game(@player_name)
82
- end
83
-
84
- def setup
85
- puts "Now, continue playing..."
86
- puts @word_control.gsub("_", "__ ").upcase
87
- end
88
- end
89
- end