Created a nice software using SpiderBasic ? Post you link here !
Charlie
 
Posts: 22
Joined: Thu Jan 10, 2019 1:54 am
Location: New Brunswick, Canada

Acey Ducey à la SpiderBasic

by Charlie Fri Jan 03, 2020 10:08 pm

G'day all,

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()


Cheers, best regards, and HAPPY 2020 !!!
User avatar
Arbrakaan
 
Posts: 89
Joined: Mon Feb 24, 2014 10:54 pm
Location: Geneva

Re: Acey Ducey à la SpiderBasic

by Arbrakaan Fri Jan 03, 2020 11:35 pm

Nice game !
But, i'am not bery good at it... :)

Cheers,
User avatar
skywalk
 
Posts: 43
Joined: Tue Feb 25, 2014 2:13 am
Location: Boston, MA

Re: Acey Ducey à la SpiderBasic

by skywalk Sat Jan 04, 2020 3:06 am

Nice, change your spingadget to allow numeric entry. ;)
Code: Select all
gBet = SpinGadget(#PB_Any, 120, 425, 150, 50, 0, Q, #PB_Spin_Numeric)
When working toward the solution of a problem, it always helps if you know the answer. ~ ?
An expert is one who knows more and more about less and less until he knows absolutely everything about nothing. ~ Weber
Charlie
 
Posts: 22
Joined: Thu Jan 10, 2019 1:54 am
Location: New Brunswick, Canada

Re: Acey Ducey à la SpiderBasic

by Charlie Sat Jan 04, 2020 5:05 am

skywalk wrote:Nice, change your spingadget to allow numeric entry. ;)
Code: Select all
gBet = SpinGadget(#PB_Any, 120, 425, 150, 50, 0, Q, #PB_Spin_Numeric)


Yeah, I got shamefully lazy avoiding the few little extra lines to handle somebody betting more than $$$'s remaining. Way more user friendly to add that in there.

Thanks for the suggestion !

I just updated the app hosted over at Neocities as per the following 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
      BetValue = GetGadgetState(gBet)
      If BetValue > Q
        SetGadgetText(gMessage, "HEY BIG SPENDER, YOU CAN'T COVER THE BUCKS FOR THAT BET. TRY AGAIN!")
      Else
        HideGadget(gPlaceBet, 1)
        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
      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)

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()
Return to Showcase

Who is online

Users browsing this forum: No registered users and 1 guest