如何在Commodore 64 Basic中分离字符串?

3
我已经在Commodore 64的板子上初始化了一个由"."组成的棋盘。我想要随机地将单词放置在这个棋盘上,使得每个单词的每个字母都是棋盘上的一个"."(就像单词搜索游戏一样)。如果单词无法放置,则可以尝试放置下一个单词。我希望能够将单词垂直和水平地放置。目前为止,我的代码可以生成一个10x10的由"."组成的棋盘。请问如何将单词分离(我已经将单词硬编码)并将它们垂直和水平地放置在屏幕上?
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

现在我需要将这些单词放入网格中。
有什么想法?
1个回答

3

MID$字符串函数

另一个重要的函数是MID$。该函数选择任何给定字符串参数的一部分。

输入命令:

PRINT MID$("ABCOEFG",2,4)

结果显示了MID$函数的工作原理。在这种情况下,它显示一个4个字符的字符串,从"ABCDEFG"的第2个字符开始。
正式地说,MID$函数需要三个参数,由逗号分隔并括在括号中。这些参数如下:
- 第一个参数是要使用的字符串。 - 第二个参数是指定结果中第一个字符位置的数字。 - 第三个参数是给出结果的长度的另一个数字。
像预期的那样,任何参数都可以是相应类型的变量。结果的长度可以是从0(称为空字符串)到第一个参数的完整长度的任何值。实际上,通常是一个字符。
以下是一个简单的程序,用于输入一个单词并将其反向显示。仔细研究它,并注意如何使用LENMID$函数:
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  

输入程序并自己检查;尝试使用1、2或更多字符的单词。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接