Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lesson 10: Slot Machine
#7
@marbac74 See if this is a little easier to understand.  I don't think there's any advanced commands in it anymore. 

Code: (Select All)
SCREEN _NEWIMAGE(340, 340, 32)
_TITLE "Slot Machine!"
RANDOMIZE TIMER
$COLOR:32
COLOR White, 0
Money = 300
DIM AS _FLOAT spin1, spin2, spin3
DO
    CLS , DarkGray
    CenterText 2, "ENTER TO SPIN!  (You have $" + STR$(Money) + ")"
    CenterText 10, "PAYOUTS"
    CenterText 11, "Three Double Circles -- 500"
    CenterText 12, "Three Squares        --  25"
    CenterText 13, "Three Triangles      --  25"
    CenterText 14, "Three Circles        --  25"
    CenterText 15, "Two Circles          --  10"
    CenterText 16, "Three Diamonds      --  10"
    CenterText 17, "Two Diamonds        --  5"
    CenterText 18, "One Diamond          --  1"
    DO: a$ = INPUT$(1): LOOP UNTIL a$ = CHR$(13) OR a$ = CHR$(27)
    IF a$ = CHR$(27) THEN SYSTEM
    LINE (0, 0)-(340, 340), DarkGray, BF
    spin1 = TIMER + RND * 2 + 1: spin2 = RND * 2 + 1 + spin1: spin3 = RND * 2 + 1 + spin2
    DO
        finished = -1
        IF spin1 > TIMER THEN slot1 = INT(RND * 16 / 3) + 1: DrawSlot 0, slot1
        IF spin2 > TIMER THEN slot2 = INT(RND * 16 / 3) + 1: DrawSlot 1, slot2
        IF spin3 > TIMER THEN slot3 = INT(RND * 16 / 3) + 1: DrawSlot 2, slot3: finished = 0
        _LIMIT 10
        _DISPLAY
    LOOP UNTIL finished
    _AUTODISPLAY
    win = -10: diamond = 0: circles = 0 'the "ante" of $10 to spin.  Reset values
    IF slot1 = slot2 AND slot2 = slot3 THEN 'three of a kind!
        SELECT CASE slot1
            CASE 1, 2, 4, 5: win = 250 '3 circles/triangles/reverse triangles/squares
            CASE 3: win = 100 '3 diamonds
            CASE 6: win = 5000 '3 double circles
        END SELECT
    END IF
    IF slot1 = 3 THEN diamond = diamond + 1 ELSE IF slot1 = 1 THEN circles = circles + 1
    IF slot2 = 3 THEN diamond = diamond + 1 ELSE IF slot2 = 1 THEN circles = circles + 1
    IF slot3 = 3 THEN diamond = diamond + 1 ELSE IF slot3 = 1 THEN circles = circles + 1
    IF diamond = 1 THEN win = 10 ELSE IF diamond = 2 THEN win = 50 '1 diamond or 2 diamond
    IF circles = 2 THEN win = 100 '2 circles
    IF win < 0 THEN CenterText 15, "Sorry.  No Match.  You lose." ELSE CenterText 15, "Congrats!  You win!"
    Money = Money + win
    _KEYCLEAR: SLEEP: _DELAY .5: _KEYCLEAR
LOOP
SUB DrawSlot (where, what)
    w = 110 * where
    LINE (10 + w, 50)-STEP(100, 100), Black, BF
    SELECT CASE what
        CASE 1: MakeCircle 60 + w, 100, 50, Red 'circle
        CASE 2: MakeTriangle 60 + w, 50, 10 + w, 150, 110 + w, 150, Yellow 'up triangle
        CASE 3: MakeDiamond 60 + w, 50, 10 + w, 100, 60 + w, 150, 110 + w, 100, Green 'diamond
        CASE 4: MakeTriangle 60 + w, 150, 10 + w, 50, 110 + w, 50, Purple 'down triangle
        CASE 5: LINE (20 + 110 * where, 60)-STEP(80, 80), Blue, BF: 'square
        CASE 6: MakeCircle 60 + w, 100, 50, Cyan: MakeCircle 60 + w, 100, 25, Blue 'double circle
    END SELECT
END SUB
SUB CenterText (y, text$)
    LOCATE y, (42 - LEN(text$)) / 2: PRINT text$;
END SUB
SUB MakeTriangle (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
    LINE (x1, y1)-(x2, y2), K: LINE -(x3, y3), K: LINE -(x1, y1), K
    PAINT (x1, 100), K
END SUB
SUB MakeDiamond (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
    LINE (x1, y1)-(x2, y2), K: LINE -(x3, y3), K: LINE -(x4, y4), K: LINE -(x1, y1), K
    PAINT (x1, 100), K
END SUB
SUB MakeCircle (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
    CIRCLE (CX, CY), R, C
    PAINT (CX, CY), C
END SUB

Most of the advanced stuff, was really just quick little plug-ins from code that I've wrote in the past and optomized for speed.  It looks fancy, and runs fast, but it's no more valid than something as simple as the above, for little games and demos like this.  Smile

If you have any questions of what I've did here, at any point in the code, just ask.  I'm always available to answer questions.  Wink



(And you also have to keep in mind, I'm not quite classified as a "beginner" anymore.  I suppose I can still claim the tag of "developer" for the language -- though I'm often too lazy, or two busy with other stuff to do any real developing.  I tend to leave that to the younger, smarter, but less amazing guys!  Big Grin )
Reply


Messages In This Thread
Lesson 10: Slot Machine - by SMcNeill - 06-08-2024, 11:02 PM
RE: Lesson 10: Slot Machine - by TerryRitchie - 06-09-2024, 12:39 AM
RE: Lesson 10: Slot Machine - by SMcNeill - 06-09-2024, 12:42 AM
RE: Lesson 10: Slot Machine - by SMcNeill - 06-09-2024, 03:26 AM
RE: Lesson 10: Slot Machine - by TerryRitchie - 06-09-2024, 02:29 PM
RE: Lesson 10: Slot Machine - by marbac74 - 06-09-2024, 03:43 PM
RE: Lesson 10: Slot Machine - by TerryRitchie - 06-10-2024, 03:14 AM
RE: Lesson 10: Slot Machine - by SMcNeill - 06-09-2024, 05:22 PM



Users browsing this thread: 1 Guest(s)