Author Topic: Welcome to the Playground--DrugWars knockoff  (Read 724 times)

cole1121

  • Newbie
  • *
  • Posts: 14
Welcome to the Playground--DrugWars knockoff
« on: December 18, 2011, 09:36:57 AM »
This is a DrugWars/DopeWars knockoff I came up with.  You're a kid on a playground trying to sell a lot of candy before recess is over.  It's got a good number of features--Increasing debt, potential shakedowns, bust-related price increases, etc.  It can be a lot of fun.

The interface is a bit clunky, but I think I've written out most of the wrong-input-leads-to-shutdown bugs, so you can figure it out if you mess around.  It doesn't have a save high scores function yet; I'll get to that a little later.  There's also a curious quasi-bug:  If you repay your debt in full, then make further payments, your negative debt will increase with interest, giving you crap-tons of money by the end of the game.

Please give the game a try and let me know what you think I can do to make it better.  I know I probably used waaay more code than the game needed, but this is my first "real" program ever ("real" meaning more than a few lines for the sake of an exercise).  I'm looking to get into programming as a more frequent hobby/work option, so I'm looking for feedback.

Thanks, and thanks to the people that make QB64 so awesome and beginner-friendly.

Code: [Select]
DIM jbeans AS SINGLE
DIM goods(6) AS STRING
DIM locations(6) AS STRING
DIM price(6) AS INTEGER
DIM inbackpack(6) AS INTEGER
DIM picknumber(6) AS INTEGER
DIM bust AS INTEGER
DIM bsl AS STRING
DIM buywhat AS INTEGER
DIM howmanyb AS INTEGER
DIM sellwhat AS INTEGER
DIM howmanys AS INTEGER
DIM yourmoney AS INTEGER
DIM location AS INTEGER
DIM daycounter AS INTEGER
DIM debt AS INTEGER
DIM doesntmatter AS STRING
DIM visls AS STRING
DIM paynow AS STRING
DIM paydebt AS INTEGER
DIM endtotal AS INTEGER
DIM playagain AS STRING
DIM instructions AS STRING
DIM minutes AS INTEGER
DIM anothertransaction AS STRING
DIM backpackcapacity AS INTEGER
DIM canafford AS INTEGER
DIM buybackpack AS STRING
DIM bustagain AS INTEGER

PRINT "Press enter to continue..."
SLEEP
INPUT doesntmatter
CLS

SLEEP 1
PRINT "UND"
SLEEP 1
CLS
PRINT ""
PRINT "GROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT "LAYGROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT " "
PRINT "E PLAYGROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " THE PLAYGROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " TO THE PLAYGROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT "OME TO THE PLAYGROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT "ELCOME TO THE PLAYGROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT "  WELCOME TO THE PLAYGROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT "     WELCOME TO THE PLAYGROUND"
SLEEP 1
CLS
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT "Written by anarchronism...Creative Commons 2011 "
PRINT " "
PRINT "        WELCOME TO THE PLAYGROUND"
SLEEP 1
PRINT
400 PRINT "Would you like instructions? (yes or no)"
INPUT instructions
instructions = UCASE$(instructions)

SELECT CASE instructions
    CASE "YES"
        CLS
        PRINT "It's recess time again, and that means lunch is coming up.  Your"
        PRINT "stomach is growling, but it looks like Mom packed you something"
        PRINT "green and leafy...  You're a fourth grader!  You want REAL food!"
        PRINT
        PRINT "You're going to have to wrangle up some lunch money yourself, and"
        PRINT "that means doing what you do best--clandestine playground candy sales!"
        PRINT "You get a loan of 40 pennies from Billy the Bully and you've got until"
        PRINT "recess is over to pay him back with interest, otherwise you'll see"
        PRINT "exactly how he got his name..."
        PRINT
        PRINT "You can visit Billy to make payments on your loan at his hangout"
        PRINT "under the swings any time.  Make sure to keep track of your debt and"
        PRINT "how many minutes of recess have gone by.  Buy and sell by visiting"
        PRINT "different locations and monitoring prices for different goods."
        PRINT
        PRINT "Buy low, sell high, and good luck!"
        PRINT
        PRINT "Press enter to continue..."
        INPUT doesntmatter
        GOTO 300
    CASE "NO"
        CLS
        GOTO 300
    CASE ELSE
        PRINT "Huh?"
        GOTO 400
END SELECT






300

CLS
PRINT "How many minutes(turns) of recess do you want this game to be?"
PRINT
PRINT "5 is hard, 15 is medium, 25 is easy"
PRINT
INPUT minutes
RANDOMIZE TIMER

CLS

backpackcapacity = 25

debt = 50

daycounter = 1

yourmoney = 40

goods(1) = "Jelly beans"
goods(2) = "Lollies"
goods(3) = "Taffiez"
goods(4) = "Chocolatez"
goods(5) = "Cookiez"
goods(6) = "Fudge Popz"

70
PRINT "Choose a location (by number):"
90 PRINT
PRINT "1.  Swings"
PRINT "2.  Slide"
PRINT "3.  Basketball Court"
PRINT "4.  Tire Swing"
PRINT "5.  Monkey Bars"
PRINT "6.  Time Out"
PRINT
INPUT "Location number:"; location

SELECT CASE location
    CASE IS < 1
        CLS
        PRINT "Pick a number, smartass."
        GOTO 90
    CASE IS > 6
        CLS
        PRINT "Pick a number, smartass."
        GOTO 90
    CASE ELSE
        GOTO 150
END SELECT

150
CLS

price(1) = 1 + INT(RND * 15)
10 price(2) = 25 + INT(RND * 45)
IF price(2) > 45 THEN
    GOTO 10
END IF
20 price(3) = 75 + INT(RND * 100)
IF price(3) > 100 THEN
    GOTO 20
END IF
30 price(4) = 90 + INT(RND * 125)
IF price(4) > 125 THEN
    GOTO 30
END IF
40 price(5) = 150 + INT(RND * 225)
IF price(5) > 225 THEN
    GOTO 40
END IF
50 price(6) = 200 + INT(RND * 350)
IF price(6) > 350 THEN
    GOTO 50
END IF

bust = 1 + INT(RND * 100)

IF bust > 10 AND bust < 18 THEN
    CLS
    PRINT "No candy on the playground!"
    PRINT
    PRINT "Principal Hardass caught you selling candy!  She confiscates what she finds!"
    FOR x = 1 TO 6
        inbackpack(x) = inbackpack(x) / 2
    NEXT x
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF

IF bust > 0 AND bust < 9 THEN
    CLS
    PRINT "Hey man, wanna buy a bigger backpack?  *SNIFF*"
    PRINT
    PRINT "Sniffly Tom wants to sell you a backpack that will hold 20 more"
    PRINT "pieces of candy."
    PRINT
    750 PRINT "It'll cost 40 pennies.  Do you accept?(yes or no)"
    INPUT buybackpack
    buybackpack = UCASE$(buybackpack)
    SELECT CASE buybackpack
        CASE "YES"
            IF yourmoney < 40 THEN
                PRINT "You can't afford that."
            END IF
            IF yourmoney >= 40 THEN
                yourmoney = yourmoney - 40
                backpackcapacity = backpackcapacity + 20
                PRINT
                PRINT "Thanks, man! *SNIFF* It'll pay for itself in no time!"
            END IF
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT "Press enter to continue..."
            SLEEP
            INPUT doesntmatter
        CASE "NO"
            CLS
            PRINT "Your loss...*SNIFF*"
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT "Press enter to continue..."
            SLEEP
            INPUT doesntmatter
        CASE ELSE
            PRINT "Huh?"
            GOTO 750
    END SELECT
END IF
IF bust > 49 AND bust < 60 THEN
    price(1) = price(1) + 1 + INT(RND * 20)
    PRINT "Principal Hardass cracked down on jelly beans!  Prices are through"
    PRINT "the roof!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 59 AND bust < 70 THEN
    price(2) = price(2) + 1 + INT(RND * 45)
    PRINT "Teachers are confiscating lollies!  High prices!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 69 AND bust < 80 THEN
    price(3) = price(3) + 1 + INT(RND * 110)
    PRINT "Taffy bust!  Prices are through the roof!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 79 AND bust < 90 THEN
    price(4) = price(4) + 1 + INT(RND * 130)
    PRINT "Chocolate fiends got busted by those asshole teachers!"
    PRINT "Prices are up!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 89 AND bust < 95 THEN
    price(5) = price(5) + 1 + INT(RND * 285)
    PRINT "Cookie bust!  Prices are through the roof!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 30 AND bust < 42 THEN
    price(6) = price(6) + 1 + INT(RND * 500)
    PRINT "They busted the ice cream peddlers!  Fudge popz ain't cheap!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF

IF location = 1 THEN
    price(6) = price(6) + 1 + INT(RND * 150)
    CLS

    120 PRINT "Visit Billy the Bully?"
    INPUT visls
    visls = UCASE$(visls)

    SELECT CASE visls
        CASE "YES"
            CLS
            PRINT "Hey bub, how's the business comin'?"
            PRINT
            PRINT "Looks like you owe me "; debt; " pennies."
            PRINT
            130 PRINT "Pay now? (yes or no)"
            INPUT paynow
            paynow = UCASE$(paynow)

            SELECT CASE paynow
                CASE "YES"
                    CLS
                    PRINT "Good thinkin'.  You don't wanna keep me waitin'."
                    PRINT
                    140 PRINT "How much do you pay?  You owe "; debt
                    INPUT paydebt
                    IF paydebt > yourmoney THEN
                        PRINT "You don't have that much."
                        PRINT
                        GOTO 140
                    END IF
                    yourmoney = yourmoney - paydebt
                    debt = debt - paydebt
                    CLS
                    PRINT "You now owe Billy "; debt; " pennies."

                CASE "NO"
                    CLS
                    PRINT "Fine.  Suit yourself.  We'll meet again, one way or another"
                CASE ELSE
                    GOTO 130
            END SELECT


        CASE "NO"
            CLS
            GOTO 110
        CASE ELSE
            CLS
            GOTO 120
    END SELECT

    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    INPUT doesntmatter
    CLS
END IF

