所以我在战地3的QBasic中制作了一个随机地图生成器。
我的想法是,当我运行程序时,程序应该从已经预定义的字符串中打印一个地图名称。我到目前为止的代码是:
CLS
REM --------------------- RANDOM NUMBER VALUE --------------------------
RANDOMIZE TIMER: A = INT((RND * 100)): B = INT((RND * 10)): C = (A + B)
NUM = INT(C - (RND * 10))
REM --------------------------- MAPS - -------------------------------
A$ = "Caspian Border"
B$ = "Damavant Peak"
C$ = "Grand Bazaar"
D$ = "Kharg Island"
E$ = "Norshar Canals"
F$ = "Operation Firestorm"
G$ = "Operation Metro"
H$ = "Seine Corssing"
I$ = "Tehran Highway"
REM ----------------------------- GAME MODE ----------------------------
RSH$ = "Rush"
TDM$ = "Team Deathmatch"
CQS$ = "Conquest"
CQSL$ = "Conquest Large"
SQDM$ = "Squad Deathmatch"
REM --------------------------- PLAYER COUNT -----------------------------
AA$ = "16 Players"
BB$ = "32 Players"
CC$ = "64 Players"
REM ------------------------ PROCESSING CODE ----------------------------
PRINT "Bore-o-mat 3000 Initilaized"
PRINT "The random number is"; NUM; "therfore the map drawn is:"
IF NUM > 10 THEN PRINT A$
IF NUM > 20 THEN PRINT B$
IF NUM > 30 THEN PRINT C$
IF NUM > 40 THEN PRINT D$
IF NUM > 50 THEN PRINT E$
IF NUM > 60 THEN PRINT F$
IF NUM > 70 THEN PRINT G$
IF NUM > 80 THEN PRINT H$
IF NUM > 90 THEN PRINT I$
END
让我们说随机NUM是22。
检查NUM是否大于10并打印A $,因为22> 10. B $也是如此。当谈到C $时,程序会因为NUM不是>而中断。这是正常的。问题是我得到了多个地图名称。我得到了一些。回到图片:
http://i.stack.imgur.com/TTnXQ.png
我只想要一个基于随机数的字符串。
如何打破代码进入下一行? 是否有更简单的方法来拉随机字符串?
就像我运行程序一样,它会从A $,B $,C $等中随机抽出一个字符串。
干杯:)
答案 0 :(得分:2)
你应该把字符串放在一个数组中。否则,这是一个快速修复。
IF NUM >= 10 AND NUM < 20 THEN PRINT A$
IF NUM >= 20 AND NUM < 30 THEN PRINT B$
IF NUM >= 30 AND NUM < 40 THEN PRINT C$
IF NUM >= 40 AND NUM < 50 THEN PRINT D$
IF NUM >= 50 AND NUM < 60 THEN PRINT E$
IF NUM >= 60 AND NUM < 70 THEN PRINT F$
IF NUM >= 70 AND NUM < 80 THEN PRINT G$
IF NUM >= 80 AND NUM < 90 THEN PRINT H$
IF NUM >= 90 AND NUM < 100 THEN PRINT I$
答案 1 :(得分:0)
您可以将它们放入数组中,然后随机选择一个:
A$(1) = "Caspian Border"
A$(2) = "Damavant Peak"
A$(3) = "Grand Bazaar"
A$(4) = "Kharg Island"
A$(5) = "Norshar Canals"
A$(6) = "Operation Firestorm"
A$(7) = "Operation Metro"
A$(8) = "Seine Corssing"
A$(9) = "Tehran Highway"
Num = INT(RND * 9 + 1)
PRINT A$(Num)