Programmeren voor beginners

Cursussen, tutorials
Plaats hier uw bijdrage.

Programmeren voor beginners

Berichtdoor Gordon » zo jan 28, 2007 11:37 pm

Hier is de listing van CAMEL.BAS
Echt een programma met PRINT INPUT RND() GOTO GOSUB en IF THEN

Code: Selecteer alles
CLS
PRINT "CAMEL"
PRINT "";:INPUT "DO YOU NEED INSTRUCTIONS ";I$
IF LEFT$(I$,1)="N" or LEFT$(I$,1)="n" THEN CLS :GOTO [Display]

CLS :PRINT "              CAMEL":PRINT
PRINT"   WELCOME TO CAMEL.  THE OBJECT IS TO TRAVEL"
PRINT"200 MILES ACROSS THE GREAT GOBI DESERT."
PRINT"A TRIBE OF KNOCK-KNEED PYGMEES WILL BE CHASING YOU."
PRINT"YOU WILL BE ASKED FOR COMMANDS EVERY SO OFTEN."
PRINT
PRINT"   YOU HAVE ONE QUART OF WATER WHICH WILL LAST YOU SIX DRINKS."
PRINT"YOU MAY RENEW YOUR WATER SUPPLY COMPLETELY AT AN OASIS."
PRINT"YOU GET A HALF A QUART IF FOUND BY HELP."
PRINT"IF HELP DOES NOT FIND YOU AFTER COMMAND SIX, YOU LOSE."

[start]
PRINT"GOOD LUCK AND GOOD CAMELING !!" :PRINT
INPUT "PRESS ANY KEY TO CONTINUE ";I1$
IF LEN(I1$)>0 THEN CLS

[Display]
PRINT"1. DRINK FROM CANTEEN             4. STOP FOR THE NIGHT"
PRINT"2. AHEAD MODERATE SPEED           5. STATUS CHECK"
PRINT"3. AHEAD FULL SPEED               6. HOPE FOR HELP"
PRINT:PRINT"YOU ARE IN THE MIDDLE OF THE DESERT AT AN OASIS."
GOSUB [init]

[CheckFinish]
IF C>199 THEN GOTO [winner]

[health]
Z=Z-1
IF Z=1 THEN PRINT"------------WARNING-----------GET A DRINK"
IF Z<0 THEN GOTO [NoWater]
P=P+1 :X2=INT(10*RND(0)+2.5)
IF Q>0 THEN GOTO [SandStorm]
IF P<4 THEN GOTO [Pygmee]
C1=C1+X2:IF C1<C THEN GOTO [travel]
PRINT"THE PYGMEES HAVE CAPTURED YOU.  CAMEL AND PEOPLE SOUP IS"
PRINT"THEIR FAVORITE DISH!!!!!"
GOTO [NewGame]


[travel]
PRINT"THE PYGMEES ARE ";C-C1; " MILES BEHIND YOU."
[Pygmee]
PRINT"YOU HAVE TRAVELLED "; C; " MILES ALTOGETHER."

[command]
PRINT"WHAT IS YOUR COMMAND ";
INPUT Y
PRINT

SELECT CASE Y
    CASE 1
    GOTO [Drink]
    CASE 2
    GOTO [moderateSpeed]
    CASE 3
    GOTO [FullSpeed]
    CASE 4
    GOTO [Sleep]
    CASE 5
    GOTO [StatusCheck]
    END SELECT

    T=INT(10*RND(0))
    IF T<>1 THEN
        GOTO [died]
    ELSE
        PRINT"HELP HAS FOUND YOU IN A STATE OF UNCONSCIOUSNESS. "
        S=3:Z=4
        GOTO [CheckFinish]
    END IF

[moderateSpeed]
F=F+1
IF F=8 THEN GOTO [Figs]
GOSUB [bebers]
X1=INT(10*RND(0))
C=C+X1
PRINT"YOUR CAMEL LIKES THIS PLACE. "
GOTO [CheckFinish]

[FullSpeed]
F=F+3
IF F>7 THEN GOTO [Figs]
GOSUB [bebers]
X1=2*INT(10*RND(0))
C=C+X1
PRINT"YOUR CAMEL IS BURNING ACROSS THE DESERT SANDS."
GOTO [CheckFinish]

[Sleep]
PRINT"YOUR CAMEL THANKS YOU!!" :F=0
GOTO [health]

[StatusCheck]
PRINT"YOUR CAMEL HAS ";7-F;" GOOD DAYS LEFT."
PRINT"YOU HAVE ";S;" DRINKS LEFT IN YOUR CANTEEN."
PRINT"YOU CAN GO ";Z; " COMMANDS WITHOUT DRINKING."

[Drink]
S=S-1:IF S<0 THEN GOTO [died]
PRINT"BETTER WATCH FOR AN OASIS!!":Z=4
GOTO [command]

