basic - 如何在 commodore 64 basic 中分隔字符串?

标签 basic c64 commodore

我在 commodore 64 中初始化了一 block “.”板。

我想随机将单词放入板中,单词的每个字母都是“.”在棋盘上(如单词搜索游戏)。如果单词不适合,则可以放置下一个单词。我想垂直和水平放置单词。这是我到目前为止所拥有的:(这使得点板为 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

现在我需要把单词放在网格中

有什么想法吗?

最佳答案

MID$ 字符串函数

另一个重要的功能是MID$。此函数选择为其参数提供的任何字符串的一部分。

输入命令:

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

结果向您展示了 MID$ 的工作原理。在这种情况下,它显示一个 4 个字符的字符串,从“ABCDEFG”的第二个字符开始。

在形式上,MID$ 函数采用三个参数,这些参数用逗号分隔并括在方括号中。参数如下 如下:

  • 第一个是要使用的字符串。
  • 第二个是指定第一个字符位置的数字 在结果中。
  • 第三个是给出结果长度的另一个数字。

如您所料,任何参数都可以是适当类型的变量。结果的长度可以是从 0(称为 null 字符串)到第一个参数的全长之间的任何值。在实践中,它通常是一个字符。

这是一个简单的程序,用于输入一个单词并向后显示它。仔细研究它并注意函数 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 个或更多字符的单词。

关于basic - 如何在 commodore 64 basic 中分隔字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22596561/

相关文章:

basic - 在 QuickBasic 中打开使用 BSAVE 创建的文件?

基本打印 LIN(2)

assembly - 比较击键 - assembly CCS64

c64 - 为什么总是设置 53280 $D020 的高位 (c64)

function - Commodore 64 BASIC 中的多行功能

mysql - Visual Basic 连接 MySQL 语法错误

kotlin - 在Kotlin中具有等效功能的Visual Basic

xcode - Xcode 中的 C64 开发?

coordinate-transformation - 打印出屏幕任意位置的字母

assembly - C64 程序集渲染 Sprite