-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.rb
More file actions
66 lines (56 loc) · 1.54 KB
/
runner.rb
File metadata and controls
66 lines (56 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require './mastermind'
puts "Welcome to Mastermind"
mastermind = Mastermind.new
response = nil
#user makes first menu selection
puts mastermind.print_menu
menu_select = gets.chomp
while menu_select != "q"
#user selects difficulty
if menu_select == "p"
difficulty_selected = nil
until difficulty_selected == "B" || difficulty_selected == "I" || difficulty_selected == "H"
puts mastermind.print_difficulty
print "> "
input = gets.chomp
difficulty_selected = input.upcase
end
mastermind.difficulty(input)
#generates secret answer & starts the game
puts mastermind.print_play
t1 = mastermind.time
mastermind.color_gen
response = nil
#runs the game until user wins or quits
until (response && response.status == :won) || (response && response.status == :quit)
print "> "
input = gets.chomp
mastermind.guess_gen(input)
mastermind.compare_positions
mastermind.compare_colors
mastermind.guess_count
response = mastermind.compare
puts response.message
end
#user wins or quits
if response.status == :won
t2 = mastermind.time
puts "Time: #{(t2 - t1).to_i} seconds"
print mastermind.play_again
menu_select = gets.chomp
elsif response.status == :quit
break
end
#other menu options
elsif menu_select == "i"
puts mastermind.print_instruct
menu_select = gets.chomp
else
puts mastermind.print_exception
menu_select = gets.chomp
end
end
if menu_select != "p"
puts mastermind.print_quit
end
puts "Goodbye!"