110
IF location = 2 THEN
    price(5) = price(5) - 1 + INT(RND * 50)
END IF
IF location = 3 THEN
    price(4) = price(4) - 1 + INT(RND * 15)
    price(1) = price(1) + 1 + INT(RND * 5)
END IF
IF location = 6 THEN
    bustagain = 1 + INT(RND * 100)
    IF bustagain >= 85 THEN
        CLS
        PRINT "That pompous student teacher caught you selling candy to the"
        PRINT "kids in time out!  She confiscates what she finds!"
        FOR x = 1 TO 6
            inbackpack(x) = inbackpack(x) / 2
        NEXT x
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT "Press enter to continue..."
        SLEEP
        INPUT doesntmatter
    END IF
    price(3) = price(3) + 1 + INT(RND * 100)
    price(4) = price(4) + 1 + INT(RND * 100)
    price(5) = price(5) + 1 + INT(RND * 125)
    price(6) = price(6) + 1 + INT(RND * 150)
END IF



500 CLS
PRINT "You have "; yourmoney; " pennies.", "Minute: "; daycounter, "Debt: "; debt
PRINT
PRINT "For sale:", "Price:", "In backpack:"
PRINT
PRINT "1. J-Beanz", price(1), inbackpack(1)
PRINT "2. Lolliez", price(2), inbackpack(2)
PRINT "3. Taffiez", price(3), inbackpack(3)
PRINT "4. Chocolatez", price(4), inbackpack(4)
PRINT "5. Cookiez", price(5), inbackpack(5)
PRINT "6. Fudge Popz", price(6), inbackpack(6)
PRINT
60 PRINT "Buy, sell, or leave?"
INPUT bsl
bsl = UCASE$(bsl)

SELECT CASE bsl

    CASE "BUY"

        PRINT
        550 PRINT "Buy what? (Choose a number)"
        canafford = 0
        INPUT buywhat
        IF buywhat < 1 OR buywhat > 6 THEN
            PRINT "Huh?"
            GOTO 550
        END IF
        PRINT
        PRINT goods(buywhat); " cost "; price(buywhat); " pennies."
        PRINT
        DO WHILE price(buywhat) * canafford <= yourmoney
            canafford = canafford + 1
        LOOP
        canafford = canafford - 1
        PRINT "You can afford "; canafford; "."
        PRINT
        PRINT "How many?"
        INPUT howmanyb
        PRINT
        CLS
        PRINT howmanyb; goods(buywhat); " cost you "; howmanyb * price(buywhat); " pennies."
        IF howmanyb * price(buywhat) > yourmoney THEN
            PRINT "You can't afford that."
            PRINT
            PRINT "Press enter to continue..."
            SLEEP
            INPUT doesntmatter
            GOTO 500
        END IF
        IF howmanyb + inbackpack(1) + inbackpack(2) + inbackpack(3) + inbackpack(4) + inbackpack(5) + inbackpack(6) > backpackcapacity THEN
            PRINT "You can only have up to "; backpackcapacity; " pieces of candy in your backpack!"
            PRINT
            PRINT "Press enter to continue"
            SLEEP
            INPUT doesntmatter
            GOTO 500
        END IF

        inbackpack(buywhat) = inbackpack(buywhat) + howmanyb
        yourmoney = yourmoney - howmanyb * price(buywhat)
        PRINT
        PRINT "You have "; yourmoney; " pennies and "; inbackpack(buywhat); goods(buywhat)
        PRINT
        520 PRINT "Perform another transaction at this location? (yes or no)"
        INPUT anothertransaction
        anothertransaction = UCASE$(anothertransaction)
        SELECT CASE anothertransaction
            CASE "YES"
                CLS
                GOTO 500
            CASE "NO"
                CLS
                PRINT "Better get going!"
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT "Press enter to continue..."
                SLEEP
                INPUT doesntmatter
                CLS
            CASE ELSE
                PRINT
                PRINT "Huh?"
                GOTO 520
        END SELECT


    CASE "SELL"

        PRINT
        650 PRINT "Sell what? (Choose a number)"
        INPUT sellwhat
        IF sellwhat < 0 OR sellwhat > 6 THEN
            PRINT "Huh?"
            GOTO 650
        END IF
        IF inbackpack(sellwhat) < 1 THEN
            PRINT "You don't have any "; goods(sellwhat)
            GOTO 60
        END IF
        PRINT
        PRINT goods(sellwhat); " cost "; price(sellwhat); " pennies."
        PRINT
        PRINT "How many do you sell?  You have "; inbackpack(sellwhat)
        INPUT howmanys
        PRINT
        CLS
        IF howmanys > inbackpack(sellwhat) THEN
            PRINT "You don't have that much to sell."
            PRINT
            PRINT "Press enter to continue..."
            SLEEP
            INPUT doesntmatter
            GOTO 500
        END IF
        PRINT howmanys; goods(sellwhat); " earn you "; howmanys * price(sellwhat); " pennies."
        inbackpack(sellwhat) = inbackpack(sellwhat) - howmanys
        yourmoney = yourmoney + howmanys * price(sellwhat)
        PRINT
        PRINT "You have "; yourmoney; " pennies and "; inbackpack(sellwhat); goods(sellwhat)
        PRINT
        510 PRINT "Perform another transaction at this location? (yes or no)"
        INPUT anothertransaction
        anothertransaction = UCASE$(anothertransaction)
        SELECT CASE anothertransaction
            CASE "YES"
                CLS
                GOTO 500
            CASE "NO"
                CLS
                PRINT "Better get going!"
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT "Press enter to continue..."
                SLEEP
                INPUT doesntmatter
                CLS
            CASE ELSE
                PRINT
                PRINT "Huh?"
                GOTO 510
        END SELECT




    CASE "LEAVE"
        CLS
        PRINT "Nothing to see here!"
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT "Press enter to continue..."
        SLEEP
        INPUT doesntmatter
        CLS
        GOTO 80

    CASE ELSE
        PRINT "What?"
        GOTO 60

