_TITLE "Blackjack B+ Johnno v 2020-06" ' started 2019-06-11 B+ as: BJ 1on1 DD w Images.bas ' Thanks to [banned user] for Card Image file.
' Fixes since BJ 1on1 wImages.bas 2019-06-09:
' + Fix label: Dealer must hit if es Total is < 17, not 16.
' + I added Double Down (DD) option, not just for Pete's sake.
' So for DD, I read BJ rules according to Hoyle, more fixes to those rules:
' + The 2nd card to Dealer is face down not first.
' + Blackjack pays 3:2 or 1.5 times bet, IF Dealer does not match = "push".
' + If player busts e loses immediately, no push if Dealer also busts.
' + After everyone gets 2 cards, Dealer looks to see if e has BJ, if so, shows it.
' + Splash Screen and introduction.
'BJ restart 2020-06-12 wow 1 year later w Johnno collaboration
' Punch List: from easy to hard
' + change chips type to _integer64 ;-)) done
' + larger stakes to start 1000 instead of 100 done
' + If player busts Dealer wins as everyone is familiar to this rule: this was done already!
' + Buttons controls like in Gin Rummy, OK done
' + Banking system charge interest on negative balances and pay interest on positive ones, sound fun? Done very basic
' + get done quickly so Johnno can work in assets, eh not so quick
' + fixed up new betting system that involves the bank file.
' 2020-06-13 post
'BJ v2020-06-13
' + add Johnno's image for splash screen (or table background?)
' + charge/pay player interest as soon as sign in again, along with Founder update
'BJ v2020-06-14
' + update acct at every change of chips count, so user cant cut all loses during session by X-out
' + start tracking dealer wins and losses too = wins and losses of house without Interest
' + Oh, oh, oh everybody starts at 0! so it's an automatic P&L statement
CONST xmax
= 900, ymax
= 640, white
= &HFFFFFFFF ' 40 lines CONST player
= 1 ' at the table
setbet
AS _INTEGER64 ' what's this again? a preset bet for all bets so not constantly queried about a bet amount now has limit of 1000 cardY
AS INTEGER ' graphic Y position for cards
DIM SHARED deck
(1 TO 52) AS CardType
, deckIndex
' deck and last card dealt
players(player).ID = "Player": players(player).cardY = 420
players(dealer).ID = "Dealer": players(dealer).cardY = 100
players
(dealer
).
name = "Dealer"
DIM i
, choice
, pick2$
(0 TO 2), pick3$
(0 TO 3) ' declare main variables pick2$(1) = "Hit": pick2$(2) = "Stand": pick2$(0) = "Quit"
pick3$(1) = "Hit": pick3$(2) = "Stand": pick3$(3) = "Double Down": pick3$(0) = "Quit"
GetStarted 'sets bColor to Johnno splash screen backcolor
IF players
(player
).setbet
= 0 THEN ' Get Bet (if not preset) ShowAndTell
10, "You have " + _TRIM$(STR$(players
(player
).chips
)) + " chips." LOCATE 11, 25:
INPUT "(0 quits) Enter your bet > ", players
(player
).bet
IF players
(player
).bet
= 0 THEN 'quits 'updateBankAcct players(player).name, players(player).chips should now be constantly updated
ELSEIF players
(player
).bet
> 1000 THEN 'you can bet up to half your chips IF players
(player
).chips
< 2000 THEN players(player).bet = 1000
ELSEIF players
(player
).bet
> .5 * players
(player
).chips
THEN 'half because player can Double Down players(player).bet = .5 * players(player).chips
ELSE 'using preset betting set at beginning of the game see GetStarted players(player).bet = players(player).setbet
ClearPlayers 'and screen
blockDealerCard = -1
FOR i
= 1 TO 2 ' 2 Cards for Each Player PlayerAddCard player
PlayerAddCard dealer
blockDealerCard = 0
IF players
(player
).Total
= 21 THEN ' Handle all the Blackjacks ShowAndTell 36, "Blackjack!"
IF players
(dealer
).Total
= 21 THEN ' Dealer BJ PlayerShow (dealer)
ShowAndTell 16, "Dealer has Blackjack!"
IF players
(player
).Total
<> 21 THEN players(player).chips = players(player).chips - players(player).bet
players(dealer).chips = players(dealer).chips + players(player).bet
roundUpdate
ShowAndTell
38, "You lose" + STR$(players
(player
).bet
) ShowAndTell 38, "Push, Dealer and Player have Blackjack."
IF players
(player
).Total
= 21 THEN ' Player BJ! pays 1.5 times bet players(player).chips = players(player).chips + 1.5 * players(player).bet
players(dealer).chips = players(dealer).chips - 1.5 * players(player).bet
roundUpdate
ShowAndTell
38, "You win" + STR$(1.5 * players
(player
).bet
) WHILE players
(player
).Total
< 21 ' Player's turn choice = getButtonNumberChoice%(pick3$())
choice = getButtonNumberChoice%(pick2$())
IF choice
= 1 THEN ' Hit Option PlayerAddCard player
players(player).bet = 2 * players(player).bet
PlayerAddCard player
'updateBankAcct players(player).name, players(player).chips should be updated after each round
IF players
(player
).Total
> 21 THEN ' Oops! busted ShowAndTell 36, "Busted!"
ShowAndTell
38, "You lost" + STR$(players
(player
).bet
) players(player).chips = players(player).chips - players(player).bet
players(dealer).chips = players(dealer).chips + players(player).bet
roundUpdate
PlayerShow dealer ' Dealer's Turn
WHILE players
(dealer
).Total
< 17 ShowAndTell 16, "Dealer takes a card."
PlayerAddCard dealer
IF players
(dealer
).Total
> 21 THEN 'busted Results Accounting ShowAndTell
38, "You won" + STR$(players
(player
).bet
) players(player).chips = players(player).chips + players(player).bet
players(dealer).chips = players(dealer).chips - players(player).bet
roundUpdate
ELSEIF players
(player
).Total
> players
(dealer
).Total
THEN ShowAndTell 38, "You won!"
players(player).chips = players(player).chips + players(player).bet
players(dealer).chips = players(dealer).chips - players(player).bet
roundUpdate
ELSEIF players
(player
).Total
< players
(dealer
).Total
THEN ShowAndTell
38, "You lost" + STR$(players
(player
).bet
) players(player).chips = players(player).chips - players(player).bet
players(dealer).chips = players(dealer).chips + players(player).bet
roundUpdate
ELSEIF players
(player
).Total
= players
(dealer
).Total
THEN ShowAndTell 38, "Push"
skip:
'IF players(player).chips = 0 THEN ShowAndTell 40, "Out of chips!"
'that's all folks the game ends when Player quits inside the main loop
IF LoadCardImages
= 0 THEN PRINT "PlayingCards.png failed to load, bye!":
END
'quick log in to get started with Bank to be developed more later
IF _FILEEXISTS("B+ Banking and Loan.txt") = 0 THEN ' get a file started to track player acounts fname$
= MID$(fline$
, 1, INSTR(fline$
, "$") - 1) nFound = 1
IF amount
< 0 THEN bankerFee
= .1 * ABS(amount
) ELSE bankerFee
= .05 * amount
'interest made by banker IF amount
< 0 THEN amount
= 1.1 * amount
ELSE amount
= 1.05 * amount
players(player).chips = amount
players(dealer).chips = amount
players(player).chips = 0
bankerFee = 0
updateBankAcct "Founder", Founder + bankerFee ' update banker's acct
updateBankAcct players
(player
).
name, players
(player
).chips
' update player acct InitDeck
ShowAndTell
6, "Welcome back to B+J Blackjack, " + name$
ShowAndTell
8, "The banker informs us you have a balance of " + _TRIM$(STR$(players
(player
).chips
)) ShowAndTell
3, "Welcome to B+ and Johnno's Game of Blackjack, " + name$
ShowAndTell 5, "An account has been setup for you at B+ Banking and Loan."
ShowAndTell 6, "Terms are 10% interest payments for negative balance and"
ShowAndTell 7, "5% interest paid to you for positive balance."
ShowAndTell 8, "Thankyou for banking with B+."
ShowAndTell 10, "The object of the game is to get to 21 or as close as possible without going over."
ShowAndTell 11, "You will need to get closer than dealer to win your bet (placed before cards are dealt)."
ShowAndTell 12, "An Ace counts as 1 or 11, points for 2-10 cards are 2-10, Jack, Queen, King are 10."
ShowAndTell 14, "Some Blackjack Terms:"
ShowAndTell 16, "Blackjack is getting a total of 21 with first 2 cards (an Ace and a 10 point card)."
ShowAndTell 17, "Blackjack pays 1.5 times the bet if the Dealer does not also have Blackjack."
ShowAndTell 18, "Hit is asking for another card."
ShowAndTell 19, "Stand is saying, no more cards."
ShowAndTell 20, "Double Down option occurs after 2nd card."
ShowAndTell 21, "Double Down is doubling your bet and getting just one more card."
ShowAndTell 22, "If 2 X Bet > Player's Chips, Bet will be Player's Chips."
ShowAndTell 23, "A Push is the same as a tie or a draw, no one loses."
ShowAndTell 25, "For this Blackjack Game, you start by owing bank -1000 chips."
ShowAndTell 26, "If you owe you can bet up to 1000. If have more than 2000, you can bet half of"
ShowAndTell 27, " any positive amount you have."
ShowAndTell 29, "If you'd like to set your bet for each round now, enter that Amount (<=1000),"
ShowAndTell 30, "otherwise, to place your bet before each round, enter 0 now."
ShowAndTell 32, ""
INPUT ""; players
(player
).setbet
IF players
(player
).setbet
> 1000 THEN players
(player
).setbet
= 1000
updateBankAcct players
(dealer
).
name, players
(dealer
).chips
updateBankAcct players
(player
).
name, players
(player
).chips
fname$
= MID$(fline$
, 1, INSTR(fline$
, "$") - 1) loadSort
name$
+ "$" + STR$(amount
), accts
() loadSort fline$, accts()
Shuffle
deckIndex = 0
players(i).hand = ""
players(i).Ace = 0
players(i).Total = 0
SUB PlayerAddCard
(receiver
) deckIndex = deckIndex + 1
players(receiver).hand = players(receiver).hand + D2$(deckIndex)
IF deck
(deckIndex
).value
= 1 THEN players
(receiver
).Ace
= -1 players(receiver).Total = 0
di
= VAL(MID$(players
(receiver
).hand
, i
, 2)) players(receiver).Total = players(receiver).Total + deck(di).points
IF players
(receiver
).Total
< 12 AND players
(receiver
).Ace
THEN players
(receiver
).Total
= players
(receiver
).Total
+ 10 PlayerShow receiver
FUNCTION D2$
(num
) 'we have to store 1 or 2 digit numbers in a string to represent hand that is buch of card indexes
ShowAndTell
1, STR$(players
(dealer
).chips
) ShowAndTell 2, "BLACKJACK: Dealer must Hit if House Total < 17, Blackjack pays 3:2 unless Push"
ShowAndTell 5, players(shower).ID
ShowAndTell
15, "Total =" + STR$(players
(shower
).Total
) IF players
(shower
).Total
> 21 THEN ShowAndTell
16, "Busted!" LINE (0, 320)-STEP(xmax
, 320), bColor
, BF
ShowAndTell
25, "Chips:" + STR$(players
(player
).chips
) + " Betting:" + STR$(players
(player
).bet
) + " chips." ShowAndTell 23, players(shower).ID
ShowAndTell
35, "Total =" + STR$(players
(shower
).Total
) IF players
(shower
).Total
> 21 THEN ShowAndTell
36, "Busted!" xoff
= (xmax
- 43 * LEN(players
(shower
).hand
)) / 2 di
= VAL(MID$(players
(shower
).hand
, i
, 2)) ShowCardDI xoff, players(shower).cardY, di
xoff = xoff + 86
IF shower
= dealer
AND blockDealerCard
AND LEN(players
(dealer
).hand
) = 4 THEN 'hide first card xoff = xoff - 86
ShowCard 2, xoff, players(dealer).cardY, 0, 4
ShowAndTell 15, " Total = ?? "
suit$(0) = "Hearts": suit$(1) = "Clubs": suit$(2) = "Diamonds": suit$(3) = "Spades"
v$(1) = "Ace": v$(11) = "Jack": v$(12) = "Queen": v$(13) = "King"
i = 0
i = i + 1
deck(i).ID = i
deck(i).cname = v$(v) + " of " + suit$(s)
deck(i).value = v
deck(i).suit = s
IF v
< 11 THEN deck
(i
).points
= v
ELSE deck
(i
).points
= 10
ShowCard 2, x, y, deck(deckI).value - 1, deck(deckI).suit
'at scale = 2 need screen space of 76 x 100 for one card
SUB ShowCard
(scale
, ScrnX
, ScrnY
, imageCol
, imageRow
) 'screen x, y h= horizontal , v =vertical image h, v ch = 38 * imageCol + 1: cv = 51 * imageRow + 1
_PUTIMAGE (ScrnX
, ScrnY
)-STEP(38 * scale
, 50 * scale
), cardDeck
, 0, (ch
, cv
)-(ch
+ 37, cv
+ 50)
LoadCardImages% = -1
'this sub uses drwBtn Const bColor for background
FUNCTION getButtonNumberChoice%
(choice$
()) 'developed for this app but likely can use as is elsewhere DIM ub
, s1
, b
, oldmouse
, mx
, my
, mb
s1
= (_WIDTH - (ub
+ 1) * 200 - ub
* 20) / 2 drwBtn b * 220 + s1, 270, choice$(b)
oldmouse = -1
IF mx
> b
* 220 + s1
AND mx
<= b
* 250 + s1
+ 200 THEN LINE (0, 265)-(_WIDTH, 330), bColor
, BF
'erase buttons
SUB drwBtn
(x
, y
, s$
) '200 x 50 const white = &hffffffff and bColor th
= 16: tw
= 8 * LEN(s$
): gray~&
= _RGB32(190, 190, 190)
SUB loadSort
(insertN
AS STRING, dynArr
() AS STRING) ' note this leaves dynArr(0) empty! so ubound of array is also number of items in list IF insertN
> dynArr
(j
) THEN ' GT to LT according to descending or ascending sort dynArr(k) = dynArr(k - 1)
dynArr(j) = insertN