Need help with my Text adventure

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
winger5150
Newbie
Posts: 2
Joined: Sat Nov 18, 2006 1:22 pm

Need help with my Text adventure

Post by winger5150 »

Hi guys (and gals if there are any),

I'm a new member here, and new to QBasic and indeed any programming. I downloaded QBASIC last weekend...dunno why really it just sparked nostalgia for the day in computer science when I used to write silly programs like

DO
PRINT "MR. CARNE IS A *insert explitive""
LOOP

That was about the extent of my skills.......anyway so I downloaded it and a tutorial and I've started coding a simple text adventure. No parser or anything just a kind of Press A to do this or B to do that etc.

Now I've just included a baddie for the player to fight...only thing is I can't work out how to make it work.

What I would like to do is have it so the player has to score 3 or above to hit the baddie (which I can do using INT(RND) ) and then the baddie would lose a HP. Then I want the baddie to attack and for it to go back and forth until the baddie loses all his HP and then dies (or the player dies)...........but I can't get it to work, I can't get the player and baddie to attack in turn and I can't get the computer to remember the loss of hitpoints.......

Can anyone offer me help, I don't need a full example (though that would be nice) just advice on what commands I need to use or is it a case that what I'm trying to do is one of those things that seems simple but actually isn't?

Also at the moment because of my limits the game code is very long, lots of IF...THEN,SELECT CASE and GOTO/GOSUB going on.....should I continue doing this little game or is it a wasted exercise?

Cheers
Ben
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

There's no such thing as a wasted exercise.

You need variables, someone else will explain it further I'm sure.
I have left this dump.
winger5150
Newbie
Posts: 2
Joined: Sat Nov 18, 2006 1:22 pm

Post by winger5150 »

Hmmmm...ok obviously no one wants to help further so I'll take your advice and go do some research on using variables.

Thanks for your encouragement Z!re though regarding the validity of even doing this little bit of programming! Shame nobody else feels like helping...I guess I broke some unwritten rule of asking for help or something.
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post by bungytheworm »

As Z1re told, nothing is as wasted exercise. Even the silliest programs are good for learning.
Give us some code you got and we help you :)
D.S
Coder
Posts: 38
Joined: Wed Sep 14, 2005 7:37 am

Post by D.S »

Firstly, you didn't break any unwritten rule by asking for help, but it is a little hard to respond if you don't post any code along with your problem. Just FYI for next time ;). Secondly, tutorials are a good way to get information, but from my experience, having an example to look at helps you to understand them a lot more. Try this.

Code: Select all

begin:
playerhealth = 10
monsterhealth = 10
color 4
print "A monster has attacked you!"
color 1
print "(F)ight, or (R)un?"
do ' begin a loop
k$ = inkey$ ' let k$ = the key the user presses.
if k$ = "r" or k$ = "R" then end ' run away!
if k$ = "f" or k$ = "F" then goto fight ' charge!
loop ' end the loop

fight:
cls ' clear screen
color 15
do ' another loop
print "Player attacks!"
playerattack = int(rnd * 10) 

if playerattack >= 3 then ' if >= 3, takes 1 away from monster's health
print "Monster is hit!"
monsterhealth = monsterhealth - 1
end if

if playerattack < 3 then print "Player misses!"

do ' a loop inside a loop
k$ = inkey$
loop until k$ <> "" ' waits until the player presses a key

' monster's attack

print "Monster attacks!"
monsterattack = int(rnd * 10)

if monsterattack >= 3 then
print "Player is hit!"
playerhealth = playerhealth - 1
end if

if monsterattack < 3 then print "Monster misses!"

do ' a loop inside a loop
k$ = inkey$
loop until k$ <> "" ' waits until the player presses a key

cls ' clear screen again


' print health stuff
print "Player:" ;playerhealth
print "Monster:" ; monsterhealth
if monsterhealth = 0 then print "You win!": end
if playerhealth = 0 then print "You lose!": end

loop
If you get your hands on a couple of beginner tutorials, you should be able to understand everything in this code, and mold it for your own needs.
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 »

yes keep going its a good thing to try....once you get your first
program done you'll feel better and understand more no matter
what the program is...simple is better for your first program....

the example above is very good for you...but try to
modify it once you get it done so you can see
what does what afterwords...
dragonz
Newbie
Posts: 4
Joined: Wed Nov 29, 2006 8:45 pm
Location: east lansing, mi

thank god

Post by dragonz »

Thank you I had the same question and I have been beating my head on this desk for like 3 hours trying to get a simple battle to run and I have had no end of trouble and was about to check the flight potential of my pc and or shoot myself.
D.S wrote:Firstly, you didn't break any unwritten rule by asking for help, but it is a little hard to respond if you don't post any code along with your problem. Just FYI for next time ;). Secondly, tutorials are a good way to get information, but from my experience, having an example to look at helps you to understand them a lot more. Try this.

Code: Select all

begin:
playerhealth = 10
monsterhealth = 10
color 4
print "A monster has attacked you!"
color 1
print "(F)ight, or (R)un?"
do ' begin a loop
k$ = inkey$ ' let k$ = the key the user presses.
if k$ = "r" or k$ = "R" then end ' run away!
if k$ = "f" or k$ = "F" then goto fight ' charge!
loop ' end the loop

fight:
cls ' clear screen
color 15
do ' another loop
print "Player attacks!"
playerattack = int(rnd * 10) 

if playerattack >= 3 then ' if >= 3, takes 1 away from monster's health
print "Monster is hit!"
monsterhealth = monsterhealth - 1
end if

if playerattack <3>= 3 then
print "Player is hit!"
playerhealth = playerhealth - 1
end if

if monsterattack < 3 then print "Monster misses!"

do ' a loop inside a loop
k$ = inkey$
loop until k$ <> "" ' waits until the player presses a key

cls ' clear screen again


' print health stuff
print "Player:" ;playerhealth
print "Monster:" ; monsterhealth
if monsterhealth = 0 then print "You win!": end
if playerhealth = 0 then print "You lose!": end

loop
If you get your hands on a couple of beginner tutorials, you should be able to understand everything in this code, and mold it for your own needs.
________
260 D
Post Reply