Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lesson's 10 Exercise (Partial solution)
#4
Well, that's today's state-of-the-art version. I'm partially happy with this, but not completely. There is no blinking "WINNER" print statement, but that would be a minor detail. It kind of works, but from time to time the second wheel's box gets black without showing the symbol, I can't understand why. The programs makes use of three distinct loops while I saw your solution used one, which makes the code shorter and possibly more efficient. That is my result, not optimal, but I'm gonna stop today and come back maybe in the next days to try to improve it.

PS: At least I found the problem with WHEEL2: It was a misspelling of DOWNTRIANGLE which I wrote as DOWNTRIAMGLE. No surprise that the symbol was not drawn Big Grin
Code: (Select All)
SCREEN _NEWIMAGE(340, 340, 32)
_TITLE "Slot Machine"

CONST RED = _RGB32(255, 0, 0)
CONST GREEN = _RGB32(0, 255, 0)
CONST BLUE = _RGB32(0, 0, 255)
CONST PURPLE = _RGB32(255, 0, 255)
CONST YELLOW = _RGB32(255, 255, 0)
CONST CYAN = _RGB32(0, 255, 255)
CONST BLACK = _RGB32(0)
CONST GREY = _RGB32(70)

DIM SHARED Wheel1$(15)
Wheel1$(0) = "SQUARE": Wheel1$(1) = "CIRCLE": Wheel1$(2) = "DIAMOND": Wheel1$(3) = "UPTRIANGLE"
Wheel1$(4) = "DOWNTRIANGLE": Wheel1$(5) = "SQUARE": Wheel1$(6) = "CIRCLE": Wheel1$(7) = "DIAMOND"
Wheel1$(8) = "UPTRIANGLE": Wheel1$(9) = "DOWNTRIANGLE": Wheel1$(10) = "SQUARE": Wheel1$(11) = "CIRCLE"
Wheel1$(12) = "DIAMOND": Wheel1$(13) = "UPTRIANGLE": Wheel1$(14) = "DOWNTRIANGLE": Wheel1$(15) = "SPECIAL"

DIM SHARED Wheel2$(15)
Wheel2$(0) = "CIRCLE": Wheel2$(1) = "DIAMOND": Wheel2$(2) = "DOWNTRIANGLE": Wheel2$(3) = "SQUARE"
Wheel2$(4) = "UPTRIANGLE": Wheel2$(5) = "CIRCLE": Wheel2$(6) = "DIAMOND": Wheel2$(7) = "DOWNTRIAMGLE"
Wheel2$(8) = "SQUARE": Wheel2$(9) = "UPTRIANGLE": Wheel2$(10) = "CIRCLE": Wheel2$(11) = "DIAMOND"
Wheel2$(12) = "DOWNTRIANGLE": Wheel2$(13) = "SQUARE": Wheel2$(14) = "UPTRIANGLE": Wheel2$(15) = "SPECIAL"

DIM SHARED Wheel3$(15)
Wheel3$(0) = "UPTRIANGLE": Wheel3$(1) = "CIRCLE": Wheel3$(2) = "DIAMOND": Wheel3$(3) = "SQUARE"
Wheel3$(4) = "DOWNTRIANGLE": Wheel3$(5) = "UPTRIANGLE": Wheel3$(6) = "CIRCLE": Wheel3$(7) = "DIAMOND"
Wheel3$(8) = "SQUARE": Wheel3$(9) = "DOWNTRIANGLE": Wheel3$(10) = "UPTRIANGLE": Wheel3$(11) = "CIRCLE"
Wheel3$(12) = "DIAMOND": Wheel3$(13) = "SQUARE": Wheel3$(14) = "DOWNTRIANGLE": Wheel3$(15) = "SPECIAL"

DIM SHARED Outcome$(2)

DIM SHARED Special$(2)
Special$(0) = "SPECIAL": Special$(1) = "SPECIAL": Special$(2) = "SPECIAL"
DIM SHARED Square$(2)
Square$(0) = "SQUARE": Square$(1) = "SQUARE": Square$(2) = "SQUARE"
DIM SHARED Circle$(2)
Circle$(0) = "CIRCLE": Circle$(1) = "CIRCLE": Circle$(2) = "CIRCLE"
DIM SHARED Diamond$(2)
Diamond$(0) = "DIAMOND": Diamond$(1) = "DIAMOND": Diamond$(2) = "DIAMOND"
DIM SHARED UpTriangle$(2)
UpTriangle$(0) = "UPTRIANGLE": UpTriangle$(1) = "UPTRIANGLE": UpTriangle$(2) = "UPTRIANGLE"
DIM SHARED DownTriangle$(2)
DownTriangle$(0) = "DOWNTRIANGLE": DownTriangle$(1) = "DOWNTRIANGLE": DownTriangle$(2) = "DOWNTRIANGLE"

DIM SHARED Score%

CLS , GREY
LINE (10, 20)-(110, 120), BLACK, BF
DrawSymbol "SPECIAL", 1
LINE (120, 20)-(220, 120), BLACK, BF
DrawSymbol "SPECIAL", 2
LINE (230, 20)-(330, 120), BLACK, BF
DrawSymbol "SPECIAL", 3

DO
    _PRINTMODE _KEEPBACKGROUND
    LOCATE 1, 16
    COLOR YELLOW: PRINT "SLOT MACHINE"
    LOCATE 9, 2
    COLOR YELLOW: PRINT "ENTER to spin"; TAB(21); Score%; TAB(32); "ESC to exit"
    LOCATE 11, 18
    PRINT "PAYOUTS"
    LOCATE 13, 10
    COLOR YELLOW: PRINT "3 Double Circles - 250"
    LOCATE 14, 10
    COLOR YELLOW: PRINT "3 Squares        -  25"
    LOCATE 15, 10
    COLOR YELLOW: PRINT "3 Triangles      -  25"
    LOCATE 16, 10
    COLOR YELLOW: PRINT "3 Circles        -  25"
    LOCATE 17, 10
    COLOR YELLOW: PRINT "2 Circles        -  10"
    LOCATE 18, 10
    COLOR YELLOW: PRINT "3 Diamonds      -  10"
    LOCATE 19, 10
    COLOR YELLOW: PRINT "2 Diamonds      -  5"
    LOCATE 20, 10
    COLOR YELLOW: PRINT "1 Diamond        -  1";

    KeyPressed$ = INKEY$
    IF KeyPressed$ = CHR$(13) THEN
        Score% = Score% - 1
        RANDOMIZE TIMER

        Wheel1% = INT(RND * 10 + 10)
        Index% = 0
        FOR C = 0 TO Wheel1%
            IF Index% < 16 THEN
                Outcome$(0) = Wheel1$(Index%)
                LINE (10, 20)-(110, 120), BLACK, BF
                DrawSymbol Wheel1$(Index%), 1
                LINE (120, 20)-(220, 120), BLACK, BF
                DrawSymbol Wheel2$(Index%), 2
                LINE (230, 20)-(330, 120), BLACK, BF
                DrawSymbol Wheel3$(Index%), 3
                _DELAY .1
                Index% = Index% + 1
            ELSEIF Index% = 16 THEN
                Index% = 0
                Outcome$(0) = Wheel1$(Index%)
                LINE (10, 20)-(110, 120), BLACK, BF
                DrawSymbol Wheel1$(Index%), 1
                LINE (120, 20)-(220, 120), BLACK, BF
                DrawSymbol Wheel2$(Index%), 2
                LINE (230, 20)-(330, 120), BLACK, BF
                DrawSymbol Wheel3$(Index%), 3
                _DELAY .1
                Index% = Index% + 1
            END IF
        NEXT C

        Wheel2% = INT(RND * 20 + 15)
        Index% = 0
        FOR C = 0 TO Wheel2%
            IF Index% < 16 THEN
                Outcome$(1) = Wheel2$(Index%)
                LINE (120, 20)-(220, 120), BLACK, BF
                DrawSymbol Wheel2$(Index%), 2
                LINE (230, 20)-(330, 120), BLACK, BF
                DrawSymbol Wheel3$(Index%), 3
                _DELAY .1
                Index% = Index% + 1
            ELSE
                Index% = 0
                Outcome$(1) = Wheel2$(Index%)
                LINE (120, 20)-(220, 120), BLACK, BF
                DrawSymbol Wheel2$(Index%), 2
                LINE (230, 20)-(330, 120), BLACK, BF
                DrawSymbol Wheel3$(Index%), 3
                _DELAY .1
                Index% = Index% + 1
            END IF
        NEXT C

        Wheel3% = INT(RND * 20 + 15)
        Index% = 0
        FOR C = 0 TO Wheel3%
            IF Index% < 16 THEN
                Outcome$(2) = Wheel3$(Index%)
                LINE (230, 20)-(330, 120), BLACK, BF
                DrawSymbol Wheel3$(Index%), 3
                _DELAY .1
                Index% = Index% + 1
            ELSE
                Index% = 0
                Outcome$(2) = Wheel3$(Index%)
                LINE (230, 20)-(330, 120), BLACK, BF
                DrawSymbol Wheel3$(Index%), 3
                _DELAY .1
                Index% = Index% + 1
            END IF
        NEXT C
        Score% = CalculateScore%
        CLS , GREY
        LINE (10, 20)-(110, 120), BLACK, BF
        DrawSymbol Outcome$(0), 1
        LINE (120, 20)-(220, 120), BLACK, BF
        DrawSymbol Outcome$(1), 2
        LINE (230, 20)-(330, 120), BLACK, BF
        DrawSymbol Outcome$(2), 3
    END IF
