Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lesson 10: Slot Machine
#1
So, I saw the other post for the slot machine, and thought I'd take a quick shot at seeing how I'd come up with something like you suggested.  Wink

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 10, "ENTER TO SPIN! (You have $" + STR$(Money) + ")"
CenterText 140, "PAYOUTS"
CenterText 160, "Three Double Circles -- 500"
CenterText 180, "Three Squares -- 25"
CenterText 200, "Three Triangles -- 25"
CenterText 220, "Three Circles -- 25"
CenterText 240, "Two Circles -- 10"
CenterText 260, "Three Diamonds -- 10"
CenterText 280, "Two Diamonds -- 5"
CenterText 300, "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 = Slot(INT(RND * 32)): DrawSlot 0, slot1
IF spin2 > TIMER THEN slot2 = Slot(INT(RND * 32)): DrawSlot 1, slot2
IF spin3 > TIMER THEN slot3 = Slot(INT(RND * 32)): DrawSlot 2, slot3: finished = 0
_LIMIT 10
_DISPLAY
LOOP UNTIL finished
_AUTODISPLAY
win = -10 'the "ante" of $10 to spin.
IF slot1 = slot2 AND slot2 = slot3 THEN 'three of a kind!
SELECT CASE slot1
CASE 1: win = 250 '3 circles
CASE 2: win = 250 '3 triangles
CASE 3: win = 100 '3 diamonds
CASE 4: win = 5000 '3 double circles
CASE 5: win = 250 '3 squares
END SELECT
END IF
diamond = 0: circles = 0
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 slot2 = 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 250, "Sorry. No Match. You lose." ELSE CenterText 250, "Congrats! You win!"
Money = Money + win
_KEYCLEAR: SLEEP: _DELAY .5: _KEYCLEAR
LOOP

SUB DrawSlot (where, what)
LINE (10 + 110 * where, 50)-STEP(100, 100), Black, BF
w = 110 * where
SELECT CASE what
CASE 1: CircleFill 60 + w, 100, 50, Blue 'circle
CASE 2: FillTriangle 60 + w, 50, 10 + w, 150, 110 + w, 150, Yellow 'triangle
CASE 3: FillQuad 60 + w, 50, 10 + w, 100, 60 + w, 150, 110 + w, 100, Green 'diamond
CASE 4: CircleFill 60 + w, 100, 50, Red: CircleFill 60 + w, 100, 25, Yellow 'double circle
CASE 5: LINE (20 + 110 * where, 60)-STEP(80, 80), Gold, BF: 'square
END SELECT
END SUB

FUNCTION Slot (roll AS INTEGER)
SELECT CASE roll
CASE 0 TO 1: Slot = 1
CASE 1 TO 3: Slot = 2
CASE 3 TO 7: Slot = 5
CASE 7 TO 15: Slot = 4
CASE ELSE: Slot = 3
END SELECT
END FUNCTION

SUB CenterText (y, text$)
l = _PRINTWIDTH(text$)
w = _WIDTH
x = (w - l) \ 2
_PRINTSTRING (x, y), text$
END SUB

SUB FillTriangle (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
STATIC a&, m AS _MEM
IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32): m = _MEMIMAGE(a&)
_MEMPUT m, m.OFFSET, K
_MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
END SUB
SUB FillQuad (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
FillTriangle x1, y1, x2, y2, x3, y3, K
FillTriangle x3, y3, x4, y4, x1, y1, K
END SUB

SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
DIM Radius AS INTEGER, RadiusError AS INTEGER
DIM X AS INTEGER, Y AS INTEGER
Radius = ABS(R)
RadiusError = -Radius
X = Radius
Y = 0
IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
LINE (CX - X, CY)-(CX + X, CY), C, BF
WHILE X > Y
RadiusError = RadiusError + Y * 2 + 1
IF RadiusError >= 0 THEN
IF X <> Y + 1 THEN
LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
END IF
X = X - 1
RadiusError = RadiusError - X * 2
END IF
Y = Y + 1
LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
WEND
END SUB

About 120ish lines of code, and I don't think I missed anything out of the instructions. Did I?

I haven't looked to see how anyone else has tackled this task yet, as I wanted to give it a go all on my own, so I'm hoping I didn't hit too far off the mark. Wink
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: 5 Guest(s)