-
-
Save anonymous/54060c0c7b3c47716758 to your computer and use it in GitHub Desktop.
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
def readLastKey | |
char = STDIN.read_nonblock(1).ord rescue nil | |
key = char | |
while char != nil | |
char = STDIN.read_nonblock(1).ord rescue nil | |
if char != nil | |
key = char | |
end | |
end | |
key | |
end | |
class DodgeGame | |
def initialize | |
@position = 0 | |
end | |
def printWorld | |
puts "\r\n\n\n" | |
puts "#######################################\r" | |
print "#" | |
i = 0 | |
while i < 33 | |
if @position == i | |
print "(^u^)" | |
else | |
print " " | |
end | |
i = i + 1 | |
end | |
puts "#\r" | |
puts "# #\r" | |
puts "# #\r" | |
puts "# #\r" | |
puts "# #\r" | |
puts "# #\r" | |
puts "# #\r" | |
puts "#######################################\r" | |
end | |
def moveChar | |
key = readLastKey | |
if key == 68 and @position > 0 | |
@position = @position - 1 | |
elsif key == 67 and @position < 31 | |
@position = @position + 1 | |
end | |
end | |
def gameLoop | |
i = 0 | |
system('stty raw -echo') | |
while i < 300 | |
sleep 0.1 | |
moveChar | |
printWorld | |
i = i + 1 | |
end | |
system('stty -raw echo') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment