Rem ----------------------------------------------
Rem ------------------BlackJack-------------------
REM --------By Robert --------
Rem ----------------------------------------------
`Main Screen
`play or rules
do
if makebutton(275,240,"Play")>0 then buttonselected=1
if makebutton(365,240,"Rules")>0 then buttonselected=2
if buttonselected=1 then goto welcome
if buttonselected=2
ink rgb(255,255,255),0
center text 320,300,"RULES"
center text 320,350,"When the game starts select 'hit' or 'stand'"
center text 320,370,"If you click 'hit' you take another random card"
center text 320,390,"If you click 'stand' your opponent takes another random card"
center text 320,410,"The aim of the game is to get your cards to add up to 21"
center text 320,430,"But if your opponent gets to 21 first, you lose"
center text 320,460,"[click on the play button to start]"
endif
sync
LOAD BITMAP "F:\Game Design Development II\Cards\background.jpg"
sync off
loop
function makebutton(x,y,desc$)
buttonpressed=0
ink rgb(128,0,0),0 : box x-42,y-14,x+42,y+14
ink rgb(225,0,0),0 : box x-40,y-12,x+40,y+12
ink rgb(0,0,0),0
myx=mousex() : myy=mousey()
if myx>x-40 and myx<x+40
if myy>y-12 and myy<y+12
buttonpressed=1
endif
endif
if buttonpressed=1 then ink rgb(255,255,0),0
set text size 18 : center text x,y-8,desc$
if mouseclick()=0 then buttonpressed=0
endfunction buttonpressed
Welcome:
pathRoot$ = GET DIR$()
pathCards$ = "Cards"
set text font "Arial"
ink rgb(255,255,255),rgb(255,255,255)
set text to bold
set text size 14
randomize timer()
GOSUB Load_Strips
Game:
DO
LOAD BITMAP "F:\Game Design Development II\Cards\background.jpg"
center text 320,40, "Press T to start game"
text 32,15, "AI Score: "+str$(valTOTALE)
text 32,25, "Your Score: "+str$(valTOTAL)
center text 320,80, "AI Cards"
center text 320,250, "Your Cards"
`-----------MAKE BUTTON (T)------------
if keystate(20) > 0 and T_BUT = 0 then T_BUT = 1
if T_BUT = 1
T_BUT = 2
REM PLAYER
rows = rnd(13)
card = rnd(4) * 100
if rows = 0 or card = 0
if rows < 1 then rows = 1
if card < 100 then card = 100
endif
REM ENEMY
rowsE = rnd(13)
cardE = rnd(4) * 100
if rowsE = 0 or cardE = 0
if rowsE < 1 then rowsE = 1
if cardE < 100 then cardE = 100
endif
inc BUT_T, 1
if BUT_T > 9 then BUT_T = 0
endif
if keystate(20) = 0 then T_BUT = 0
if BUT_T = 1
if sprite exist(card+rows) > 0
sprOne = card+rows
if rows => 10
valOne = 10
else
valOne = rows
endif
endif
endif
IF BUT_T = 2
if sprite exist(cardE+rowsE) > 0
sprOneE = cardE+rowsE
if rowsE => 10
valOneE = 10
else
valOneE = rowsE
endif
endif
endif
if BUT_T = 3
if sprite exist(card+rows) > 0
sprTwo = card+rows
if rows => 10
valTwo = 10
else
valTwo = rows
endif
endif
endif
IF BUT_T = 4
if sprite exist(cardE+rowsE) > 0
sprTwoE = cardE+rowsE
if rowsE => 10
valTwoE = 10
else
valTwoE = rowsE
endif
endif
endif
if BUT_T = 5
if sprite exist(card+rows) > 0
sprThree = card+rows
if rows => 10
valThree = 10
else
valThree = rows
endif
endif
endif
IF BUT_T = 6
if sprite exist(cardE+rowsE) > 0
sprThreeE = cardE+rowsE
if rowsE => 10
valThreeE = 10
else
valThreeE = rowsE
endif
endif
endif
if BUT_T = 7
if sprite exist(card+rows) > 0
sprFour = card+rows
if rows => 10
valFour = 10
else
valFour = rows
endif
endif
endif
IF BUT_T = 8
if sprite exist(cardE+rowsE) > 0
sprFourE = cardE+rowsE
if rowsE => 10
valFourE = 10
else
valFourE = rowsE
endif
endif
endif
if BUT_T = 9
T_BUT = 0
BUT_T = 0
sprOne = 0
sprTwo = 0
sprThree = 0
sprFour = 0
valOne = 0
valTwo = 0
valThree = 0
valFour = 0
valTOTAL = 0
sprOneE = 0
sprTwoE = 0
sprThreeE = 0
sprFourE = 0
valOneE = 0
valTwoE = 0
valThreeE = 0
valFourE = 0
valTOTALE = 0
endif
valTOTAL = valOne + valTwo + valThree + valFour
valTOTALE = valOneE + valTwoE + valThreeE + valFourE
if valTOTAL < 21 and valTOTAL < 21
if valTOTAL < 21
if sprOne > 0 then PASTE SPRITE sprOne, 100, 300
if sprTwo > 0 then PASTE SPRITE sprTwo, 200, 300
if sprThree > 0 then PASTE SPRITE sprThree, 300, 300
if sprFour > 0 then PASTE SPRITE sprFour, 400, 300
endif
if valTOTALE < 21
if sprOneE > 0 then PASTE SPRITE sprOneE, 100, 100
if sprTwoE > 0 then PASTE SPRITE sprTwoE, 200, 100
if sprThreeE > 0 then PASTE SPRITE sprThreeE, 300, 100
if sprFourE > 0 then PASTE SPRITE sprFourE, 400, 100
endif
If ValTOTAL = 21
center Text 320,200, "You Win!"
center text 320,220,"Press Any key to restart"
GOTO Game
endif
If ValTOTAL => 21
Center Text 320,200, "You Lose!"
Center Text 320,220, "Press Any key to restart"
GOTO Game
endif
If ValTOTALE = 21
center Text 320,200, "You Lose!"
center text 320,220,"Press Any key to restart"
GOTO Game
endif
If ValTOTALE > 21
Center Text 320,200, "You Win!"
Center Text 320,220, "Press Any key to restart"
GOTO Game
endif
IF VALTOTAL > 21
IF VALTOTALE > 21
center text 320,200, "It's a Tie!"
endif
endif
else
T_BUT = 0
BUT_T = 0
valOne = 0
valTwo = 0
valThree = 0
valFour = 0
valTOTAL = 0
sprOne = 0 : sprTwo = 0 : sprThree = 0 : sprFour = 0
T_BUT = 0
BUT_T = 0
valOneE = 0
valTwoE = 0
valThreeE = 0
valFourE = 0
valTOTALE = 0
sprOneE = 0 : sprTwoE = 0 : sprThreeE = 0 : sprFourE = 0
endif
SYNC
loop
Load_Strips:
`-----------LOAD IMAGES-----------
clubs = 100
diamonds = 200
hearts = 300
spades = 400
imgWidth = 71
imgHeight = 96
imgSeperate = 1
LOAD BITMAP "F:\Game Design Development II\Cards\cards_clubs.png", clubs
for s = 1 to 13
GET IMAGE clubs+s, imgSeperate+(s-1)*imgWidth, imgSeperate, imgWidth+(s-1)*imgWidth, imgHeight
SPRITE clubs+s, 0, 0, clubs+s : HIDE SPRITE clubs+s
next s
DELETE BITMAP clubs
LOAD BITMAP "F:\Game Design Development II\Cards\cards_diamonds.png", diamonds
for s = 1 to 13
GET IMAGE diamonds+s, imgSeperate+(s-1)*imgWidth, imgSeperate, imgWidth+(s-1)*imgWidth, imgHeight
SPRITE diamonds+s, 0, 0, diamonds+s : HIDE SPRITE diamonds+s
next s
DELETE BITMAP diamonds
LOAD BITMAP "F:\Game Design Development II\Cards\cards_hearts.png", hearts
for s = 1 to 13
GET IMAGE hearts+s, imgSeperate+(s-1)*imgWidth, imgSeperate, imgWidth+(s-1)*imgWidth, imgHeight
SPRITE hearts+s, 0, 0, hearts+s : HIDE SPRITE hearts+s
next s
DELETE BITMAP hearts
LOAD BITMAP "F:\Game Design Development II\Cards\cards_spades.png", spades
for s = 1 to 13
GET IMAGE spades+s, imgSeperate+(s-1)*imgWidth, imgSeperate, imgWidth+(s-1)*imgWidth, imgHeight
SPRITE spades+s, 0, 0, spades+s : HIDE SPRITE spades+s
next s
DELETE BITMAP spades
`---------SET SPRITE PROPERTIES-----------
for spr = clubs to spades+13
if sprite exist (spr)
SET SPRITE spr, 1, 0
endif
next spr
SET DIR pathRoot$
RETURN
When I play the game, only sometimes does it give me the win/loss ending before restarting the hand. It sometimes just ends the loop and goes straight to a new hand without giving me a popup telling me that I won or lost.
When it runs, whenever you or the AI reaches 21 it's supposed to tell you if you won or lost. Meanwhile the same is supposed to apply if you or the AI go over 21, it's supposed to tell you if you won or lost. However, I've noticed that it'll restart the game if both the player and AI go over 21 or if just the player goes over 21, it won't tell me that I've lost, instead it just restarts the game.
Also, I have another issue. When the player either wins or loses, if theres only 3 cards on the screen for each player, instead of restarting the loop like it should, it continues to play the hand. How would I fix this? Every attempt I've tried either causes the program to stop working or the game doesn't sync and the scores from multiple hands starts to pile up.