Weekly Qbasic and Qb64 Lesson Topics
April 19, 2024, 09:25:30 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Better sample, of a text adventure

Pages: [1]
  Print  
Author Topic: Better sample, of a text adventure  (Read 1974 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« on: March 24, 2012, 12:13:49 am »

The entire code dose not fit, however the sample, in qb64/samples/qb64/original/temple.bas
 temple.bas is the  game, it compiled and runs in qb64 just fine, and is a good example,
of a text adventure, I selected the, no graphics, so it was "pure"text, I have not tried using the graphics option.
Code:
 DIM SHARED X AS INTEGER
DIM SHARED Y AS INTEGER
10 'KEY OFF
15 N = VAL(MID$(TIME$, 7, 2))
20 RANDOMIZE N
30 INPUT "Do you want graphics (Y/N)"; ANS$
40 IF ANS$ = "y" GOTO 70
50 IF ANS$ = "Y" GOTO 70
55 IF ANS$ = "ZORK" GOTO 700
60 GOTO 350
70 SCREEN 1: CLS '///this causes it to change to screen 1, which is small ,try various 'screen modes to see what they do.
 
As you can see it uses a lot of GOTO there are over 5000 gotos in the entire program, the above code cannot work at this time, because some of the GOTO numbers are not there, it is just to show what he (the author starts with), I am trying to do some mods, to this short piece, to make a "snippet" that works, but it will take me awhile. from Garry
« Last Edit: March 24, 2012, 08:24:25 am by GarrisonRicketson » Report Spam   Logged

Share on Facebook Share on Twitter

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #1 on: March 24, 2012, 08:15:08 am »

Ok, here I have modified, the above snippet, so it dose works, it dose not do much, but it is a start,
Code:
 DIM SHARED X AS INTEGER
DIM SHARED Y AS INTEGER
10 'KEY OFF
15 N = VAL(MID$(TIME$, 7, 2))
1 PRINT "be sure to use upper case when you enter a command"
INPUT "To continue type C "; ANS$
IF ANS$ = "C" GOTO 30
20 RANDOMIZE N
30 INPUT "Do you want graphics (Y/N)"; ANS$
40 IF ANS$ = "y" GOTO 70
50 IF ANS$ = "Y" GOTO 70
55 IF ANS$ = "ZORK" GOTO 700
60 GOTO 350
70 SCREEN 1: CLS'//This can be changed. Try various screen modes,and see what they do.
PRINT " Sorry no graphics yet"
PLAY "ga"
SLEEP 2
CLS
INPUT "Do you want to be ZORK(Y/N"; ANS$
IF ANS$ = "Y" GOTO 350
IF ANS$ = "N" GOTO 1
GOTO 1
700 PRINT "ZORK" '///modified by me so it works.
PRINT "ZORK is  the character, could be zork or anyone"
SLEEP 2
GOTO 350
350 PRINT "this is 350" 'mod by me to make it work.
PRINT " 350 could be where the first part of the story is,some instructions"
PRINT " and or "
PRINT " this is where we add more options,also. "
PLAY "eeaagbd"
SLEEP 2
GOTO 1
 
There was some discussion on this forum, and I have seen on others, about using  ,some say it is not good , and I have read that, there can be problems if not used correctly,..I will try to add a link to those discussions, later, or simpley ,ha! goto the wiki, do a key word search on goto.
GOTO
GOTO

On the line where it  says SCREEN 1: CLS that makes the screen change to a small screen, see this, (mostly screen 13)
 http://qb64.net/wiki/index.php?title=Graphics_with_QB64

 On the line where it  says SCREEN 1: CLS that makes the screen change to a small screen, see this, (mostly screen 13)
 http://qb64.net/wiki/index.php?title=Graphics_with_QB64
or,
SCREEN
 Feel free to add on and modify this snippet,, also if it dose not work on your computer/OS, but it should.
 from Garry
« Last Edit: March 24, 2012, 09:35:14 am by GarrisonRicketson » Report Spam   Logged

Axlyon
official TAD aficionado
Newbie
*
Posts: 6


Machiner of the e!


« Reply #2 on: March 24, 2012, 11:28:41 am »

thanks. i will try this
Report Spam   Logged

"Do or do not, there is no try"
Yoda in: Star Wars V The Empire Strikes Back
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #3 on: March 24, 2012, 06:55:56 pm »

It took some searching, but I found this, it had been posted a long time by a guy named dusty,
Not exactly a console, but a menu of sorts,...Hope this is not to much to fast, but anyway, it is good code, and works, but can be modified too, I noticed your comment in the other thread, about "tedious", and slow, Yes it can be , especially when one dose not know enough code to just write something from scratch, or to make the mods needed to adapt something to suit your needs. Actually I found 2 "scripts" , so I will put the other in a reply. Here is the Menu (template),
Code:
DIM SHARED Llist$(10)
DIM SHARED Sel AS INTEGER

SCREEN 12

FOR x = 1 TO 10 '---- Get the Menu List - Only needs done once
    READ Llist$(x)
NEXT x

MakeMenu '---- Show the Menu

'----------------

DO
    '--- Moving down Menu
    IF _KEYDOWN(20480) THEN
        COLOR 0, 7 ' --- Erase last move
        LOCATE Sel, 25: PRINT Llist$(Sel - 5)

        Sel = Sel + 1: IF Sel > 15 THEN Sel = 6
        COLOR 0, 8 ' --- Show present move going down
        LOCATE Sel, 25: PRINT Llist$(Sel - 5)
    END IF

    ' --- Moving up the Menu
    IF _KEYDOWN(18432) THEN
        COLOR 0, 7 ' --- Erase last move
        LOCATE Sel, 25: PRINT Llist$(Sel - 5)

        Sel = Sel - 1: IF Sel < 6 THEN Sel = 15
        COLOR 0, 8 ' ---  Show present move going up the Menu
        LOCATE Sel, 25: PRINT Llist$(Sel - 5)
    END IF

    a$ = INKEY$
    IF a$ = CHR$(13) THEN '--- press ENTER to select
        Selection Sel ' ---  Goto Selected item
    END IF


    IF LCASE$(a$) = "q" THEN EXIT DO ' --- end Program

    _DISPLAY
    _LIMIT 8 ' --- set speed of selecter, change if selecter goes to fast or slow. Large number = faster
LOOP

SYSTEM

'-------------- Change these suit your needs in the menu ----------------
DATA "Math","Draw Circle","Draw Box","Enter Name","Paste","Clear","Cut","Find","New","Run"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' _____________________ Sub Selection _________________________________
SUB Selection (Sel)
GotoRoutine = Sel - 5


' NOTE:  cases 1 to 3 are calling subs. I didn't use subs in Cases  4 to 10
'            You can choose to do it either way but subs seperate from the rest
'            so its easier to edit later on and makes the programs more clear.

SELECT CASE GotoRoutine

    CASE 1
        Math ' --- Call sub math

    CASE 2
        DrawCircle ' --- Call sub DrawCircle

    CASE 3
        Drawbox ' --- Call sub Drawbox

    CASE 4

        COLOR 0, 7: CLS: LOCATE 10, 20
        INPUT "What is your name?"; n$,
        LOCATE 12, 20: PRINT "Hello "; n$; " Press a key to go to menu"
        _DISPLAY
        SLEEP 'wait for keypress to leave sub
        DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

    CASE 5
        COLOR 0, 7: CLS: LOCATE 10, 20
        PRINT "you selected Option 'PASTE', Press a key to go to menu";
        _DISPLAY
        SLEEP 'wait for keypress to leave sub
        DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

    CASE 6
        COLOR 0, 7: CLS: LOCATE 10, 20
        PRINT "you selected Option Clear, Press a key to go to menu";
        _DISPLAY
        SLEEP 'wait for keypress to leave sub
        DO: LOOP UNTIL INKEY$ = "" '  clear the keyboard after SLEEP statement

    CASE 7
        COLOR 0, 7: CLS: LOCATE 10, 20
        PRINT "you selected Option 'CUT', Press a key to go to menu";
        _DISPLAY
        SLEEP 'wait for keypress to leave sub
        DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

    CASE 8
        COLOR 0, 7: CLS: LOCATE 10, 20
        PRINT "you selected Option 'FIND', Press a key to go to menu";
        _DISPLAY
        SLEEP 'wait for keypress to leave sub
        DO: LOOP UNTIL INKEY$ = "" '  clear the keyboard after SLEEP statement

    CASE 9
        COLOR 0, 7: CLS: LOCATE 10, 20
        PRINT "you selected Option 'NEW', Press a key to go to menu";
        _DISPLAY
        SLEEP 'wait for keypress to leave sub
        DO: LOOP UNTIL INKEY$ = "" '  clear the keyboard after SLEEP statement

    CASE 10
        COLOR 0, 7: CLS: LOCATE 10, 20
        PRINT "you selected Option 'RUN', Press a key to go to menu";
        _DISPLAY
        SLEEP 'wait for keypress to leave sub
        DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

END SELECT

MakeMenu '-------- Go back to the menu
END SUB

' _______________________ Sub Draw Circle _________________________________
SUB DrawCircle

COLOR 0, 7: CLS '------- Clear the screen of the menu
CIRCLE (300, 100), 50, 4
LOCATE 14, 20
PRINT " we are drawing circles"
LOCATE 16, 20
PRINT " Press a key to go back to main menu"

_DISPLAY ' -- show the circle and text

SLEEP 'wait for keypress to leave sub
DO: LOOP UNTIL INKEY$ = "" '  clear the keyboard after SLEEP statement

END SUB

'_______________________ Sub Draw Box_________________________________
SUB Drawbox

COLOR 0, 7: CLS ' ------- Clear the screen of the menu
LINE (200, 100)-(400, 150), 4, BF
LINE (200, 100)-(400, 150), 0, B
LOCATE 14, 20
PRINT " we are drawing boxes"
LOCATE 16, 20
PRINT " Press a key to go back to main menu"

_DISPLAY ' --- show the box and text

SLEEP 'wait for keypress to leave sub
DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

END SUB
'______________________ Sub Math _____________________________________
SUB Math

COLOR 0, 7: CLS ' ------- Clear the screen of the menu
LOCATE 10, 16
PRINT " we are doing math now:  9 X 6 = 54"
LOCATE 12, 10
PRINT " Put your Multiplication tables in this Sub Routine 'Math'"
LOCATE 16, 18
PRINT "Press a key to go back to the main menu"
_DISPLAY ' ------- Show the text

SLEEP
DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

END SUB

'_________________ Sub Make the Menu ________________________
SUB MakeMenu
Sel = 6 ' --- Start location for selecter

COLOR 0, 7: CLS
FOR x = 5 TO 15 ' ---  Print the Menu list
    LOCATE x, 25
    PRINT Llist$(x - 5)
NEXT x

LOCATE 20, 10
PRINT "Use up/Down arrow keys - Press Enter to make selection";
LOCATE 22, 20: PRINT " Press q to exit";
COLOR 0, 8: LOCATE Sel, 25
PRINT Llist$(Sel - 5)
_DISPLAY

END SUB
 
In this he (Dusty bear), also comments the code real well, so it is helpful in understanding what is going on, and what can be done.
from Garry
Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #4 on: March 24, 2012, 07:02:15 pm »

This is the other "snippet", but I tried modifying part, and got frustrated,..you may or may not find it of use,not sure,..
Code:
   SCREEN 12
COLOR , 7
CLS
a$ = "THIS IS The New text adventure, So the story begins..."


' Center the text

' Since this text will be 8 pixels per chr we divide screen width
' by 16 to find text center.
xx = _WIDTH / 16

'Then subtract center value from length a$ / 2
xx = INT(xx - LEN(a$) / 2)

FOR x = xx TO LEN(a$) + xx
    c = INT(RND * 6) + 1
    COLOR c ' --- set color for each character
    b = b + 1 ' --- Select next character to be printed
    LOCATE 15, x
    PRINT MID$(a$, b, 1); ' --- Do the print centered

    _DELAY .2 ' Slow it down a bit
NEXT x
CLS
SCREEN 13 '///Notice the change in the screen,....
PRINT " I think , then more subs can be added "
SLEEP 1
PRINT "Like this"
'//// I will see if it works this way.

 
I think one could add to this and make it get interesting.
« Last Edit: March 24, 2012, 07:22:23 pm by GarrisonRicketson » Report Spam   Logged


Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy