• Print

Author Topic: I require assistance once again my friends.  (Read 241 times)

therealdavetaylor

  • Newbie
  • *
  • Posts: 22
  • Qbasic for life.
    • Email
I require assistance once again my friends.
« on: March 17, 2013, 06:30:03 PM »
Hi, it is I Therealdavetaylor once again needing help.
I'm trying to program a text version of Outlaw. The game
that I love for the Atari 2600. You are an honest horse
farmer going up against the notorious horse thief
Black Bart. I'm trying to keep it under 50 lines of code.
So I have everything done except for I'm having trouble
trying to program the code to repeat to the beginning
of the game. Here is what I have so far. Please don't
judge.  ;)

--------------------------------------------------------------------------------

PRINT "What can really be said about using violence to solve a problem?"
PRINT "Nothing really can be said when someone takes the law into"
PRINT "thier own hands..."
PRINT ""
PRINT "The date is August 14th 1872."
PRINT "The place, Drumheller."
PRINT "The time, Noon, high noon."
PRINT ""
PRINT "Now you and the town have had enough. Black Bart must be put"
PRINT "to rest. You have taken your paces, with you're pistol on hip, you"
PRINT "have only one shot. So make it count and bring peace to this"
PRINT "quite one horse town."
PRINT ""
PRINT "Press any key..."
DO: LOOP UNTIL INKEY$ <> ""

GOSUB 10
10 DO
    20 CLS
    30 PRINT "===================="
    40 PRINT "I      Outlaw      I"
    50 PRINT "I    Written by    I"
    60 PRINT "I    D.B. Taylor   I"
    70 PRINT "===================="
80 LOOP

90 REM
100 DEFINT A-Z

110 PRINT "You tightly grip the handle of you're six shooter..."
120 INPUT Word$
130 IF UCASE$(Word$) = "FIRE" THEN
    140 RANDOMIZE TIMER
    150 z% = INT(RND * 2) + 1
    160 IF z% = 1 THEN PRINT "You got'em. All is " ELSE PRINT "You missed. Black Bart laughs as the town is lost forever."
170 END IF

GOSUB 110

How come I'm the only person I know who writes text adventures in basic???

therealdavetaylor

  • Newbie
  • *
  • Posts: 22
  • Qbasic for life.
    • Email
Re: I require assistance once again my friends.
« Reply #1 on: March 17, 2013, 07:18:28 PM »
By the way this is just a small test program for a larger one that I am planning on making in a few weeks.
How come I'm the only person I know who writes text adventures in basic???

therealdavetaylor

  • Newbie
  • *
  • Posts: 22
  • Qbasic for life.
    • Email
Re: I require assistance once again my friends.
« Reply #2 on: March 17, 2013, 07:26:12 PM »
Also i'm using the random code that OlDosLover wrote. I'm just trying to work with and figure it out.
How come I'm the only person I know who writes text adventures in basic???

OlDosLover

  • Hero Member
  • *****
  • Posts: 3944
  • OlDosLover
    • Email
Re: I require assistance once again my friends.
« Reply #3 on: March 17, 2013, 08:04:14 PM »
Hi all,
    It's a good effort Dave! One little problem is this endless loop:
Quote
10 DO
    20 CLS
    30 PRINT "===================="
    40 PRINT "I      Outlaw      I"
    50 PRINT "I    Written by    I"
    60 PRINT "I    D.B. Taylor   I"
    70 PRINT "===================="
80 LOOP
    I changed it  to this and it now continues onward:
Quote
10 DO
  20 CLS
  30 PRINT "===================="
  40 PRINT "I      Outlaw      I"
  50 PRINT "I    Written by    I"
  60 PRINT "I    D.B. Taylor   I"
  70 PRINT "===================="
80 LOOP WHILE INKEY$ = ""

    The way your code is written it seems to me that you cleared the keyboard buffer so that the title would always be readable and need to exit by a keypress.

    Some explanations of this:
Quote
130 IF UCASE$(Word$) = "FIRE" THEN
  140 RANDOMIZE TIMER
  150 z% = INT(RND * 2) + 1
  160 IF z% = 1 THEN PRINT "You got'em. All is " ELSE PRINT "You missed. Black Bart laughs as the town is lost forever."
