-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathColor_Game.rb
68 lines (58 loc) · 1.31 KB
/
Color_Game.rb
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
67
68
require 'io/console'
COLORS = ["Red", "Orange", "White", "Black", "Green", "Blue", "Brown", "Purple", "Cyan", "Yellow", "Pink", "Magenta"]
score = 0
displayed_word_color = ''
game_running = false
def print_score(score)
puts "Your Score: #{score}"
end
def print_time_left(seconds_left)
puts "Game Ends in: #{seconds_left}s"
end
def print_game_description
puts "Game Description: Enter the color of the words displayed below."
puts "And keep in mind not to enter the word text itself"
end
def start_game
if !game_running
game_running = true
system("clear")
print_game_description
print_score(score)
print_time_left(60)
displayed_word_color = COLORS.sample
end
end
def stop_game
game_running = false
system("clear")
puts "Game Over!"
end
def next_word
if game_running
displayed_word_text = COLORS.sample
puts displayed_word_text
print "Enter the color: "
displayed_word_color = COLORS.sample
end
end
def check_word(user_input)
if game_running
user_input.downcase!
if user_input == displayed_word_color.downcase
score += 1
print_score(score)
end
next_word
end
end
loop do
key = STDIN.getch
if key == ' '
start_game
elsif key == "\r"
print "Enter the color: "
user_input = gets.chomp
check_word(user_input)
end
end