LOOP UNTIL KeyPressed$ = CHR$(27)
SYSTEM

SUB DrawSymbol (Figure$, Box%)
    IF Figure$ = "SQUARE" AND Box% = 1 THEN
        LINE (20, 30)-(100, 110), BLUE, BF
    ELSEIF Figure$ = "SQUARE" AND Box% = 2 THEN
        LINE (130, 30)-(210, 110), BLUE, BF
    ELSEIF Figure$ = "SQUARE" AND Box% = 3 THEN
        LINE (240, 30)-(320, 110), BLUE, BF
    ELSEIF Figure$ = "CIRCLE" AND Box% = 1 THEN
        CIRCLE (60, 70), 40, RED
        PAINT (60, 70), RED, RED
    ELSEIF Figure$ = "CIRCLE" AND Box% = 2 THEN
        CIRCLE (170, 70), 40, RED
        PAINT (170, 70), RED, RED
    ELSEIF Figure$ = "CIRCLE" AND Box% = 3 THEN
        CIRCLE (280, 70), 40, RED
        PAINT (280, 70), RED, RED
    ELSEIF Figure$ = "SPECIAL" AND Box% = 1 THEN
        CIRCLE (60, 70), 40, CYAN
        PAINT (60, 70), CYAN, CYAN
        CIRCLE (60, 70), 20, BLUE
        PAINT (60, 70), BLUE, BLUE
    ELSEIF Figure$ = "SPECIAL" AND Box% = 2 THEN
        CIRCLE (170, 70), 40, CYAN
        PAINT (170, 70), CYAN, CYAN
        CIRCLE (170, 70), 20, BLUE
        PAINT (170, 70), BLUE, BLUE
    ELSEIF Figure$ = "SPECIAL" AND Box% = 3 THEN
        CIRCLE (280, 70), 40, CYAN
        PAINT (280, 70), CYAN, CYAN
        CIRCLE (280, 70), 20, BLUE
        PAINT (280, 70), BLUE, BLUE
    ELSEIF Figure$ = "UPTRIANGLE" AND Box% = 1 THEN
        LINE (20, 110)-(100, 110), YELLOW
        LINE -(60, 30), YELLOW
        LINE -(20, 110), YELLOW
        PAINT (60, 70), YELLOW, YELLOW
    ELSEIF Figure$ = "UPTRIANGLE" AND Box% = 2 THEN
        LINE (130, 110)-(210, 110), YELLOW
        LINE -(170, 30), YELLOW
        LINE -(130, 110), YELLOW
        PAINT (170, 70), YELLOW, YELLOW
    ELSEIF Figure$ = "UPTRIANGLE" AND Box% = 3 THEN
        LINE (240, 110)-(320, 110), YELLOW
        LINE -(280, 30), YELLOW
        LINE -(240, 110), YELLOW
        PAINT (280, 70), YELLOW, YELLOW
    ELSEIF Figure$ = "DOWNTRIANGLE" AND Box% = 1 THEN
        LINE (20, 30)-(100, 30), PURPLE
        LINE -(60, 110), PURPLE
        LINE -(20, 30), PURPLE
        PAINT (60, 70), PURPLE, PURPLE
    ELSEIF Figure$ = "DOWNTRIANGLE" AND Box% = 2 THEN
        LINE (130, 30)-(210, 30), PURPLE
        LINE -(170, 110), PURPLE
        LINE -(130, 30), PURPLE
        PAINT (170, 70), PURPLE, PURPLE
    ELSEIF Figure$ = "DOWNTRIANGLE" AND Box% = 3 THEN
        LINE (240, 30)-(320, 30), PURPLE
        LINE -(280, 110), PURPLE
        LINE -(240, 30), PURPLE
        PAINT (280, 70), PURPLE, PURPLE
    ELSEIF Figure$ = "DIAMOND" AND Box% = 1 THEN
        LINE (60, 110)-(100, 70), GREEN
        LINE -(60, 30), GREEN
        LINE -(20, 70), GREEN
        LINE -(60, 110), GREEN
        PAINT (60, 70), GREEN, GREEN
    ELSEIF Figure$ = "DIAMOND" AND Box% = 2 THEN
        LINE (170, 110)-(210, 70), GREEN
        LINE -(170, 30), GREEN
        LINE -(130, 70), GREEN
        LINE -(170, 110), GREEN
        PAINT (170, 70), GREEN, GREEN
    ELSEIF Figure$ = "DIAMOND" AND Box% = 3 THEN
        LINE (280, 110)-(320, 70), GREEN
        LINE -(280, 30), GREEN
        LINE -(240, 70), GREEN
        LINE -(280, 110), GREEN
        PAINT (280, 70), GREEN, GREEN
    END IF
END SUB

FUNCTION CalculateScore% ()
    IF Outcome$(0) = Special$(0) AND Outcome$(1) = Special$(1) AND Outcome$(2) = Special$(2) THEN
        CalculateScore% = Score% + 250
    ELSEIF Outcome$(0) = Square$(0) AND Outcome$(1) = Square$(1) AND Outcome$(2) = Square$(2) THEN
        CalculateScore% = Score% + 25
    ELSEIF Outcome$(0) = Circle$(0) AND Outcome$(1) = Circle$(1) AND Outcome$(2) = Circle$(2) THEN
        CalculateScore% = Score% + 25
    ELSEIF Outcome$(0) = UpTriangle$(0) AND Outcome$(1) = UpTriangle$(1) AND Outcome$(2) = UpTriangle$(2) THEN
        CalculateScore% = Score% + 25
    ELSEIF Outcome$(0) = DownTriangle$(0) AND Outcome$(1) = DownTriangle$(1) AND Outcome$(2) = DownTriangle$(2) THEN
        CalculateScore% = Score% + 25
    ELSEIF Outcome$(0) = Diamond$(0) AND Outcome$(1) = Diamond$(1) AND Outcome$(2) = Diamond$(2) THEN
        CalculateScore% = Score% + 10
    ELSEIF Outcome$(0) = Circle$(0) AND Outcome$(1) = Circle$(1) OR Outcome$(0) = Circle$(0) AND Outcome$(2) = Circle$(2) OR Outcome$(1) = Circle$(1) AND Outcome$(2) = Circle$(2) THEN
        CalculateScore% = Score% + 10
    ELSEIF Outcome$(0) = Diamond$(0) AND Outcome$(1) = Diamond$(1) OR Outcome$(0) = Diamond$(0) AND Outcome$(2) = Diamond$(2) OR Outcome$(1) = Diamond$(1) AND Outcome$(2) = Diamond$(2) THEN
        CalculateScore% = Score% + 5
    ELSEIF Outcome$(0) = Diamond$(0) OR Outcome$(1) = Diamond$(1) OR Outcome$(2) = Diamond$(2) THEN
        CalculateScore% = Score% + 1
    ELSE
        CalculateScore% = Score%
    END IF
END FUNCTION
Reply


Messages In This Thread
RE: Lesson's 10 Exercise (Partial solution) - by marbac74 - 06-08-2024, 01:50 PM



Users browsing this thread: 1 Guest(s)