Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5d2dc4
commit 1d58e1f
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "curses";include $a=a=Curses;def w(i);i<5?i:5-i+4;end;$m="#### # ### ## # ";for j in 0..9;for i in 0..9;a.addstr $m[w(j)*5+w(i)].chr+(i>8?$/:"");end;end;$x=$y=2;def d(t="@");$a.setpos $y,$x;$a.addstr t;end;def m(x,y);$x,$y=x,y if $m[w(y)*5+w(x)]==32;end;s=a.init_screen;a.noecho;a.curs_set 0;s.keypad 1;d;until (c=s.getch)==?q;k={259=>[$x,$y-1],258=>[$x,$y+1],260=>[$x-1,$y],261=>[$x+1,$y]};d " ";m *k[c] if k[c];d;end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# see the c# version for a fuller description of what's going on | ||
# comments here are just to document tricks specific to the ruby version | ||
|
||
require "curses" | ||
# load the Curses class into a local and global var (it's cheaper to use both) | ||
include $a = a = Curses | ||
|
||
def w( i ) | ||
i < 5 ? i : 5 - i + 4 | ||
end | ||
|
||
$m="#### # ### ## # " | ||
|
||
for j in 0..9 | ||
for i in 0..9 | ||
# use input record seperator $/ instead of "\n" | ||
# see http://ruby.runpaint.org/globals | ||
a.addstr $m[ w(j) * 5 + w(i) ].chr + ( i > 8 ? $/ : "" ) | ||
end | ||
end | ||
|
||
$x = $y = 2 | ||
|
||
# draw tile | ||
def d( t = "@" ) | ||
$a.setpos $y, $x | ||
$a.addstr t | ||
end | ||
|
||
# move player | ||
def m( x, y ) | ||
# 32 is the character code for a whitespace | ||
$x, $y = x,y if $m[ w(y) * 5 + w(x) ] == 32 | ||
end | ||
|
||
s = a.init_screen | ||
a.noecho | ||
a.curs_set 0 | ||
# use 1 instead of TRUE | ||
s.keypad 1 | ||
d | ||
|
||
until ( c = s.getch ) == ?q | ||
# use character codes instead of KEY_UP, KEY_DOWN etc. | ||
k = { 259 => [$x, $y - 1], | ||
258 => [$x, $y + 1], | ||
260 => [$x - 1, $y], | ||
261 => [$x + 1, $y] } | ||
d " " | ||
m *k[c] if k[c] | ||
d | ||
end |