CONST TRUE
= -1, FALSE
= NOT TRUE
, DOWN
= 1, UP
= 2
Columndata:
WordsList:
DATA BASIC
,APPLE
,PEACH
,COMPUTER
,TRICYCLE
DATA TORNADO
,GARBAGE
,SUNSHINE
,PRETTY
,MEDIA
DATA EXPERIMENT
,TECHNIQUE
,CHALLENGE
,ACTIVE
,SPEECH
DATA TRADITION
,COFFEE
,MEMORY
,STANDING
,ORANGE
DATA DRAMA
,FOUNDATION
,LISTEN
,NATURAL
,WATER
DATA SUPPORT
,TYRANNY
,DINOSAUR
,COBRA
,PUPPY
'Empty the grid field
Grid(c%%, r%%) = ""
GridColor
(c%%
, r%%
) = _RGB32(6, 6, 6)
'load the word list
FOR i%%
= 1 TO Total_Words
'Pick words for current Game
FOR i%%
= 1 TO Words_to_Find
w%%
= INT(RND * Total_Words
) + 1 IF WordList
(w%%
) <> "" THEN Is_Good
= TRUE
ELSE Is_Good
= FALSE
'now Place word in current list
SWAP Words
(i%%
), WordList
(w%%
)
'---------Lets find a place for each word--------
FOR i%%
= 1 TO Words_to_Find
'----Find a Place to start word----
col%%
= INT(RND * Columns
(G.Level
)) + 1 row%%
= INT(RND * (Columns
(G.Level
) \
2)) + 1 IF Grid
(col%%
, row%%
) = "" THEN Is_Good%%
= TRUE
ELSE Is_Good%%
= FALSE
'----------------------------------
'---------Try to Place word--------
It_Works%%=Horz_fit(Grid(),Words(),Col%%,Row%%,I%%,Columns(G.level),G.Allow_Reverse)
It_Works%%=Vert_fit(Grid(),Words(),Col%%,Row%%,I%%,Columns(G.level)/2,G.Allow_Reverse)
It_Works%%=Diag_fit(Grid(),Words(),Col%%,Row%%,I%%,Columns(G.level),G.Allow_Reverse,DOWN)
It_Works%%=Diag_fit(Grid(),Words(),Col%%,Row%%,I%%,Columns(G.level),G.Allow_Reverse,UP)
'----------------------------------
'------------------------------------------------
'-Fill in rest of the space with random letters--
FOR row%%
= 1 TO Columns
(g.level
)/2 FOR col%%
= 1 TO columns
(g.level
) IF Grid
(col%%
, row%%
) = "" THEN '------------------------------------------------
'display the grid!
PrintGrid Columns(G.level)
'CC%%-- Column count (Passed as Columns(G.Level))
PRINT Grid
(col%%
, row%%
);
Function Horz_Fit
(WG$
(),WA$
(),Col%%
,Row%%
,CW%%
,CC%%
,AR%%
) 'WG$()- Word Grid array
'WA$()- Word array
'Col%%- Column of Word Grid
'Row%%- Row of Word Grid
'CW%%-- Current Word array element
'CC%%-- Column count (Passed as Columns(G.Level))
'AR%%-- Allow Reversed word flag(passed as G.Allow_Reverse)
'see if the word will even fit here
WordLength%%
=len(WA$
(cw%%
)) LeftLength%%=CC%%-col%%
if WordLenght%%
<=LeftLength%%
then 'if the word fits
'see if the letters work backwards
for i%%
=0 to WordLength%%
-1 if WG$
(col%%
+i%%
,row%%
)<>"" and WG$
(col%%
+i%%
,row%%
)<>mid$(WA$
(cw%%
),WordLength%%
-i%%
,1) then Failed_Reverse%%
=True:I%%
=WordLength%%
+1:Result%%
=FALSE
else Failed_Reverse%%
=false
'the word will work, write it to grid
Result%%=TRUE 'function will return success
for i%%
=0 to WordLength%%
-1 wg$
(col%%
+i%%
,row%%
)=mid$(Wa$
(CW
),wordlength%%
-i%%
,1) Failed_reverse%%=true 'set due to not using reverse
if Failed_Reverse%%
then 'try going forward for i%%
=0 to wordlength%%
-1 if wg$
(col%%
+i%%
,row%%
)<>"" and wg$
(col%%
+i%%
,row%%
)<>mid$(wa$
(cw%%
),i%%
+1,1) then result%%
=FALSE:I%%
=Wordlength%%
+1 else Result%%
=true
wG$
(col%%
+ i%%
, row%%
) = MID$(wa$
(cw
), i%%
+ 1, 1) Horz_Fit=result%%
Function Vert_Fit
(WG$
(),WA$
(),Col%%
,Row%%
,CW%%
,RC%%
,AR%%
) 'WG$()- Word Grid array
'WA$()- Word array
'Col%%- Column of Word Grid
'Row%%- Row of Word Grid
'CW%%-- Current Word array element
'RC%%-- Row count (Passed as Columns(G.Level)/2)
'AR%%-- Allow Reversed word flag(passed as G.Allow_Reverse)
'see if the word will even fit here
WordLength%%
=len(WA$
(cw%%
)) LeftLength%%=RC%%-Row%%
if WordLenght%%
<=LeftLength%%
then 'if the word fits
'see if the letters work backwards
for i%%
=0 to WordLength%%
-1 if WG$
(col%%
,row%%
+i%%
)<>"" and WG$
(col%%
,row%%
+i%%
)<>mid$(WA$
(cw%%
),WordLength%%
-i%%
,1) then Failed_Reverse%%
=True:I%%
=WordLength%%
+1:Result%%
=FALSE
else Failed_Reverse%%
=false
'the word will work, write it to grid
Result%%=TRUE 'function will return success
for i%%
=0 to WordLength%%
-1 wg$
(col%%
,row%%
+i%%
)=mid$(Wa$
(CW
),wordlength%%
-i%%
,1) Failed_reverse%%=true 'set due to not using reverse
if Failed_Reverse%%
then 'try going forward for i%%
=0 to wordlength%%
-1 if wg$
(col%%
,row%%
+i%%
)<>"" and wg$
(col%%
,row%%
+i%%
)<>mid$(wa$
(cw%%
),i%%
+1,1) then result%%
=FALSE:I%%
=Wordlength%%
+1 else Result%%
=true
wG$
(col%%
, row%%
+i%%
) = MID$(wa$
(cw
), i%%
+ 1, 1) Vert_Fit=result%%
Function Diag_Fit
(WG$
(),WA$
(),Col%%
,Row%%
,CW%%
,CC%%
,AR%%
,D%%
) 'WG$()- Word Grid array
'WA$()- Word array
'Col%%- Column of Word Grid
'Row%%- Row of Word Grid
'CW%%-- Current Word array element
'CC%%-- Column count (Passed as Columns(G.Level))
'AR%%-- Allow Reversed word flag(passed as G.Allow_Reverse)
'D%%--- Direction Flag(1-Down,2-Up)
WordLength%%
=len(WA$
(cw%%
))
'see if the word will even fit here
HorzLeftLen%%=CC%%-col%%
VertLeftLen%%=CC%%/2-row%%
If VertLeftLen%%
>HorzLeftLen%%
then LeftLength%%
=HorzLeftLen%%
else LeftLength%%
=VertLeftLen%%
if WordLenght%%
<=LeftLength%%
then 'if the word fits
'see if the letters work backwards
for i%%
=0 to WordLength%%
-1 if WG$
(col%%
+i%%
,row%%
+i%%
)<>"" and WG$
(col%%
+i%%
,row%%
+i%%
)<>mid$(WA$
(cw%%
),WordLength%%
-i%%
,1) then Failed_Reverse%%
=True:I%%
=WordLength%%
+1:Result%%
=FALSE
else Failed_Reverse%%
=false
'the word will work, write it to grid
Result%%=TRUE 'function will return success
for i%%
=0 to WordLength%%
-1 wg$
(col%%
+i%%
,row%%
+I%%
)=mid$(Wa$
(CW
),wordlength%%
-i%%
,1) Failed_reverse%%=true 'set due to not using reverse
if Failed_Reverse%%
then 'try going forward for i%%
=0 to wordlength%%
-1 if wg$
(col%%
+i%%
,row%%
+1)<>"" and wg$
(col%%
+i%%
,row%%
+1)<>mid$(wa$
(cw%%
),i%%
+1,1) then result%%
=FALSE:I%%
=Wordlength%%
+1 else Result%%
=true
wG$
(col%%
+ i%%
, row%%
+1) = MID$(wa$
(cw
), i%%
+ 1, 1) 'see if the word will even fit here
HorzLeftLen%%=CC%%-col%%
VertLeftLen%%=row%%
If VertLeftLen%%
>HorzLeftLen%%
then LeftLength%%
=HorzLeftLen%%
else LeftLength%%
=VertLeftLen%%
if WordLenght%%
<=LeftLength%%
then 'if the word fits
'see if the letters work backwards
for i%%
=0 to WordLength%%
-1 if WG$
(col%%
+i%%
,row%%
-i%%
)<>"" and WG$
(col%%
+i%%
,row%%
-i%%
)<>mid$(WA$
(cw%%
),WordLength%%
-i%%
,1) then Failed_Reverse%%
=True:I%%
=WordLength%%
+1:Result%%
=FALSE
else Failed_Reverse%%
=false
'the word will work, write it to grid
Result%%=TRUE 'function will return success
for i%%
=0 to WordLength%%
-1 wg$
(col%%
+i%%
,row%%
-I%%
)=mid$(Wa$
(CW
),wordlength%%
-i%%
,1) Failed_reverse%%=true 'set due to not using reverse
if Failed_Reverse%%
then 'try going forward for i%%
=0 to wordlength%%
-1 if wg$
(col%%
+i%%
,row%%
-1)<>"" and wg$
(col%%
+i%%
,row%%
-1)<>mid$(wa$
(cw%%
),i%%
+1,1) then result%%
=FALSE:I%%
=Wordlength%%
+1 else Result%%
=true
wG$
(col%%
+ i%%
, row%%
-1) = MID$(wa$
(cw
), i%%
+ 1, 1)
Diag_Fit=result%%