import GUI in "%oot/lib/GUI"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Set the initial variables%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
type card :
record
suit : string
num : int
end record
var hitbutton : int
var deck : array 2 .. 53 of card %This array holds the 'cards'
var playercard1 : int
var standbutton : int
var playercard : string
var housecard : string
var font4 : int := Font.New ("Arial:24:bold,italic")
var font5 : int := Font.New ("Arial:24:bold,italic")
var font6 : int := Font.New ("Arial:20:bold,italic")
var pc3 : string %players third card
var amount : int := 2 %store the amount of times user has hit the button
var bet : int
var cpuamount : int := 1
var gotbet : boolean
var winfont : int := Font.New ("Arial:20:bold,italic")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%fills the array with cards uses a global parameter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc createDeck
for createcards : 2 .. 53
if createcards <= 14 then
deck (createcards).suit := "_Heart.jpg" %load the card suit and number
deck (createcards).num := createcards
elsif createcards > 14 and createcards <= 27 then
deck (createcards).suit := "_Diamond.jpg"
deck (createcards).num := createcards - 13
elsif createcards > 27 and createcards <= 40 then
deck (createcards).suit := "_Spade.jpg"
deck (createcards).num := createcards - 26
else
deck (createcards).suit := "_Club.jpg"
deck (createcards).num := createcards - 39
end if
end for
end createDeck
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Main Program%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%Set the screen%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var player : string
var playerMoney, houseMoney : real
var deal, total, totalp : int := 0
%Set window to the way I want it
%View.Set ("graphics:400;300,nomouse,title:BlackJack,nobuttonbar")
View.Set ("graphics:675;500,position:40,65,nobuttonbar,title:BlackJack")
colorback (green)
cls
color (white)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Get player's name and money%%%%%%%%%%%%%%%%%%%%%%%%%%%
put "Please enter your name"
get player
put "Enter the amount of money you are starting with"
get playerMoney
%setscreen ("offscreenonly")
cls
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%set the house start money
houseMoney := 10000
createDeck
randomize
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Deal House Cards%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure housedeal (var total : int, var housecard : string)
randint (deal, 2, 53)
total := total + deck (deal).num
housecard := intstr (deck (deal).num) + deck (deal).suit
if deck (deal).num < 11 then
total := total + deck (deal).num
elsif deck (deal).num = 11 then
total := totalp + 10
elsif deck (deal).num = 12 then
total := totalp + 10
elsif deck (deal).num = 13 then
total := totalp + 10
elsif deck (deal).num = 14 then
if total + 11 > 21 then
total := totalp + 1
else
total := totalp + 11
end if
else
total := total + deck (deal).num
end if
end housedeal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Deal Players cards%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure playerdeal (var totalp : int, var playercard : string)
randint (deal, 2, 53)
playercard := intstr (deck (deal).num) + deck (deal).suit
if deck (deal).num > 11 then
totalp := totalp + deck (deal).num
elsif deck (deal).num = 11 then
totalp := totalp + 10
elsif deck (deal).num = 12 then
totalp := totalp + 10
elsif deck (deal).num = 13 then
totalp := totalp + 10
elsif deck (deal).num = 14 then
if totalp + 11 > 21 then
totalp := totalp + 1
else
totalp := totalp + 11
end if
else
totalp := totalp + deck (deal).num
end if
end playerdeal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Draw first four cards
proc firstcards
playerdeal (totalp, playercard)
var playercard1pi := Pic.FileNew ("Images/" + playercard)
Pic.Draw (playercard1pi, 20, 25, picCopy)
locate (22, 64)
colorback (yellow)
put totalp
colorback (green)
playerdeal (totalp, playercard)
var playercard2pi := Pic.FileNew ("Images/" + playercard)
Pic.Draw (playercard2pi, 80, 25, picCopy)
locate (22, 64)
colorback (yellow)
put totalp
colorback (green)
housedeal (total, housecard)
var housecard1pi := Pic.FileNew ("Images/" + housecard)
Pic.Draw (housecard1pi, 380, 350, picCopy)
housedeal (total, housecard)
var houseback := Pic.FileNew ("Images/card_back.jpg")
Pic.Draw (houseback, 435, 350, picCopy)
end firstcards
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc startinfo
%locate the box to write in it
locate (13, 64)
colorback (yellow)
color (black)
%Show Computers money
put "Computers Money:"
locate (14, 64)
put "$", houseMoney
%Show Players money
locate (17, 64)
put player, "'s Money:"
locate (18, 64)
put "$", playerMoney
colorback (green)
drawfillbox (500, 95, 675, 320, yellow)
end startinfo
forward proc drawscreen
forward proc youloose
proc youwin
Font.Draw ("You beat the computer!", 50, 180, winfont, brightred)
playerMoney := playerMoney + bet
locate (18, 64)
colorback (yellow)
put "$", playerMoney
colorback (green)
View.Update
houseMoney := houseMoney - bet
locate (14, 64)
colorback (yellow)
put "$", houseMoney
colorback (green)
delay (1250)
cls
total := 0
totalp := 0
amount := 2
cpuamount := 1
drawscreen
end youwin
proc hit
gotbet := false
amount := amount + 1
randint (deal, 2, 53)
playercard := intstr (deck (deal).num) + deck (deal).suit
if deck (deal).num < 11 then
totalp := totalp + deck (deal).num
elsif deck (deal).num >= 10 then
totalp := totalp + deck (deal).num
elsif deck (deal).num = 11 then
totalp := totalp + 10
elsif deck (deal).num = 12 then
totalp := totalp + 10
elsif deck (deal).num = 13 then
totalp := totalp + 10
elsif deck (deal).num = 14 then
if totalp + 11 > 21 then
totalp := totalp + 1
else
totalp := totalp + 11
end if
end if
locate (22, 64)
colorback (yellow)
put totalp
colorback (green)
playerdeal (totalp, playercard)
if amount = 3 then
var playercard3pi := Pic.FileNew ("Images/" + playercard)
Pic.Draw (playercard3pi, 120, 25, picCopy)
end if
if amount = 4 then
playerdeal (totalp, playercard)
var playercard4pi := Pic.FileNew ("Images/" + playercard)
Pic.Draw (playercard4pi, 160, 25, picCopy)
end if
if totalp > 21 then
Font.Draw ("You Went over 21, you lose", 50, 180, font4, brightred)
youloose
end if
end hit
forward proc stand
forward proc getbet
body proc drawscreen
total := 0
totalp := 0
colorback (green)
drawfillbox (500, 95, 675, 320, yellow)
colorback (green)
Font.Draw ("Your Bet:", 300, 45, font5, brightblue)
colorback (yellow)
locate (21, 64)
color (black)
put "Your Total:"
locate (22, 64)
put totalp
locate (13, 64)
put "Computers Money:"
locate (14, 64)
put "$", houseMoney
%Show Players money
locate (17, 64)
put player, "'s Money:"
locate (18, 64)
put "$", playerMoney
Font.Draw ("Your Bet:", 300, 45, font5, brightblue)
firstcards
hitbutton := GUI.CreateButton (541, 475, 0, "Hit", hit)
standbutton := GUI.CreateButton (590, 475, 0, "Stand", stand)
getbet
end drawscreen
body proc youloose
Font.Draw ("You Went over 21, you lose", 50, 180, font4, brightred)
playerMoney := playerMoney - bet
locate (18, 64)
colorback (yellow)
put "$", playerMoney
colorback (green)
View.Update
houseMoney := houseMoney + bet
locate (14, 64)
colorback (yellow)
put "$", houseMoney
colorback (green)
delay (450)
cls
total := 0
totalp := 0
amount := 2
cpuamount := 1
drawscreen
end youloose
proc checkwinner
if total > 21 then
youwin
elsif totalp > 21 then
youloose
elsif totalp > total and totalp <= 21 then
youwin
elsif total > totalp and total <= 21 then
youloose
end if
end checkwinner
body proc stand
cpuamount := 2 %mabey +1
randint (deal, 2, 53)
housecard := intstr (deck (deal).num) + deck (deal).suit
if deck (deal).num < 11 then
total := total + deck (deal).num
elsif deck (deal).num < 11 then
total := total + deck (deal).num
elsif deck (deal).num = 11 then
total := totalp + 10
elsif deck (deal).num = 12 then
total := totalp + 10
elsif deck (deal).num = 13 then
total := totalp + 10
elsif deck (deal).num = 14 then
if total + 11 > 21 then
total := total + 1
else
total := total + 11
end if
else
total := total + deck (deal).num
end if
if cpuamount = 2 then
var housecard2pi := Pic.FileNew ("Images/" + housecard)
Pic.Draw (housecard2pi, 435, 350, picCopy)
cpuamount := 2
end if
if cpuamount >= 2 and total < 17 then
housedeal (total, housecard)
var housecard3pi := Pic.FileNew ("Images/" + housecard)
Pic.Draw (housecard3pi, 458, 350, picCopy)
cpuamount := 3
end if
if cpuamount = 3 and total < 17 then
housedeal (total, housecard)
var housecard4pi := Pic.FileNew ("Images/" + housecard)
Pic.Draw (housecard4pi, 468, 350, picCopy)
cpuamount := cpuamount + 1
end if
if total >= 17 then
checkwinner
end if
end stand
proc firstdrawscreen
colorback (green)
drawfillbox (500, 95, 675, 320, yellow)
colorback (green)
Font.Draw ("Your Bet:", 300, 45, font5, brightblue)
colorback (yellow)
locate (21, 64)
color (black)
put "Your Total:"
locate (22, 64)
put totalp
locate (13, 64)
put "Computers Money:"
locate (14, 64)
put "$", houseMoney
%Show Players money
locate (17, 64)
put player, "'s Money:"
locate (18, 64)
put "$", playerMoney
Font.Draw ("Your Bet:", 300, 45, font5, brightblue)
hitbutton := GUI.CreateButton (541, 475, 0, "Hit", hit)
standbutton := GUI.CreateButton (590, 475, 0, "Stand", stand)
end firstdrawscreen
locate (21, 64)
color (black)
colorback (yellow)
put "Your Total:"
locate (22, 64)
put totalp
body proc getbet
loop
Font.Draw ("Your Bet:", 300, 45, font5, brightblue)
colorback (green)
locate (29, 60)
get bet
if bet > playerMoney then
Font.Draw ("invalid bet!", 50, 180, font6, red)
delay (450)
Font.Draw ("invalid bet!", 50, 180, font6, green)
locate (29, 60)
put ""
else
bet := bet
gotbet := true
exit
end if
end loop
end getbet
%%%%%%%%%%%%%%%%Main Program%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
firstcards
getbet
firstdrawscreen
if gotbet = true then
loop
exit when GUI.ProcessEvent
end loop
end if
|