[bebers]
A=INT(100*RND(0)):IF A>5 THEN GOTO [oase]
PRINT"WILD BERBERS HIDDEN IN THE SAND HAVE CAPTURED YOU."
PRINT"LUCKILY THE LOCAL SHEIK HAS AGREED TO THEIR RANSOM-"
PRINT"DEMANDS..........BUT.......WATCH FOR THE PYGMEES!!!"
PRINT"YOU HAVE A NEW CHOICE OF SUB-COMMANDS:"
PRINT
PRINT"7. -ATTEMPT AN ESCAPE"
PRINT"8. -WAIT FOR PAYMENT"
PRINT"YOUR SUB-COMMAND ";
INPUT X
    IF X=8 THEN
        GOTO [payment]
    ELSE
        X1=INT(10*RND(0))
        IF X1<5 THEN
        GOTO [wounded]
        END IF
    PRINT"CONGRATULATIONS, YOU SUCCESSFULLY ESCAPED!!!!"
    Q=0
    GOTO [CheckFinish]
    END IF

[wounded]
    PRINT"YOU WERE MORTALLY WOUNDED BY A PYG STABBER WHILE ESCAPING."
    GOTO [died]

[payment]
    X1=INT(100*RND(0))
    IF X1>24 THEN
        PRINT"THE LOCAL SULTAN IS COLLECTING.......JUST WAIT........."
        GOTO [CheckFinish]
    ELSE
        PRINT"YOUR RANSOM HAS BEEN PAID AND YOU ARE FREE TO GO."
        Q=0
        GOTO [CheckFinish]
    END IF

[oase]
    A=INT(10*RND(0))
    IF A>2 THEN
        GOTO [SandStorm]
    ELSE
        PRINT"YOU HAVE ARRIVED AT AN OASIS-----------YOUR CAMEL IS"
        PRINT"FILLING YOUR CANTEEN AND EATING FIGS."
        Z=4
        S=6
    END IF
    RETURN

[Figs]
PRINT"YOU DIRTY RAPSCALLION! YOU RAN YOUR CAMEL TO DEATH!!"
GOTO [died]

[winner]
    PRINT"YOU WIN, A PARTY IS BEING GIVEN IN YOUR HONOR........"
    PRINT"......THE PYGMEES ARE PLANNING TO ATTEND......."
    GOTO [NewGame]

[SandStorm]
    X1=INT(100*RND(0))
    IF X1>5 THEN
        GOTO [HumpHurt]
    ELSE
        PRINT"YOU HAVE BEEN CAUGHT IN A SANDSTORM......GOOD LUCK!!"
        X5=INT(10*RND(0))
        X6=INT(10*RND(0))
        IF X6<5 THEN
            GOTO [NewPosition]
        END IF
    C=C+X5
    GOTO [NewPos1]
    END IF

[NewPosition]
    C=C-X5
[NewPos1]
    PRINT"YOUR NEW POSITION IS "; C;" MILES SO FAR!"
    RETURN

[HumpHurt]
    X1=INT(100*RND(0))
    IF X1>5 THEN RETURN
    C1=C1+1
    PRINT"YOUR CAMEL HURT HIS HUMP."
    PRINT"LUCKILY THE PYGMEES WERE FOOTWEARY !!!"
    RETURN


[died]
    U=INT(10*RND(0))
        PRINT"YOU DIED IN THE DESERT."
            IF U>1 THEN GOTO [lost1]
            PRINT"THE NATIONAL CAMEL'S UNION IS NOT ATTENDING YOUR FUNERAL!!!"
            GOTO [NewGame]
            [lost1]
            IF U>3 THEN GOTO [lost2]
            PRINT"YOUR BODY WAS EATEN BY VULTURES AND IMPORTED CANNIBALS!!!"
            GOTO [NewGame]
            [lost2]
            IF U>5 THEN GOTO [lost3]
            PRINT"THE LOCAL SHEIK NOW USES YOUR SKULL FOR A CHANGE PURSE!!!"
            GOTO [NewGame]
            [lost3]
            IF U>7 THEN GOTO [lost4]
            PRINT"PEOPLE WITH LITTLE INTELLIGENCE SHOULD STAY OUT OF THE DESERT"
            GOTO [NewGame]
            [lost4]
            PRINT"TURKEYS SHOULD FLY, NOT RIDE CAMELS!!!!!!!"

[NewGame]
            PRINT"WANT A NEW CAMEL AND A NEW GAME ";
            INPUT D$
            IF LEFT$(D$,1)="Y" or LEFT$(D$,1)="y" THEN
                CLS :GOTO [start]
            ELSE
                GOTO [chicken]
            END IF

[NoWater]
            PRINT"YOU RAN OUT OF WATER.........SORRY CHUM!!!"
            GOTO [died]

[chicken]
            PRINT"-----------------"
            PRINT"      CHICKEN"
            PRINT"-----------------"
            END

[init]
            Z=4:S=6:C=0:C1=0:Q=0:F=0:P=0
            RETURN



Veel plezier en voorzichtig met je Kameel.

Gordon
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am

Keer terug naar Leren programmeren met Liberty BASIC

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron