Created
January 19, 2015 17:36
-
-
Save huezoaa/c8abe3ee47e261a42f5d to your computer and use it in GitHub Desktop.
mo_memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mo = [] #The computer's sequence of lights. | |
#Does not clear through execution | |
your_entry = [] #The player's sequence of lights. Clears on every loop | |
level = 0 #Counter that increases with every loop. | |
#used to display level and add new index to mo array. | |
while mo == your_entry # Will run until player makes a mistake | |
print "\033c" # This clears the screen! | |
puts level > 0 ? "Awesome! Let's try again!" : "First round, go!" | |
# Greeting at the start of the game, and after each level is cleared. | |
sleep 1 # This makes Ruby wait 1 seconds! | |
# Pause for suspense and ease of use. | |
print "\033c" # This clears the screen! | |
# The following line is how the mo array is built. | |
# A random number is added to the index | |
# corresponding to "level" in the mo array. | |
mo[level] = rand(4) # Random number from 1 to 4 added to array mo | |
puts "Level #{level}. Mo's entry:" | |
# Interaction with user. Shows level and prompts for entry. | |
p mo # Displays computer's sequence. | |
#The following loop keeps the computer's array on screen for 3 seconds | |
# and provides a counter | |
puts `say Your Turn in ` | |
(0..2).each {|countdown| | |
puts `say #{(3-countdown)}` | |
sleep 0.25 | |
# This makes Ruby wait 1 second! | |
} | |
puts `say "Go!"` | |
# The screen gets cleared and user is prompted for entry. | |
print "\033c" | |
# This clears the screen! | |
puts "Now it's your turn. Go:" | |
# One digit at a time, pressing enter after each. | |
(0..level).each { |entry| | |
your_entry[entry] = gets.to_i | |
} | |
# Displays user entry in array format. | |
# This will need to go when game implements lights | |
puts "Your entry was: " | |
p your_entry | |
# counter for level is incremented by 1 | |
level += 1 | |
# This is the end of the while loop. Loop keeps going until user makes a mistake | |
end | |
# When the user makes a mistake: | |
print "\033c" | |
puts "Boo.." | |
sleep 1 | |
print "\033c" | |
# This clears the screen! | |
puts "So sorry...\n\n" | |
puts `say So sorry..` | |
# Pause for suspense... | |
sleep 0.5 | |
puts "Mo's entry was:" | |
p mo | |
puts "Yours was:" | |
p your_entry | |
print "\n\n\n\n" | |
puts "Thanks for playing.\n\n\n\n\n\n" | |
puts `say Thanks for playing` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment