home *** CD-ROM | disk | FTP | other *** search
- /*=============================*/
- /* "Solitaire" game for ARexx */
- /* © 1996 John Filsak */
- /*=============================*/
-
- /* Set up some constants */
- /* ===================== */
- esc='1b'x
- cr='a'x
- cls='c'x
- blackon=esc'[31m'
- whiteon=esc'[32m'
- blueon=esc'[33m'
- normal=esc'[0m'
- boldon=esc'[1m'
- boldoff=esc'[22m'
- wback=esc'[42m'
- bback=esc'[43m'
- gback=esc'[40m'
- blob='¤'
-
- call open(win,'raw:100/100/400/239/Solitaire ©1996 John Filsak')
- signal on break_c
-
- /*================*/
- /* Main game loop */
- /*================*/
-
- gameover=0
- do until gameover=1
- call makegrid()
- stoppit=0
- do until stoppit=1
- call moveit()
- end
- if upper(choice(normal||cr||cr||cr" Would you like to play again? "))="N" then gameover=1
- end
- call ending
- exit
-
- /*=============*/
- /* Subroutines */
- /*=============*/
-
- /* Cursor movement etc */
- /*=====================*/
- moveit:
- ans=readch(win,1)
- /*The arrow keys generate a control character (155)
- plus the letters A-D. The control character is
- apparently ignored, and ARexx happily deals with
- the movement letter*/
-
- select
- when ans="A" then do
- select
- when lft>=lft1 & lft<=lft1+4 & top>top1 then do
- top=top-1
- square=square-7
- end
- when (lft<lft1 | lft>lft1+4) & top>top2 then do
- top=top-1
- square=square-7
- end
- otherwise nop
- end
- call cpos(top,lft,"")
- end
- when ans="B" then do
- select
- when lft>=lft1 & lft<=lft1+4 & top<top1+6 then do
- top=top+1
- square=square+7
- end
- when (lft<lft1 | lft>lft1+4) & top<top2+2 then do
- top=top+1
- square=square+7
- end
- otherwise nop
- end
- call cpos(top,lft,"")
- end
- when ans="C" then do
- select
- when top>=top1 & top<=top1+1 & lft<lft1+4 then do
- lft=lft+2
- square=square+1
- end
- when top>=top2 & top<=top2+2 & lft<lft2+12 then do
- lft=lft+2
- square=square+1
- end
- when top>top2 & lft<lft1+4 then do
- lft=lft+2
- square=square+1
- end
- otherwise nop
- end
- call cpos(top,lft,"")
- end
- when ans="D" then do
- select
- when top>=top1 & top<=top1+1 & lft>lft1 then do
- lft=lft-2
- square=square-1
- end
- when top>=top2 & top<=top2+2 & lft>lft2 then do
- lft=lft-2
- square=square-1
- end
- when top>top2 & lft>lft1 then do
- lft=lft-2
- square=square-1
- end
- otherwise nop
- end
- call cpos(top,lft,"")
- end
- /* Jump over peg */
- /*===============*/
- when ans="8" then do
- sq2=square-14;sq1=square-7
- if square>12 & square.square=1 & square.sq1=1 & square.sq2=0 then do
- call cpos(top,lft,"·")
- square.square=0
- top=top-2
- call cpos(top+1,lft,"·")
- square=square-14
- call hkeep()
- end
- end
- when ans="2" then do
- sq2=square+14;sq1=square+7
- if square<34 & square.square=1 & square.sq1=1 & square.sq2=0 then do
- call cpos(top,lft,"·")
- square.square=0
- top=top+2
- call cpos(top-1,lft,"·")
- square=square+14
- call hkeep()
- end
- end
- when ans="4" then do
- sq2=square-2;sq1=square-1
- if (square<22 | square>23 & square<29 | square>30) & square.square=1 & square.sq1=1 & square.sq2=0 then do
- call cpos(top,lft,"·")
- square.square=0
- lft=lft-4
- call cpos(top,lft+2,"·")
- square=square-2
- call hkeep()
- end
- end
- when ans="6" then do
- sq2=square+2;sq1=square+1
- if (square<20 | square>21 & square<27 | square>28) & square.square=1 & square.sq1=1 & square.sq2=0 then do
- call cpos(top,lft,"·")
- square.square=0
- lft=lft+4
- call cpos(top,lft-2,"·")
- square=square+2
- call hkeep()
- end
- end
- when upper(ans)="Q" then do
- stoppit=1
- call title()
- call writech(win,cr cr" GAME STOPPED!"cr cr)
- end
- otherwise nop
- end
- if count=1 then do
- stoppit=1
- call writech(win,normal)
- do a=3 to 16
- call cpos(a,2,copies(" ",27))
- end
- if square.25=1 then do
- call cpos(5,2,whiteon||boldon||bback" CONGRATULATIONS!! "gback||cr)
- call writech(win,blackon||cr" You have completed"cr)
- call writech(win," the game!"cr)
- end
- else do
- call cpos(5,2,whiteon||boldon||bback" WRONG!! "gback||cr)
- call writech(win,normal||cr" Your're supposed to finish"cr)
- call writech(win," in the middle!"cr)
- call writech(win,cr||blueon||boldon" Better luck next time!"cr)
- end
- call writech(win,cr||cr||normal" Press a key ...")
- call readch(win,1)
- end
- return
-
- /* Housekeeping for
- jump routines */
- /*==================*/
- hkeep:
- square.sq1=0
- square.square=1
- count=count-1
- call counter()
- call cpos(top,lft,blob)
- call cpos(top,lft,"")
- return
-
- counter:
- call cpos(13,lft2+3,gback||blackon||normal||count-1" to go "blueon||boldon||wback)
- return
-
- /* Make game grid */
- /*================*/
- makegrid:
- call title()
- if game~=1 then do
- call writech(win,normal||cr||cr||cr" This is the traditional game of jumping over"cr)
- call writech(win," and removing pegs, with the aim of having"cr)
- call writech(win," just one left in the middle of the board."cr)
- call writech(win,cr||cr||boldon||whiteon||" Press any key to start."normal)
- call readch(win,1)
- game=1
- call title()
- end
- call writech(win,cr||cr||normal" Use the "boldon||whiteon"arrow keys"normal" to move"cr)
- call writech(win," the cursor to your desired"cr)
- call writech(win," peg."cr)
- call writech(win,cr" Use keys on the numeric pad"cr)
- call writech(win," to jump:"cr)
- call writech(win,boldon||whiteon||cr" 8 - UP"cr" 2 - DOWN"cr" 4 - LEFT"cr" 6 - RIGHT"cr)
- call writech(win,normal||cr" Q - QUIT"boldon||wback||blueon)
-
- do a=1 to 49
- square.a=1
- end
- square.25=0
- square=25
- count=32
- top=5;top1=top;top2=top+2
- lft=37;lft1=lft;lft2=lft-4
-
- do a=1 to 2
- do b=0 to 4 by 2
- call cpos(top,lft+b,blob" ")
- if b=0 then call cpos(top,lft-1," ")
- end
- top=top+1
- end
- do a=1 to 3
- do b=0 to 12 by 2
- call cpos(top,lft2+b,blob" ")
- if b=0 then call cpos(top,lft2-1," ")
- end
- top=top+1
- end
- do a=1 to 2
- do b=0 to 4 by 2
- call cpos(top,lft+b,blob" ")
- if b=0 then call cpos(top,lft-1," ")
- end
- top=top+1
- end
- top=top-4;lft=lft+2
- call counter()
- call cpos(top,lft,"·")
- call cpos(top,lft,"")
- return
-
- /* Get Y/N input */
- /* ============= */
- choice:
- parse arg text
- yn=""
- do until upper(yn)='Y'|upper(yn)='N'
- call writech(win,text)
- yn=readch(win,1)
- call writech(win,yn cr)
- if upper(yn)~='Y'&upper(yn)~='N'then call writeln(win," Please type Y or N.")
- end
- return yn
-
- /* Position cursor */
- /* =============== */
- cpos:
- parse arg row,col,text
- call Writech(win,'9b'x||row'3B'x||col'48'x||text)
- return
-
- /* Clear screen */
- /* ============ */
- title:
- call writech(win,cls)
- call cpos(1,18,boldon||wback||blackon" SOLITAIRE "gback)
- return
-
- /* Closing courtesies */
- /* ================== */
- ending:
- call title()
- ending1:
- call writeln(win,cr||cr||cr" Thank you for playing Solitaire."cr)
- call writeln(win,blueon||boldon" Solitaire was written for your enjoyment by")
- call writech(win,blackon" John Filsak. ")
- do a=1 to 3750;end
- call close(win)
- return
-
- /* Trap Ctrl-C */
- /* =========== */
- break_c:
- call title()
- call writeln(win,cr||cr||blackon" PROGRAM HALTED!"normal)
- call ending1()
- exit
-