170 END IF
1] If  CONDITION  then  ACTION  end if.
If the user entry is the exact word then we do the THEN part, else it is ignored. It makes sense to add the 3 inner lines as they depend upon the condition being TRUE to to have them be run.
2] 140 RANDOMIZE TIMER
Seeds the random number generator off of the timer else you will get a continually repeatable start.
3] 150 z% = INT(RND * 2) + 1
Simply produces two numbers , either 1 or 2. Could be written many ways to give a different range like 0 or 1 , or 3 or 4 , etc.
4] 160 IF z% = 1 THEN PRINT "You got'em. All is " ELSE PRINT "You missed. Black Bart laughs as the town is lost forever."
Simply writes one of two possible messages depending upon if the condition is TRUE or FALSE.

Code: [Select]
REM
DEFINT A-Z

a% =0
RANDOMIZE TIMER
DO
  z% = INT(RND * 2) + 1
  PRINT z%,
  a% = a% +1
LOOP WHILE a% < 100
    Will demonstrate the distribution sequence of the two numbers. Everytime you run it it will be different. Rem out the RANDOMIZE TIMER and it will be repeatable meaning it will output the same sequence every time.
OlDosLover.

OlDosLover

  • Hero Member
  • *****
  • Posts: 3944
  • OlDosLover
    • Email
Re: I require assistance once again my friends.
« Reply #4 on: March 18, 2013, 12:11:00 AM »
Hi all,
    Here's another way to structure your program Dave. The idea is that each standalone chunk has its own section. Some sections can be reused many times which saves on program size and excess typing. The only real alteration to your program that i made was to have a master loop that exits the program with the escape key.
Code: [Select]
REM
DEFINT A-Z

GOSUB IntroText
GOSUB ClearKeyBuffer
GOSUB ShowTitle
GOSUB AwaitAKey

DO
  _LIMIT 30
  GOSUB GetResponse
  _DISPLAY
LOOP UNTIL INKEY$ = CHR$(27)
CLS
PRINT "Program Ended, press a key"
SLEEP
SYSTEM

'------------------------- GOSUBS ------------------------------
IntroText:
PRINT "What can really be said about using violence to solve a problem?"
PRINT "Nothing really can be said when someone takes the law into"
PRINT "thier own hands..."
PRINT ""
PRINT "The date is August 14th 1872."
PRINT "The place, Drumheller."
PRINT "The time, Noon, high noon."
PRINT ""
PRINT "Now you and the town have had enough. Black Bart must be put"
PRINT "to rest. You have taken your paces, with you're pistol on hip, you"
PRINT "have only one shot. So make it count and bring peace to this"
PRINT "quite one horse town."
PRINT ""
PRINT "Press any key..."
RETURN

ClearKeyBuffer:
DO: LOOP UNTIL INKEY$ <> ""
RETURN

ShowTitle:
CLS
PRINT "===================="
PRINT "I      Outlaw      I"
PRINT "I    Written by    I"
PRINT "I    D.B. Taylor   I"
PRINT "===================="
RETURN

AwaitAKey:
DO
LOOP WHILE INKEY$ = ""
RETURN

GetResponse:
PRINT "You tightly grip the handle of you're six shooter..."
INPUT Word$
IF UCASE$(Word$) = "FIRE" THEN
  RANDOMIZE TIMER
  z% = INT(RND * 2) + 1
  IF z% = 1 THEN PRINT "You got'em. All is " ELSE PRINT "You missed. Black Bart laughs as the town is lost forever."
END IF
RETURN
OlDosLover.

therealdavetaylor

  • Newbie
  • *
  • Posts: 22
  • Qbasic for life.
    • Email
Re: I require assistance once again my friends.
« Reply #5 on: March 18, 2013, 07:13:58 PM »
Greeting's and salutations,

I am truly thankful for you helping me out on this problem that I've trying to battle with for the past few days.
OlDosLover, thank you for taking the time in going through my code and helping me solve the elusive "How
to repeat the code?" Haha. Thank you my friend  :) 
How come I'm the only person I know who writes text adventures in basic???

OlDosLover

  • Hero Member
  • *****
  • Posts: 3944
  • OlDosLover
    • Email
Re: I require assistance once again my friends.
« Reply #6 on: March 19, 2013, 01:25:56 AM »
Hi all,
    No problem it was a pleasure to assist you. feel free to email me (little envelope under my name) if you need more help.
OlDosLover.

therealdavetaylor

  • Newbie
  • *
  • Posts: 22
  • Qbasic for life.
    • Email
Re: I require assistance once again my friends.
« Reply #7 on: March 19, 2013, 01:44:07 PM »
Thank you for all the help. And I will call upon you're aid once again  8)
How come I'm the only person I know who writes text adventures in basic???

  • Print