END SELECT


80 daycounter = daycounter + 1
debt = debt * 1.25

IF daycounter = minutes + 1 THEN

    CLS
    endtotal = yourmoney - debt
    PRINT "BRRRR-IIIINNG!"
    PRINT "That's the bell!  Recess is over!"

    IF endtotal < 0 THEN
        PRINT "You lose!  Billy's running toward you, cracking his knuckles!"
        PRINT
        PRINT endtotal; " pennies..."
        PRINT
        330 PRINT "Play again?"
        INPUT playagain
        playagain = UCASE$(playagain)
        SELECT CASE playagain
            CASE "YES"
                CLS
                GOTO 300
            CASE "NO"
                CLS
                PRINT "Alright..."
                END
            CASE ELSE
                CLS
                PRINT "What?"
                PRINT
                GOTO 330
        END SELECT

    END IF
    IF endtotal = 0 THEN
        PRINT "You just made it!  You broke even!"
        PRINT
        320 PRINT "Play again?"
        INPUT playagain
        playagain = UCASE$(playagain)
        SELECT CASE playagain
            CASE "YES"
                CLS
                GOTO 300
            CASE "NO"
                CLS
                PRINT "Alright..."
                END
            CASE ELSE
                CLS
                PRINT "What?"
                PRINT
                GOTO 320
        END SELECT

    END IF
    IF endtotal > 1 THEN
        PRINT
        PRINT "You came out ahead!"
        PRINT endtotal; " pennies!"
        PRINT
        310 PRINT "Play again?"
        INPUT playagain
        playagain = UCASE$(playagain)
        SELECT CASE playagain
            CASE "YES"
                CLS
                GOTO 300
            CASE "NO"
                CLS
                PRINT "Alright..."
                END
            CASE ELSE
                CLS
                PRINT "What?"
                PRINT
                GOTO 310
        END SELECT
    END IF

END IF

GOTO 70

Clippy

  • Hero Member
  • *****
  • Posts: 16446
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Welcome to the Playground--DrugWars knockoff
« Reply #1 on: December 18, 2011, 09:57:51 AM »
Mmmmm...I used to sell chocolate covered cherries in highschool for a buck apiece...
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

OlDosLover

  • Hero Member
  • *****
  • Posts: 3914
  • OlDosLover
    • Email
Re: Welcome to the Playground--DrugWars knockoff
« Reply #2 on: December 18, 2011, 07:43:09 PM »
Hi all,
    Welcome to the forum cole1121. On copy and paste into the QB64 IDE i get the following error.
"Illegal string-number conversion on line 181"
OlDosLover.

Clippy

  • Hero Member
  • *****
  • Posts: 16446
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Welcome to the Playground--DrugWars knockoff
« Reply #3 on: December 18, 2011, 08:02:59 PM »
Worked for me...
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

OlDosLover

  • Hero Member
  • *****
  • Posts: 3914
  • OlDosLover
    • Email
Re: Welcome to the Playground--DrugWars knockoff
« Reply #4 on: December 18, 2011, 08:08:45 PM »
Hi all, 
    You are right. On trying again it all went well and ran. Must have been a bad copy and paste attempt.
OlDosLover.

cole1121

  • Newbie
  • *
  • Posts: 14
Re: Welcome to the Playground--DrugWars knockoff
« Reply #5 on: December 19, 2011, 10:42:54 AM »
Here is an improved version.

Code: [Select]


DIM jbeans AS SINGLE
DIM goods(6) AS STRING
DIM locations(6) AS STRING
DIM price(6) AS INTEGER
DIM inbackpack(6) AS INTEGER
DIM picknumber(6) AS INTEGER
DIM bust AS INTEGER
DIM bsl AS STRING
DIM buywhat AS INTEGER
DIM howmanyb AS INTEGER
DIM sellwhat AS INTEGER
DIM howmanys AS INTEGER
DIM yourmoney AS INTEGER
DIM location AS INTEGER
DIM daycounter AS INTEGER
DIM debt AS INTEGER
DIM doesntmatter AS STRING
DIM visls AS STRING
DIM paynow AS STRING
DIM paydebt AS INTEGER
DIM endtotal AS INTEGER
DIM playagain AS STRING
DIM instructions AS STRING
DIM minutes AS INTEGER
DIM anothertransaction AS STRING
DIM backpackcapacity AS INTEGER
DIM canafford AS INTEGER
DIM buybackpack AS STRING
DIM bustagain AS INTEGER
DIM highscore AS INTEGER
DIM playername AS STRING
DIM currentname AS STRING


PRINT "Press enter to continue..."
SLEEP
INPUT doesntmatter
CLS

SLEEP 1
CLS


OPEN "candyscores.txt" FOR INPUT AS #1
INPUT #1, highscore
CLOSE #1

OPEN "candynames.txt" FOR INPUT AS #2
INPUT #2, playername
CLOSE #2

PRINT "High score: "; playername; highscore
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT "Written by anarchronism...Creative Commons 2011 "
PRINT " "
PRINT "        WELCOME TO THE PLAYGROUND"
SLEEP 1
PRINT
400 PRINT "Would you like instructions? (yes or no)"
INPUT instructions
instructions = UCASE$(instructions)

SELECT CASE instructions
    CASE "YES"
        CLS
        PRINT "It's recess time again, and that means lunch is coming up.  Your"
        PRINT "stomach is growling, but it looks like Mom packed you something"
        PRINT "green and leafy...  You're a fourth grader!  You want REAL food!"
        PRINT
        PRINT "You're going to have to wrangle up some lunch money yourself, and"
        PRINT "that means doing what you do best--clandestine playground candy sales!"
        PRINT "You get a loan of 40 pennies from Billy the Bully and you've got until"
        PRINT "recess is over to pay him back with interest, otherwise you'll see"
        PRINT "exactly how he got his name..."
        PRINT
        PRINT "You can visit Billy to make payments on your loan at his hangout"
        PRINT "under the swings any time.  Make sure to keep track of your debt and"
        PRINT "how many minutes of recess have gone by.  Buy and sell by visiting"
        PRINT "different locations and monitoring prices for different goods."
        PRINT
        PRINT "Buy low, sell high, and good luck!"
        PRINT
        PRINT "Press enter to continue..."
        INPUT doesntmatter
        GOTO 300
    CASE "NO"
        CLS
        GOTO 300
    CASE ELSE
        PRINT "Huh?"
        GOTO 400
END SELECT






300

CLS
PRINT "How many minutes(turns) of recess do you want this game to be?"
PRINT
PRINT "5 is hard, 15 is medium, 25 is easy"
PRINT
INPUT minutes
RANDOMIZE TIMER

CLS

backpackcapacity = 25

debt = 50

daycounter = 1

yourmoney = 40

goods(1) = "Jelly beans"
goods(2) = "Lollies"
goods(3) = "Taffiez"
goods(4) = "Chocolatez"
goods(5) = "Cookiez"
goods(6) = "Fudge Popz"

70
PRINT "Choose a location (by number):"
90 PRINT
PRINT "1.  Swings"
PRINT "2.  Slide"
PRINT "3.  Basketball Court"
PRINT "4.  Tire Swing"
PRINT "5.  Monkey Bars"
PRINT "6.  Time Out"
PRINT
INPUT "Location number:"; location

SELECT CASE location
    CASE IS < 1
        CLS
        PRINT "Pick a number, smartass."
        GOTO 90
    CASE IS > 6
        CLS
        PRINT "Pick a number, smartass."
        GOTO 90
    CASE ELSE
        GOTO 150
END SELECT

150
CLS

price(1) = 1 + INT(RND * 15)
10 price(2) = 10 + INT(RND * 70)
IF price(2) > 80 THEN
    GOTO 10
END IF
20 price(3) = 75 + INT(RND * 100)
IF price(3) > 100 THEN
    GOTO 20
END IF
30 price(4) = 90 + INT(RND * 160)
IF price(4) > 160 THEN
    GOTO 30
END IF
40 price(5) = 150 + INT(RND * 200)
50 price(6) = 200 + INT(RND * 350)



bust = 1 + INT(RND * 100)

IF bust > 10 AND bust < 18 AND inbackpack(1) + inbackpack(2) + inbackpack(3) + inbackpack(4) + inbackpack(5) + inbackpack(6) > 0 THEN
    CLS
    PRINT "No candy on the playground!"
    PRINT
    PRINT "Principal Hardass caught you selling candy!  She confiscates what she finds!"
    FOR x = 1 TO 6
        inbackpack(x) = inbackpack(x) / 2
    NEXT x
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF

IF bust > 0 AND bust < 9 THEN
    CLS
    PRINT "Hey man, wanna buy a bigger backpack?  *SNIFF*"
    PRINT
    PRINT "Sniffly Tom wants to sell you a backpack that will hold 20 more"
    PRINT "pieces of candy."
    PRINT
    750 PRINT "It'll cost 40 pennies.  Do you accept?(yes or no)"
    INPUT buybackpack
    buybackpack = UCASE$(buybackpack)
    SELECT CASE buybackpack
        CASE "YES"
            IF yourmoney < 40 THEN
                PRINT "You can't afford that."
            END IF
            IF yourmoney >= 40 THEN
                yourmoney = yourmoney - 40
                backpackcapacity = backpackcapacity + 20
                PRINT
                PRINT "Thanks, man! *SNIFF* It'll pay for itself in no time!"
            END IF
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT "Press enter to continue..."
            SLEEP
            INPUT doesntmatter
        CASE "NO"
            CLS
            PRINT "Your loss...*SNIFF*"
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT
            PRINT "Press enter to continue..."
            SLEEP
            INPUT doesntmatter
        CASE ELSE
            PRINT "Huh?"
            GOTO 750
    END SELECT
