I felt like some easy-on-the-old-sponge playtime programming, so I decided to refactor this vintage code to create a SpiderBasic version of the classic Acey Ducey game.
Nothing particularly fancy. Here's my no-frills source code:
Code: Select all
Global.i gCard1,gCard2,gCard3,gPlaceBet,gBet,gDeal,gMain,gMessage,gStack
Global.i A, B, C, Q
Procedure.s GetCardLabel( Card.i )
CardLabel.s
Select Card
Case 11
CardLabel = "J"
Case 12
CardLabel = "Q"
Case 13
CardLabel = "K"
Case 14
CardLabel = "A"
Default
CardLabel = "" + Card
EndSelect
ProcedureReturn CardLabel
EndProcedure
Procedure GetTwoCards()
A = 0
B = 0
While A<2 Or B<2 Or A>=B Or B-A = 1
A=Random(14,2)
B=Random(14,2)
Wend
SetGadgetText(gCard1, GetCardLabel(A) )
SetGadgetText(gCard2, GetCardLabel(B) )
EndProcedure
Procedure ButtonHandler()
BetValue.i
Select EventGadget()
Case gPlaceBet
HideGadget(gPlaceBet, 1)
BetValue = GetGadgetState(gBet)
If BetValue = 0
SetGadgetText(gMessage, "CHICKEN !")
Else
C=Random(14,2)
SetGadgetColor(gCard3, #PB_Gadget_BackColor, RGB(255, 255, 200))
SetGadgetText(gCard3, GetCardLabel(C))
If C > A And C < B
SetGadgetText(gMessage, "YOU WIN !")
Q = Q + BetValue
Else
SetGadgetText(gMessage, "YOU LOSE !")
Q = Q - BetValue
EndIf
SetGadgetText(gStack, "$ " + Q )
EndIf
HideGadget(gDeal, 0)
If Q = 0
DisableGadget(gDeal, 1)
SetGadgetText(gDeal, "SORRY, FRIEND, BUT YOU BLEW YOUR WAD.")
Else
HideGadget(gDeal, 0)
SetGadgetAttribute(gBet, #PB_Spin_Maximum, Q)
EndIf
Case gDeal
SetGadgetText(gMessage, "")
HideGadget(gPlaceBet, 0)
HideGadget(gDeal, 1)
SetGadgetText(gCard3, "")
SetGadgetColor(gCard3, #PB_Gadget_BackColor, RGB(0, 0, 200))
GetTwoCards()
EndSelect
EndProcedure
Procedure DesktopSizeHandler()
ResizeWindow(gMain, 1, 1, #PB_Ignore, #PB_Ignore)
EndProcedure
Q=100
gMain = OpenWindow(#PB_Any, 0, 0, 380, 650, "Acey Deucey.SB", #PB_Window_ScreenCentered )
TextGadget(#PB_Any, 10, 10, 360, 20, "THE ACEY DUCEY CARD GAME", #PB_Text_Center)
TextGadget(#PB_Any, 10, 30, 360, 20, "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY", #PB_Text_Center)
TextGadget(#PB_Any, 10, 50, 360, 20, "SpiderBasic Version by CJ Veniot", #PB_Text_Center)
TextGadget(#PB_Any, 10, 90, 360, 20, "ACEY DUCEY IS PLAYED IN THE FOLLOWING MANNER:", #PB_Text_Center)
TextGadget(#PB_Any, 10, 110, 360, 20, "THE DEALER (COMPUTER) DEALS TWO CARDS FACE UP", #PB_Text_Center)
TextGadget(#PB_Any, 10, 130, 360, 20, "YOU HAVE AN OPTION TO BET OR NOT BET DEPENDING", #PB_Text_Center)
TextGadget(#PB_Any, 10, 150, 360, 20, "ON WHETHER OR NOT YOU FEEL THE THIRD CARD", #PB_Text_Center)
TextGadget(#PB_Any, 10, 170, 360, 20, "WILL HAVE A VALUE BETWEEN THE FIRST TWO.", #PB_Text_Center)
TextGadget(#PB_Any, 10, 190, 360, 20, "IF YOU DO NOT WANT TO BET, SET THE BET AMOUNT = 0", #PB_Text_Center)
TextGadget(#PB_Any, 10, 235, 110, 50, "YOU NOW HAVE:", #PB_Text_VerticalCenter)
gStack = TextGadget(#PB_Any, 120, 235, 150, 50, "$ 100", #PB_Text_Center | #PB_Text_VerticalCenter | #PB_Text_Border)
TextGadget(#PB_Any, 10, 305, 110, 100, "YOUR CARDS:", #PB_Text_VerticalCenter)
gCard1 = TextGadget(#PB_Any, 120, 305, 75, 100, "", #PB_Text_Center | #PB_Text_VerticalCenter | #PB_Text_Border)
gCard3 = TextGadget(#PB_Any, 205, 305, 75, 100, "", #PB_Text_Center | #PB_Text_VerticalCenter | #PB_Text_Border)
gCard2 = TextGadget(#PB_Any, 290, 305, 75, 100, "", #PB_Text_Center | #PB_Text_VerticalCenter | #PB_Text_Border)
SetGadgetColor(gCard1, #PB_Gadget_BackColor, RGB(255, 255, 200))
SetGadgetColor(gCard2, #PB_Gadget_BackColor, RGB(255, 255, 200))
SetGadgetColor(gCard3, #PB_Gadget_BackColor, RGB(0, 0, 200))
TextGadget(#PB_Any, 10, 425, 110, 50, "YOUR BET:", #PB_Text_VerticalCenter )
gBet = SpinGadget(#PB_Any, 120, 425, 150, 50, 0, Q, #PB_Spin_ReadOnly)
gMessage = TextGadget(#PB_Any, 10, 480, 360, 50, "", #PB_Text_Center | #PB_Text_VerticalCenter )
gPlaceBet = ButtonGadget(#PB_Any, 10, 530, 360, 75, "BET !")
gDeal = ButtonGadget(#PB_Any, 10, 530, 360, 75, "OK, DEAL ANOTHER ROUND.", #PB_Button_MultiLine)
HideGadget(gDeal, 1)
LoadFont(0, "arial", 18, #PB_Font_Bold)
SetGadgetFont(gStack, FontID(0))
SetGadgetFont(gCard1, FontID(0))
SetGadgetFont(gCard2, FontID(0))
SetGadgetFont(gCard3, FontID(0))
SetGadgetFont(gBet, FontID(0))
SetGadgetFont(gMessage, FontID(0))
SetGadgetFont(gPlaceBet, FontID(0))
SetGadgetFont(gDeal, FontID(0))
BindGadgetEvent(gPlaceBet, @ButtonHandler())
BindGadgetEvent(gDeal, @ButtonHandler())
BindEvent(#PB_Event_SizeDesktop, @DesktopSizeHandler() )
GetTwoCards()