I have a board of "."s initialized into a board in commodore 64.
I want to randomly place words into the board with each letter of the word being a "." on the board (like a word search game). If the word does not fit, then the next word can be placed. I want to place the words vertically and horizontally. This is what I have so far: (this makes board of dots 10x10)
Any ideas on separating a word (I have the words hard coded) and placing them vertically and horizontally on the screen?
1060 rem: Subroutine Fill
1070 rem: Purpose: read and data construct which fills b3$(x,x) with
1080 rem: either "."s or other random words depending on whether or not
1090 rem: the subroutine has been run before.
1100 x = 10
1110 rem: x represents the dimension for the board; in this case, 10
1120 rem: took out dim b3$(x, x)
1130 rem: array b3 = board = specifications for width and height (10)
1140 rem: i to x allows the horizontal aspect of board to be filled with "."s
1150 for i = 0 to x
1160 rem: j to x allows the vertical aspect of board to be filled with "."s
1170 for j = 0 to x
1180 rem: board filled with dots horizontally and vertically
1190 b3$(i, j) = "."
1200 rem: end of first nested for loop
1210 next
1220 rem: end of second nested for loop
1230 next
1240 return
1400 dim wo$(9)
1410 wo$(0) = "word"
1420 wo$(1) = "stack"
1430 wo$(2) = "overflow"
1440 wo$(3) = "hello"
1450 wo$(4) = "no"
1460 wo$(5) = "how"
1470 wo$(6) = "why"
1480 wo$(7) = "start"
1490 wo$(8) = "end"
1500 wo$(9) = "done"
1510 print wo$(7)
1520 return
10 print "START"
20 rem: go to line 1100 in order to fill board with "."s because this is
30 rem: the board's initialization
40 gosub 1100
50 rem: looping from i to x allows for horizontal aspect of board to be printed
60 rem: x represents the width dimension of board, in this case, 10
70 for i = 0 to x
80 rem: looping from j to x allows for vertical aspect of board to be printed
90 rem: x represents the height dimension of board, in this case, 10
100 for j = 0 to x
110 rem: board initialized with "."s is printed
120 print b3$(i,j),
130 rem: end of first for loop, looping from i to x put on 130; , USED 4 TAB
140 next
150 print
160 rem: end of second for loop, looping from j to x
170 next
180 rem: checks what at the random number is equal to; places word vertically
190 rem: if rand is 0 and places the word horizontally if rand is 1
Now I need to place the words in the grid
Any ideas?
The MID$
String Function
Another vital function is MID$
. This function selects a portion of any string it is given for its argument.
Type the command:
PRINT MID$("ABCOEFG",2,4)
The result shows you how MID$
works. In this case it displays a 4 character string, starting at the 2nd character of "ABCDEFG".
In formal terms, the MID$ function takes three arguments which are separated by commas and enclosed in brackets. The arguments are as follows:
As you would expect, any of the arguments can be variables of the appropriate sort. The length of the result can be anything from 0
(called the null
string) to the full length of the first argument. In practice it is often one character.
Here is a simple program to input a word and display it backwards. Study it carefully and note how the functions LEN
and MID$
are used:
10 INPUT "PLEASE TYPE A WORD"; X$
20 PRINT "YOUR WORD BACKWARD IS"
30 FOR J = LEN(X$) TO 1 STEP - 1
40 PRINT MID$(X$,J, 1);
50 NEXT J
60 STOP
Key the program in and check it for yourself; try out words of 1, 2 or more characters.