END IF
IF bust > 49 AND bust < 60 THEN
    price(1) = price(1) + 1 + INT(RND * 20)
    PRINT "Principal Hardass cracked down on jelly beans!  Prices are through"
    PRINT "the roof!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 59 AND bust < 70 THEN
    price(2) = price(2) + 1 + INT(RND * 45)
    PRINT "Teachers are confiscating lollies!  High prices!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 69 AND bust < 80 THEN
    price(3) = price(3) + 1 + INT(RND * 110)
    PRINT "Taffy bust!  Prices are through the roof!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 79 AND bust < 90 THEN
    price(4) = price(4) + 1 + INT(RND * 130)
    PRINT "Chocolate fiends got busted by those asshole teachers!"
    PRINT "Prices are up!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 89 AND bust < 95 THEN
    price(5) = price(5) + 1 + INT(RND * 285)
    PRINT "Cookie bust!  Prices are through the roof!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF
IF bust > 30 AND bust < 42 THEN
    price(6) = price(6) + 1 + INT(RND * 500)
    PRINT "They busted the ice cream peddlers!  Fudge popz ain't cheap!"
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    SLEEP
    INPUT doesntmatter
END IF

IF location = 1 THEN
    price(6) = price(6) + 1 + INT(RND * 150)
    CLS

    120 PRINT "Visit Billy the Bully?"
    INPUT visls
    visls = UCASE$(visls)

    SELECT CASE visls
        CASE "YES"
            CLS
            PRINT "Hey bub, how's the business comin'?"
            PRINT
            PRINT "Looks like you owe me "; debt; " pennies."
            PRINT
            130 PRINT "Pay now? (yes or no)"
            INPUT paynow
            paynow = UCASE$(paynow)

            SELECT CASE paynow
                CASE "YES"
                    CLS
                    PRINT "Good thinkin'.  You don't wanna keep me waitin'."
                    PRINT
                    140 PRINT "How much do you pay?  You owe "; debt
                    INPUT paydebt
                    IF paydebt > yourmoney THEN
                        PRINT "You don't have that much."
                        PRINT
                        GOTO 140
                    END IF
                    yourmoney = yourmoney - paydebt
                    debt = debt - paydebt
                    CLS
                    PRINT "You now owe Billy "; debt; " pennies."

                CASE "NO"
                    CLS
                    PRINT "Fine.  Suit yourself.  We'll meet again, one way or another"
                CASE ELSE
                    GOTO 130
            END SELECT


        CASE "NO"
            CLS
            GOTO 110
        CASE ELSE
            CLS
            GOTO 120
    END SELECT

    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT
    PRINT "Press enter to continue..."
    INPUT doesntmatter
    CLS
END IF

110
IF location = 2 THEN
    price(5) = price(5) - 1 + INT(RND * 50)
END IF
IF location = 3 THEN
    price(4) = price(4) - 1 + INT(RND * 15)
    price(1) = price(1) + 1 + INT(RND * 5)
END IF
IF location = 6 THEN
    bustagain = 1 + INT(RND * 100)
    IF bustagain >= 85 AND inbackpack(1) + inbackpack(2) + inbackpack(3) + inbackpack(4) + inbackpack(5) + inbackpack(6) > 0 THEN
        CLS
        PRINT "That pompous student teacher caught you selling candy to the"
        PRINT "kids in time out!  She confiscates what she finds!"
        FOR x = 1 TO 6
            inbackpack(x) = inbackpack(x) / 2
        NEXT x
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT "Press enter to continue..."
        SLEEP
        INPUT doesntmatter
    END IF
    price(3) = price(3) + 1 + INT(RND * 100)
    price(4) = price(4) + 1 + INT(RND * 100)
    price(5) = price(5) + 1 + INT(RND * 125)
    price(6) = price(6) + 1 + INT(RND * 150)
END IF



500 CLS
PRINT "You have "; yourmoney; " pennies.", "Minute: "; daycounter, "Debt: "; debt
PRINT
PRINT "For sale:", "Price:", "In backpack:"
PRINT
PRINT "1. J-Beanz", price(1), inbackpack(1)
PRINT "2. Lolliez", price(2), inbackpack(2)
PRINT "3. Taffiez", price(3), inbackpack(3)
PRINT "4. Chocolatez", price(4), inbackpack(4)
PRINT "5. Cookiez", price(5), inbackpack(5)
PRINT "6. Fudge Popz", price(6), inbackpack(6)
PRINT
60 PRINT "Buy, sell, or leave?"
INPUT bsl
bsl = UCASE$(bsl)

SELECT CASE bsl

    CASE "BUY"

        PRINT
        550 PRINT "Buy what? (Choose a number)"
        canafford = 0
        INPUT buywhat
        IF buywhat < 1 OR buywhat > 6 THEN
            PRINT "Huh?"
            GOTO 550
        END IF
        PRINT
        PRINT goods(buywhat); " cost "; price(buywhat); " pennies."
        PRINT
        DO WHILE price(buywhat) * canafford <= yourmoney
            canafford = canafford + 1
        LOOP
        canafford = canafford - 1
        PRINT "You can afford "; canafford; "."
        PRINT
        PRINT "How many?"
        INPUT howmanyb
        PRINT
        CLS
        PRINT howmanyb; goods(buywhat); " cost you "; howmanyb * price(buywhat); " pennies."
        IF howmanyb * price(buywhat) > yourmoney THEN
            PRINT "You can't afford that."
            PRINT
            PRINT "Press enter to continue..."
            SLEEP
            INPUT doesntmatter
            GOTO 500
        END IF
        IF howmanyb + inbackpack(1) + inbackpack(2) + inbackpack(3) + inbackpack(4) + inbackpack(5) + inbackpack(6) > backpackcapacity THEN
            PRINT "You can only have up to "; backpackcapacity; " pieces of candy in your backpack!"
            PRINT
            PRINT "Press enter to continue"
            SLEEP
            INPUT doesntmatter
            GOTO 500
        END IF

        inbackpack(buywhat) = inbackpack(buywhat) + howmanyb
        yourmoney = yourmoney - howmanyb * price(buywhat)
        PRINT
        PRINT "You have "; yourmoney; " pennies and "; inbackpack(buywhat); goods(buywhat)
        PRINT
        520 PRINT "Perform another transaction at this location? (yes or no)"
        INPUT anothertransaction
        anothertransaction = UCASE$(anothertransaction)
        SELECT CASE anothertransaction
            CASE "YES"
                CLS
                GOTO 500
            CASE "NO"
                CLS
                PRINT "Better get going!"
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT "Press enter to continue..."
                SLEEP
                INPUT doesntmatter
                CLS
            CASE ELSE
                PRINT
                PRINT "Huh?"
                GOTO 520
        END SELECT


    CASE "SELL"

        PRINT
        650 PRINT "Sell what? (Choose a number)"
        INPUT sellwhat
        IF sellwhat < 0 OR sellwhat > 6 THEN
            PRINT "Huh?"
            GOTO 650
        END IF
        IF inbackpack(sellwhat) < 1 THEN
            PRINT "You don't have any "; goods(sellwhat)
            GOTO 60
        END IF
        PRINT
        PRINT goods(sellwhat); " cost "; price(sellwhat); " pennies."
        PRINT
        PRINT "How many do you sell?  You have "; inbackpack(sellwhat)
        INPUT howmanys
        PRINT
        CLS
        IF howmanys > inbackpack(sellwhat) THEN
            PRINT "You don't have that much to sell."
            PRINT
            PRINT "Press enter to continue..."
            SLEEP
            INPUT doesntmatter
            GOTO 500
        END IF
        PRINT howmanys; goods(sellwhat); " earn you "; howmanys * price(sellwhat); " pennies."
        inbackpack(sellwhat) = inbackpack(sellwhat) - howmanys
        yourmoney = yourmoney + howmanys * price(sellwhat)
        PRINT
        PRINT "You have "; yourmoney; " pennies and "; inbackpack(sellwhat); goods(sellwhat)
        PRINT
        510 PRINT "Perform another transaction at this location? (yes or no)"
        INPUT anothertransaction
        anothertransaction = UCASE$(anothertransaction)
        SELECT CASE anothertransaction
            CASE "YES"
                CLS
                GOTO 500
            CASE "NO"
                CLS
                PRINT "Better get going!"
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT
                PRINT "Press enter to continue..."
                SLEEP
                INPUT doesntmatter
                CLS
            CASE ELSE
                PRINT
                PRINT "Huh?"
                GOTO 510
        END SELECT




    CASE "LEAVE"
        CLS
        PRINT "Nothing to see here!"
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT
        PRINT "Press enter to continue..."
        SLEEP
        INPUT doesntmatter
        CLS
        GOTO 80

    CASE ELSE
        PRINT "What?"
        GOTO 60

END SELECT


80 daycounter = daycounter + 1
debt = debt * 1.25

