Skip to content

Instantly share code, notes, and snippets.

@jacobwalkr
Last active January 31, 2016 23:06
Show Gist options
  • Save jacobwalkr/e31d0802b1436b4aeacc to your computer and use it in GitHub Desktop.
Save jacobwalkr/e31d0802b1436b4aeacc to your computer and use it in GitHub Desktop.
require "curses"
include Curses
SNAKE = "\u2588\u2588"
init_screen
begin
crmode
curs_set 0
addstr "Loading..."
refresh
sleep 3
clear
refresh
thread = Thread.new do
stop = False
snake_y = 0
snake_x = 0
snake_dir_y = 0
snake_dir_x = 1
loop do
break if stop
clear
setpos snake_y, snake_x
addstr SNAKE
refresh
snake_y += snake_dir_y
snake_x += snake_dir_x
sleep 0.5
end
end
loop do
y = 0; x = 0
case getch
when KEY_UP
y = 1; x = 0
when KEY_DOWN
y = -1; x = 0
when KEY_LEFT
y = 0; x = -1
when KEY_RIGHT
y = 0; x = 1
when KEY_ENTER
thread[:stop] = true
thread.join
break
end
thread[:snake_dir_y] = y
thread[:snake_dir_x] = x
end
ensure
close_screen
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment