home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
sourcecode
/
games
/
wordpuzsolve.amos
/
wordpuzsolve.amosSourceCode
< prev
Wrap
AMOS Source Code
|
1990-10-26
|
9KB
|
317 lines
Rem WORDSQUARE SOLVER AMIGA
Rem By Jeff Tullin
Rem (c) 1990
Screen Open 0,320,300,16,Lowres
Curs Off : Cls 0 : Hide
'
Dim A$(900)
Global HEIGHT,WIDTH,A$(),I$,MK,FLAG,STRT,WORD$,FOUND,QUIT$
'
DISPLAY
Repeat
EMPTYARRAY
QUERYSIZE
MAINSCREEN
LETTERENTRY
WORDENTRY
Until QUIT$="N"
End
'
Procedure DISPLAY
Unpack 1 To 1
Palette ,,,$F80
Wait Key
Appear 0 To 1,109
Screen Close 1
Double Buffer
Autoback 0
End Proc
Procedure EMPTYARRAY
For X=0 To 900 : A$(X)="." : Next
A$(899)="@"
End Proc
'
Procedure QUERYSIZE
' ( double buffer needed to stop screen flicker)
Screen Swap : Curs Off
Cls 0 : Pen 2 : Paper 9
Locate 0,2 : Centre "Please select the size of the"
Locate 0,4 : Centre "wordsquare by moving the sliders"
Locate 0,6 : Centre "with the mouse.."
Pen 5 : Paper 0
Locate 0,10 : Centre "* CLICK HERE WHEN READY *"
Pen 2
Locate 4,15 : Centre " Chars across= Chars Down= "
Reserve Zone 3
' set up zones for mouse in sliders & exit box
Set Zone 1,0,175 To 297,195
Set Zone 2,0,0 To 20,174
Set Zone 3,50,75 To 260,95
Ink 2 : Box 50,75 To 260,95
Set Slider 0,2,4,11,2,2,8,11
HSLIDE[9]
VSLIDE[9]
' now show the people what we've done...
Screen Copy Logic To Physic
Show
' keep reading sliders until exit is selected.
Repeat
SREAD
Until Mouse Zone=3 and Mouse Key
Ink 5 : Box 50,75 To 260,95
' flash box around exit text
Bell 45
Screen Swap : Wait 10
End Proc
'
Procedure SREAD
Rem: checks for mouse key in sliders, and redraws to suit
XM=X Screen(X Mouse)
YM=Y Screen(Y Mouse)
MK=Mouse Key
While Mouse Zone=1
MK=Mouse Key
X=X Screen(X Mouse)
If X<>XM and MK=1 Then HSLIDE[X/9] : XM=X
Screen Copy Logic To Physic
Wend
While Mouse Zone=2
MK=Mouse Key
Y=Y Screen(Y Mouse)
If Y<>YM and MK=1 Then VSLIDE[Y/10] : YM=Y
Screen Copy Logic To Physic
Wend
End Proc[X]
Procedure HSLIDE[X]
Hslider 0,180 To 297,190,33,X,1
Locate 17,15 : Print X+3;" "; : WIDTH=X+3
End Proc
Procedure VSLIDE[Y]
Vslider 0,0 To 10,174,17,Y,1
Locate 32,15 : Print Y+3;" "; : HEIGHT=Y+3
End Proc
'
Procedure MAINSCREEN
' create main grid
Cls
Cls 7,11,11 To((WIDTH+3)*8+3),((HEIGHT+3)*8+3)
Cls 2,8,8 To(WIDTH+3)*8,(HEIGHT+3)*8
Ink 4
Box 10,10 To(WIDTH+3)*8-2,(HEIGHT+3)*8-2
Set Zone 2,17,17 To(WIDTH+2)*8-1,(HEIGHT+2)*8-1
End Proc
Procedure LETTERENTRY
' create main menu box
Cls 7,62,184 To 254,198
Cls 4,60,181 To 252,196
Ink 2 : Box 62,182 To 249,193
Set Zone 1,62,182 To 249,193
Pen 2
Paper 4
Locate 8,23
Print " Please enter letters:"
Paper 6 : Pen 7
' reset creates initial grid full of spots
RESET
Screen Swap
Screen Copy Physic To Logic
Autoback 0
' now get the letters to fill the grid..
Repeat
ACCEPTLETTERS
Until FLAG=0
End Proc
Procedure ACCEPTLETTERS
' FLAG is a once only signal to print 'click here..'
If FLAG=0
Pen 2 : Paper 7
Locate 8,23 : Print " CLICK HERE WHEN READY ";
Pen 7 : Paper 6
FLAG=1
End If
'
' grid begins at 2,2
XPOS=2 : YPOS=2
Curs On
Locate XPOS,YPOS
Repeat
I$=Inkey$
I$=Upper$(I$)
' only letters of A to Z acceptable
If Asc(I$)>64 and Asc(I$)<91
A$((XPOS-2)+(YPOS-2)*WIDTH)=I$
' keep variable space down by garbage collection
DUMMY=Free
Print I$;
Add XPOS,1,2 To WIDTH+1
If XPOS=2
Add YPOS,1,2 To HEIGHT+1
End If
Locate XPOS,YPOS
Screen Copy Logic To Physic
End If
' read mouse, and reposition cursor to suit
While Mouse Zone=2 and Mouse Key=1
XPOS=X Screen(X Mouse)/8
YPOS=Y Screen(Y Mouse)/8
Locate XPOS,YPOS
Screen Swap
Screen Copy Physic To Logic
Wend
Until Mouse Zone=1 and Mouse Key=1
FLAG=0
End Proc
Procedure WORDENTRY
Curs Off
' add reset box at this point
Cls 7,14,184 To 61,198
Cls 5,12,181 To 59,196
Ink 0 : Box 13,182 To 57,193
Set Zone 2,13,182 To 56,193
Locate 2,23 : Paper 0 : Pen 2
Print "RESET";
' and add quit box
Cls 7,255,184 To 302,198
Cls 5,253,181 To 300,196
Ink 0 : Box 254,182 To 297,193
Set Zone 3,254,182 To 297,193
Locate 32,23 : Print "QUIT!";
Paper 2 : Pen 0
Locate 8,23 : Print " Enter 'hidden' word "
Screen Copy Logic To Physic
'
' make sure that mouse button not pressed at this point
Repeat : Until Mouse Key=0
Repeat
If Mouse Zone=2 and Mouse Key
Bell 40
Ink 2 : Box 13,182 To 57,193
Screen Swap
RESET
Paper 2 : Pen 0
End If
'
If(Mouse Zone=1 and Mouse Key)
Ink 0 : Box 62,182 To 249,193
Screen Swap : Bell 45 : Wait 5
LIMINPUT[19,8,23]
WORD$=Param$
If Len(WORD$)>2
SEEK
Paper 2 : Pen 0
Locate 8,23 : Print " Enter 'hidden' word "
Screen Copy Logic To Physic
End If
End If
Until Mouse Zone=3 and Mouse Key=1
Ink 2 : Box 254,182 To 297,193
Screen Swap : Bell 48 : Wait 5
Locate 8,23 : Pen 3 : Print " ANOTHER GRID? (Y/N) "
Screen Swap
Repeat : QUIT$=Upper$(Inkey$)
Until(QUIT$="Y") or(QUIT$="N")
End Proc
Procedure RESET
' clear all letters to original colour
Pen 7 : Paper 6
For H=1 To HEIGHT
Locate 2,H+1
For W=1 To WIDTH
Print A$(W-1+((H-1)*WIDTH));
Next
Next
Locate 2,2
Screen Swap
Screen Copy Physic To Logic
End Proc
Procedure LIMINPUT[CHARS,X,Y]
' accept CHARS characters at location X,Y
Hide
Repeat : Until Inkey$=""
A$=Space$(23) : Locate X,Y : Centre A$ : Centre "?"
LTH=0
Repeat
I$=Upper$(Inkey$)
If(I$=>"A") and(I$<="Z")
Locate X,Y : Curs On
If LTH<CHARS
Add LTH,1 : Mid$(A$,LTH,1)=I$
Else
Bell
End If
End If
If Scancode=65 and LTH<>0
Add LTH,-1
End If
If LTH<>0
Locate 0,Y : Centre(" "+Left$(A$,LTH)+" "+Chr$(8))
End If
Screen Copy Logic To Physic
Until I$=Chr$(13) and LTH>2 : Curs Off : Show
End Proc[Left$(A$,LTH)]
Procedure SEEK
' check each letter until 1st letter of Word$ matches
FOUND=False
For STRT=0 To(WIDTH*HEIGHT)
If Left$(WORD$,1)=A$(STRT)
CHECK_WHOLE_WORD
End If
If FOUND
STRT=900
End If
Next
End Proc
Procedure CHECK_WHOLE_WORD
' search in all eight compass directions
SEARCH[0,1]
If Not FOUND
SEARCH[WIDTH,1]
End If
If Not FOUND
SEARCH[WIDTH,0]
End If
If Not FOUND
SEARCH[WIDTH,-1]
End If
If Not FOUND
SEARCH[0,-1]
End If
If Not FOUND
SEARCH[-WIDTH,-1]
End If
If Not FOUND
SEARCH[-WIDTH,0]
End If
If Not FOUND
SEARCH[-WIDTH,1]
End If
End Proc
Procedure SEARCH[HDIR,WDIR]
' start at 2nd letter of word$, check letter by letter
' in direction HDIR and WDIR as vectors
NXT=STRT
FOUND=True
For X=2 To Len(WORD$)
NXT=NXT+HDIR+WDIR
If NXT<0 or NXT>(WIDTH*HEIGHT)
NXT=899
End If
If A$(NXT)<>Mid$(WORD$,X,1)
FOUND=False : X=255
End If
Next X
'
If FOUND
HILITE[HDIR,WDIR]
End If
End Proc
Procedure HILITE[HDIR,WDIR]
' turn 'found' word white to show it up
Pen 2 : Paper 6
STRT=STRT-(HDIR+WDIR)
For X=1 To Len(WORD$)
Add STRT,(HDIR+WDIR)
Locate(2+(STRT mod WIDTH)),(2+(STRT/WIDTH)) : Print A$(STRT);
Next X
Pen 0 : Paper 2
End Proc