![PoGa 4DGL Reference Manual Download Page 11](http://html1.mh-extra.com/html/poga/4dgl/4dgl_reference-manual_1570571011.webp)
Portable Game Console
PoGa-4DGL Reference Manual
And now the main function.
func main()
var i, j, xp, yp, xn, yn, newgame;
SEED(peekB(SYSTEM_TIMER_LO)) ;
newgame := 1 ;
while(1)
if (newgame == 1)
for(i := 0; i < 16; i++) // randomise sliders
SWAP(&posn[i],&posn[ABS(RAND() % 16)]) ;
next
for(i := 0; i < TileNY; i++) // draw screen
for(j := 0; j < TileNX; j++)
if (posn[i*j] == 15)
gfx_RectangleFilled(j*TileSX,i*TileSY,(j+1)*TileSX-1,(i+1)*TileSY-
1,BLACK);
yp := i ;
xp := j ;
else
pokeB(TEXT_XMAG,3) ;
pokeB(TEXT_YMAG,3) ;
gfx_MoveTo(j*TileSX, i*TileSY) ;
print([CHR] chars[posn[i*j]]);
endif
next
next
newgame := 0 ;
endif
yn := yp ;
xn := xp ;
while((i := joystick()) == 0) ; // read the joystick value
pause(200) ;
if ((i == UP) && (yp != 0)) // move slider if within bounds
yn := yp -1 ;
else if ((i == DOWN) && (yp != TileNY-1))
yn := yp +1 ;
else if ((i == RIGHT) && (xp != TileNX-1))
xn := xp +1;
else if ((i == LEFT) && (xp != 0))
xn := xp -1;
endif
if ((yn != yp) || (xn != xp)) // if sucessful move, reorder board
gfx_RectangleFilled(xn*TileSX,yn*TileSY,(xn+1)*TileSX-1,(yn+1)*TileSY-1,BLACK) ;
gfx_MoveTo(xp*TileSX, yp*TileSY) ;
pokeB(TEXT_XMAG,3) ;
pokeB(TEXT_YMAG,3) ;
print([CHR] chars[posn[yn*xn]]);
SWAP(&posn[yn*xn],&posn[yp*xp]) ;
yp := yn ;
xp := xn ;
endif
j := 0 ; // check for everything in correct order
for(i := 0; i < 16; i++)
if (i != posn[i]) j := 1 ;
next
if (j == 0) // yep, game over
gfx_MoveTo(xp*TileSX, yp*TileSY) ;
pokeB(TEXT_XMAG,3) ;
pokeB(TEXT_YMAG,3) ;
print([CHR] chars[15]);
beep(20,1000) ;
pause(1000) ; // wait for beep to end
newgame := 1 ;
endif
wend
endfunc
Now compile and download this, saving it as TextTiler.
© 2011 4D Systems
www.4dsystems.com.au
Page 11 of 87