1

So i am making a random map generator in QBasic for Battlefield 3.

The idea is, whenether i run the program, the program should print a map name from already predefined strings. The code i have so far is:

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    

Lets say the random NUM is 22.

It checks if NUM is bigger than 10 and prints A$, because 22 > 10. It does the same for B$. When it comes to C$, the program breaks as NUM is not > 30. Thats normal. The problem is that i get more than one map name. I get a few. Reffer to the picture:

http://i.stack.imgur.com/TTnXQ.png

I want only one string based of the random number.

How do i break the code from going to the next line? Is there a simpler way of pulling random strings?

Like i run the program and it pulls a random string out of the A$, B$, C$ etc.

Cheers :)

4

2 回答 2

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$
于 2014-07-19T13:42:06.240 回答
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)
于 2018-05-29T05:04:12.790 回答