IF daycounter = minutes + 1 THEN

    CLS
    endtotal = yourmoney - debt
    PRINT "BRRRR-IIIINNG!"
    PRINT "That's the bell!  Recess is over!"

    IF endtotal < 0 THEN
        PRINT "You lose!  Billy's running toward you, cracking his knuckles!"
        PRINT
        PRINT endtotal; " pennies..."
        PRINT

        OPEN "candyscores.txt" FOR INPUT AS #1
        INPUT #1, highscore
        CLOSE #1

        OPEN "candynames.txt" FOR INPUT AS #2
        INPUT #2, playername
        CLOSE #2

        PRINT "High score: "; playername; highscore
        PRINT



        330 PRINT "Play again?"
        INPUT playagain
        playagain = UCASE$(playagain)
        SELECT CASE playagain
            CASE "YES"
                CLS
                GOTO 300
            CASE "NO"
                CLS
                PRINT "Alright..."
                END
            CASE ELSE
                CLS
                PRINT "What?"
                PRINT
                GOTO 330
        END SELECT

    END IF

    IF endtotal = 0 THEN
        PRINT "You just made it!  You broke even!"
        PRINT
        OPEN "candyscores.txt" FOR INPUT AS #1
        INPUT #1, highscore
        CLOSE #1

        OPEN "candynames.txt" FOR INPUT AS #2
        INPUT #2, playername
        CLOSE #2


        PRINT "High score: "; playername; highscore
        PRINT


        320 PRINT "Play again?"
        INPUT playagain
        playagain = UCASE$(playagain)
        SELECT CASE playagain
            CASE "YES"
                CLS
                GOTO 300
            CASE "NO"
                CLS
                PRINT "Alright..."
                END
            CASE ELSE
                CLS
                PRINT "What?"
                PRINT
                GOTO 320
        END SELECT

    END IF
    IF endtotal > 1 THEN
        PRINT
        PRINT "You came out ahead!"
        PRINT endtotal; " pennies!"
        PRINT


        OPEN "candyscores.txt" FOR INPUT AS #1
        INPUT #1, highscore
        CLOSE #1

        OPEN "candynames.txt" FOR INPUT AS #2
        INPUT #2, playername
        CLOSE #2

        IF endtotal <= highscore THEN
            PRINT "High score: "; playername; highscore
            PRINT
        END IF


        IF endtotal > highscore THEN
            PRINT "New high score!"
            PRINT
            PRINT "Previous high score: "; playername; highscore
            PRINT
            PRINT "Enter your name:"
            INPUT currentname
            OPEN "candynames.txt" FOR OUTPUT AS #3
            WRITE #3, currentname
            CLOSE #3
            OPEN "candyscores.txt" FOR OUTPUT AS #4
            WRITE #4, endtotal
            CLOSE #4
            CLS

            PRINT "High score: "; currentname; endtotal
            PRINT
        END IF




        310 PRINT "Play again?"
        INPUT playagain
        playagain = UCASE$(playagain)
        SELECT CASE playagain
            CASE "YES"
                CLS
                GOTO 300
            CASE "NO"
                CLS
                PRINT "Alright..."
                END
            CASE ELSE
                CLS
                PRINT "What?"
                PRINT
                GOTO 310
        END SELECT
    END IF

END IF

GOTO 70


There is greater variety in candy prices in this version, so there's more potential for earning huge amounts of money, which makes it feel more fun and less studious.

I've also included the capability for a high score to be saved.  In order for the program to work, you'll need to create a "candynames.txt" file and a "candyscores.txt" file in your QB64 folder, and then put a character string in candynames.txt and a number in candyscores.txt.

For example, I start off candynames.txt with "Nobody" written in it and candyscores.txt with "0" written in it.

Is there some kind of create-text-file command/function I can use in my code to make it so that users don't have to create the text files themselves?

Thanks to Clippy and OlDos for giving it a try.

coma8coma1

  • Sr. Member
  • ****
  • Posts: 435
Re: Welcome to the Playground--DrugWars knockoff
« Reply #6 on: December 22, 2011, 04:01:11 AM »
...Is there some kind of create-text-file command/function I can use in my code to make it so that users don't have to create the text files themselves?...

You could use one of Clippy's file detection routines
http://qb64.net/wiki/index.php?title=OPEN
to determine if the file exists, and if not, generate one by OPENing it for INPUT and WRITEing the appropriate default data.

The code in that link works great, and I use it in all of my game editors to prevent the user from trying to open a map or tile file that does not yet exist, thereby preventing crashes that cause a loss of work!

EDIT: wait, there's also THIS, which I previously did not know about! A qb64 function that returns true of false if a file exists!
http://qb64.net/wiki/index.php?title=FILEEXISTS
It is a NEW function as of qb64 v0.94, so make sure you have the latest version of qb64!

Check at the beginning of your program if the necessary files exist, and if they don't, create them!
« Last Edit: December 22, 2011, 04:13:27 AM by coma8coma1 »

cole1121

  • Newbie
  • *
  • Posts: 14
Re: Welcome to the Playground--DrugWars knockoff
« Reply #7 on: December 30, 2011, 04:07:55 PM »
Thanks a bunch coma!  Learning is good.  I'll go back and throw that code in there.

vrensul

  • Sr. Member
  • ****
  • Posts: 320
  • 44th Degree Digital Wizard of the HighBytes Order
Re: Welcome to the Playground--DrugWars knockoff
« Reply #8 on: December 30, 2011, 06:27:35 PM »
Not to change your entire idea but why not just use one file instead of two?

For example the file could list like:
Code: [Select]
Player1=23
player2=44
player97=154
player66=2

Then, just load each line and use INSTR to break the string using MID$ (from 1 to the "=" position-1 , then the "=" position +1 to the LEN of the string) or you could use LEFT$ and RIGHT$ either way. 

Otherwise, I was a big fan of drug wars (is it still around?) and I like this game too =)  I hope it makes basic gamer.  (I can't remember the author's name for the life of me!)
« Last Edit: December 31, 2011, 07:37:55 AM by vrensul »
' With programming, you  can do anything!
DEF SEG = &HBANKACNT 'weekend starts here...
     poke checking, 1000000
DEF SEG ' quit job here.