Your game works fine for me when I enter:
attack
next
attack
However, the way you wrote it is very picky. If I don't type that exactly (if I type it in all caps ATTACK
or attack
with a space at the end), it won't match the if-statement and it'll fall through.
You can force the input to lowercase and trim any spaces with:
INPUT co$
co$ = RTRIM$(LTRIM$(LCASE$(co$)))
This will let you accept a weird input like " aTTaCK "
.
Second, it looks like when you run away, the monster is supposed to eat you. Is that your intention? If so, then there's nothing in place to stop it from falling to the next line of code.
6 IF co$ = "attack" GOTO 7 ELSE GOTO 9
7 PRINT "you kill'd the monster"
8 INPUT n$
9 IF n$ = "next" THEN 11
10 PRINT "the monster ate you. Have a fun time in his belly!"
11 PRINT "You won a potion!!!"
On line 10, after the monster eats you, you can either: add another GOTO
statement to jump to another part of the program, or END
the program. Here's an example to END
the program afterward:
6 IF co$ = "attack" GOTO 7 ELSE GOTO 9
7 PRINT "you kill'd the monster"
8 INPUT n$
9 IF n$ = "next" THEN 11
10 PRINT "the monster ate you. Have a fun time in his belly!": END
11 PRINT "You won a potion!!!"
Lastly, in Qbasic, you don't need to enter numbers for each line. That's a nightmare to maintain and bugs like this will keep popping up because they're hard to catch when you write code this way. You can make it easier on yourself by using labels instead. Here's you code with the line numbers removed and replaced with labels (for the GOTO statements):
PRINT "welcome to the dungeon, " + name$ + "!"
PRINT "monster!!! attack or run away"
INPUT co$
IF co$ = "attack" GOTO 7 ELSE GOTO 9
7:
PRINT "you kill'd the monster"
INPUT n$
9:
IF n$ = "next" THEN 11
PRINT "the monster ate you. Have a fun time in his belly!"
END
11:
PRINT "You won a potion!!!"
PRINT "uh oh! You found a dragon"
PRINT "Use the potion, attack or run away"
INPUT com$
IF com$ = "attack" GOTO 18
IF com$ = "use potion" THEN 19 ELSE PRINT "fried human for mr dragon!!!"
18:
PRINT "bye bye dragon"
19:
PRINT "the dragon got to sleep and you got to get away"
You can also use letters for labels, and form descriptive names. Such as:
IF co$ = "attack" GOTO KillMonster ELSE GOTO RunAway
KillMonster:
PRINT "you kill'd the monster"
INPUT n$
RunAway:
IF n$ = "next" THEN GOTO WonPotion:
PRINT "the monster ate you. Have a fun time in his belly!"
END
WonPotion:
PRINT "You won a potion!!!"
The easier it is to read your code, the easier it is to understand and see problems. You'll also have more fun.