Hello! Novice programmer teaching middle school students. Have spent three weeks teaching my students how to program in Javascript(Rhino), and would love to finish out our unit with some cheesy little games, but I can't figure out how to make any kind of active keyboard listener work in that language. Rerouting to a different flavor of javascript would be a little hard on them. Any Rhino masters out there? Goal is simple console games like below but that the user can interact with using WASD keys Thanks in advance!
importPackage(java.io);
importPackage(java.lang);
var screen = [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]
var x
var y
var z
function setPosition(x, y, z)
{
screen[8-y][x+1]=z
}
function clear()
{
var i
var j
for(i=1; i<9; i++)
{
for(j=1; j<29; j++)
{
screen[i][j]=" "
}
}
}
function draw()
{
var k
for (k = 0; k<10; k++)
{
System.out.println(screen[k])
}
}
function sendBorders()
{
var i
var j
for(i=0; i<10; i++)
{
for(j=0; j<30; j++)
{
if (((i==0) && (j==0)) || ((i==9) && (j==29)))
{
screen[i][j]="/"
}
if (((i==9) && (j==0)) || ((i==0) && (j==29)))
{
screen[i][j]="\\"
}
if (((i==0) || (i==9)) && ((j>0) && (j<29)))
{
screen[i][j]="-"
}
if (((j==0) || (j==29)) && ((i>0) && (i<9)))
{
screen[i][j]="|"
}
}
}
}
clear()
sendBorders()
var t
for(t=0; t<60; t++)
{
right = Math.floor(t/(60/27))
up = Math.floor(-(1/130)*((t-30)*(t-30))+7)
clear()
setPosition(right,up,"X")
Thread.sleep(50)
System.out.print("\033[H\033[2J")
draw()
}