Computer Science Canada

BlackJack >. HELP ME I SUCK AT PROGRAMMING

Author:  putz33 [ Tue Dec 11, 2007 11:41 am ]
Post subject:  BlackJack >. HELP ME I SUCK AT PROGRAMMING

%Mark Wallis
%October 22nd 2007
%Black Jack
import GUI in "%oot/lib/GUI"
setscreen ("graphics:600;384")

var drandCard, drandCard2, drandCard3, drandCard4, randCard, randCard2,
randCard3 : int
:= 0
var dealerscore : int
var score : int
var z : int := 250
var name : string
var hscore : int := 0

procedure Intro
drawfillbox (0, 0, 600, 600, white)
Pic.ScreenLoad ("blackjacktext.bmp", 200, 80, picCopy)
Pic.ScreenLoad ("1clubs.bmp", 0, 0, picCopy)
Pic.ScreenLoad ("2clubs.bmp", 14, 0, picCopy)
Pic.ScreenLoad ("3clubs.bmp", 28, 0, picCopy)
Pic.ScreenLoad ("4clubs.bmp", 42, 0, picCopy)
Pic.ScreenLoad ("5clubs.bmp", 56, 0, picCopy)
Pic.ScreenLoad ("6clubs.bmp", 70, 0, picCopy)
Pic.ScreenLoad ("7clubs.bmp", 84, 0, picCopy)
Pic.ScreenLoad ("8clubs.bmp", 98, 0, picCopy)
Pic.ScreenLoad ("9clubs.bmp", 112, 0, picCopy)
Pic.ScreenLoad ("10clubs.bmp", 126, 0, picCopy)
Pic.ScreenLoad ("11clubs.bmp", 140, 0, picCopy)
Pic.ScreenLoad ("12clubs.bmp", 154, 0, picCopy)
Pic.ScreenLoad ("0clubs.bmp", 168, 0, picCopy)

delay (300)

Pic.ScreenLoad ("1spade.bmp", 0, 96, picCopy)
Pic.ScreenLoad ("2spade.bmp", 14, 96, picCopy)
Pic.ScreenLoad ("3spade.bmp", 28, 96, picCopy)
Pic.ScreenLoad ("4spade.bmp", 42, 96, picCopy)
Pic.ScreenLoad ("5spade.bmp", 56, 96, picCopy)
Pic.ScreenLoad ("6spade.bmp", 70, 96, picCopy)
Pic.ScreenLoad ("7spade.bmp", 84, 96, picCopy)
Pic.ScreenLoad ("8spade.bmp", 98, 96, picCopy)
Pic.ScreenLoad ("9spade.bmp", 112, 96, picCopy)
Pic.ScreenLoad ("10spade.bmp", 126, 96, picCopy)
Pic.ScreenLoad ("11spade.bmp", 140, 96, picCopy)
Pic.ScreenLoad ("12spade.bmp", 154, 96, picCopy)
Pic.ScreenLoad ("0spade.bmp", 168, 96, picCopy)

delay (300)

Pic.ScreenLoad ("1Diamond.bmp", 0, 192, picCopy)
Pic.ScreenLoad ("2Diamond.bmp", 14, 192, picCopy)
Pic.ScreenLoad ("3Diamond.bmp", 28, 192, picCopy)
Pic.ScreenLoad ("4Diamond.bmp", 42, 192, picCopy)
Pic.ScreenLoad ("5Diamond.bmp", 56, 192, picCopy)
Pic.ScreenLoad ("6Diamond.bmp", 70, 192, picCopy)
Pic.ScreenLoad ("7Diamond.bmp", 84, 192, picCopy)
Pic.ScreenLoad ("8Diamond.bmp", 98, 192, picCopy)
Pic.ScreenLoad ("9Diamond.bmp", 112, 192, picCopy)
Pic.ScreenLoad ("10Diamond.bmp", 126, 192, picCopy)
Pic.ScreenLoad ("11Diamond.bmp", 140, 192, picCopy)
Pic.ScreenLoad ("12Diamond.bmp", 154, 192, picCopy)
Pic.ScreenLoad ("0Diamond.bmp", 168, 192, picCopy)

delay (300)

Pic.ScreenLoad ("1heart.bmp", 0, 288, picCopy)
Pic.ScreenLoad ("2heart.bmp", 14, 288, picCopy)
Pic.ScreenLoad ("3heart.bmp", 28, 288, picCopy)
Pic.ScreenLoad ("4heart.bmp", 42, 288, picCopy)
Pic.ScreenLoad ("5heart.bmp", 56, 288, picCopy)
Pic.ScreenLoad ("6heart.bmp", 70, 288, picCopy)
Pic.ScreenLoad ("7heart.bmp", 84, 288, picCopy)
Pic.ScreenLoad ("8heart.bmp", 98, 288, picCopy)
Pic.ScreenLoad ("9heart.bmp", 112, 288, picCopy)
Pic.ScreenLoad ("10heart.bmp", 126, 288, picCopy)
Pic.ScreenLoad ("11heart.bmp", 140, 288, picCopy)
Pic.ScreenLoad ("12heart.bmp", 154, 288, picCopy)
Pic.ScreenLoad ("0heart.bmp", 168, 288, picCopy)


delay (3000)
cls
drawfillbox (0, 0, 600, 600, 0)
end Intro

%- Intro
drawfillbox (0, 0, 800, 500, green)
locate (16, 19)
put "Enter your name: " ..
get name
setscreen ("graphics:800;500")
drawfillbox (0, 0, 800, 500, green)

type cardType :
record
suit : string
value : int
dealt : boolean
pic : string
end record

var cards : array 1 .. 52 of cardType


for x : 1 .. 52
cards (x).dealt := false

if x >= 1 and x <= 13 then
cards (x).suit := "clubs"
cards (x).pic := intstr (x mod 13) + "clubs.bmp"
if x >= 2 and x <= 10 then
cards (x).value := x
elsif x = 1 then
cards (x).value := 11
elsif x >= 11 and x <= 13 then
cards (x).value := 10
end if
end if
if x >= 14 and x <= 26 then
cards (x).suit := "spades"
cards (x).pic := intstr (x mod 13) + "spade.bmp"
if x >= 15 and x <= 23 then
cards (x).value := x mod 13
elsif x = 14 then
cards (x).value := 11
elsif x >= 24 and x <= 26 then
cards (x).value := 10

end if
end if
if x >= 27 and x <= 39 then
cards (x).suit := "diamonds"
cards (x).pic := intstr (x mod 13) + "Diamond.bmp"
if x >= 28 and x <= 36 then
cards (x).value := x mod 13
elsif x = 27 then
cards (x).value := 11
elsif x >= 37 and x <= 39 then
cards (x).value := 10

end if
end if
if x >= 40 and x <= 52 then
cards (x).suit := "hearts"
cards (x).pic := intstr (x mod 13) + "heart.bmp"
if x >= 41 and x <= 49 then
cards (x).value := x mod 13
elsif x = 40 then
cards (x).value := 11
elsif x >= 49 and x <= 52 then
cards (x).value := 10
end if
end if
end for


%- procedure DealerRandomCard
loop
randint (drandCard, 1, 52)
if cards (drandCard).dealt = false then
Pic.ScreenLoad ("guy.bmp", 100, 400, picCopy)
cards (drandCard).dealt := true
exit
end if
end loop
loop
randint (drandCard2, 1, 52)
if cards (drandCard2).dealt = false then
Pic.ScreenLoad (cards (drandCard2).pic, 200, 400, picCopy)
cards (drandCard2).dealt := true
exit
end if
end loop


dealerscore := cards (drandCard2).value

locate (10, 1)
put "Dealerscore : ", dealerscore

%- end DealerRandomCard
%-
%- DealerRandomCard


%- procedure RandomCard

loop
randint (randCard, 1, 52)
if cards (randCard).dealt = false then
Pic.ScreenLoad (cards (randCard).pic, 100, 100, picCopy)
cards (randCard).dealt := true
exit
end if
end loop

loop
randint (randCard2, 1, 52)
if cards (randCard2).dealt = false then
Pic.ScreenLoad (cards (randCard2).pic, 200, 100, picCopy)
cards (randCard2).dealt := true
exit
end if
end loop


%- end RandomCard
%- RandomCard

score := cards (randCard).value + cards (randCard2).value

locate (40, 1)

put "Score : ", score

if score = 21 then
locate (15, 5)
put "Black Jack! You Win"
hscore := hscore + 1
end if

procedure Hitme
randCard := 0

var y : int := 0

z := z + 50

randint (randCard, 1, 52)

Pic.ScreenLoad (cards (randCard).pic, z, 100, picCopy)

score := score + cards (randCard).value

if score > 21 then
locate (15, 5)
put "You Bust!!"
Pic.ScreenLoad (cards (drandCard).pic, 100, 400, picCopy)

elsif score = 21 then
locate (17, 10)
put "Blackjack, you win!"
hscore := hscore + 1
end if

locate (40, 1)
put "Score : ", score

end Hitme

procedure Stay

Pic.ScreenLoad (cards (drandCard).pic, 100, 400, picCopy)

dealerscore := dealerscore + cards (drandCard).value
locate (10, 1)
put "Dealer Score : ", dealerscore
if dealerscore <= 15 then
loop
randint (drandCard3, 1, 52)
if cards (drandCard3).dealt = false then
Pic.ScreenLoad (cards (drandCard3).pic, 300, 400, picCopy)
cards (drandCard3).dealt := true
exit
end if
end loop

dealerscore := dealerscore + cards (drandCard3).value
end if

if dealerscore <= 15 then
loop
randint (drandCard4, 1, 52)
if cards (drandCard4).dealt = false then
Pic.ScreenLoad (cards (drandCard4).pic, 400, 400, picCopy)
cards (drandCard4).dealt := true
exit
end if
end loop

dealerscore := dealerscore + cards (drandCard4).value
end if

if dealerscore > 21 then
locate (17, 10)
put "Dealer BUST!!"
hscore:=hscore+1
elsif dealerscore = 21 then
locate (11, 1)
put "Black Jack!! Dealer wins"
locate (15, 5)
put "Dealer's Score : ", dealerscore
else
locate (10, 1)
put "Dealer's Score : ", dealerscore
end if

if score = dealerscore then
locate (17, 10)
put "Tie"
end if

if dealerscore > score and dealerscore < 21 then
locate (15, 5)
put "Dealer Wins!"
end if

if score > dealerscore and score < 21 then
locate (15, 5)
put "You Win!"
hscore := hscore + 1
end if



end Stay

procedure AceValueOne
if cards (randCard).value = 11 then
cards (randCard).value := 1
cards (randCard2).value := 1
score := score - 11 + cards (randCard).value
locate (40, 1)
drawfillbox (0, 0, 200, 40, green)
put "Score : ", score
end if

if cards (randCard2).value = 11 then
cards (randCard2).value := 1
score := score - 11 + cards (randCard2).value
locate (40, 1)
drawfillbox (0, 0, 200, 40, green)
put "Score : ", score
end if
end AceValueOne

procedure AceValueEleven
if cards (randCard).value = 1 then
cards (randCard).value := 10
score := score + cards (randCard).value
locate (40, 1)
drawfillbox (0, 0, 200, 40, green)
put "Score : ", score
end if

if cards (randCard2).value = 1 then
cards (randCard2).value := 10
score := score + cards (randCard2).value
locate (40, 1)
drawfillbox (0, 0, 200, 40, green)
put "Score : ", score
end if
end AceValueEleven

procedure highScore
drawfillbox (0, 0, 800, 800, green)
Pic.ScreenLoad ("HighScore.bmp", 200, 400, picMerge)
locate (10, 20)
put "|Player| |Score|"
put " "
put " "
locate (15, 20)
put name," ",hscore
end highScore




var b : int := GUI.CreateButton (10, 100, 0, "Hit me", Hitme)

var c : int := GUI.CreateButton (10, 50, 0, "Stay", Stay)

var d : int := GUI.CreateButton (100, 50, 0, "Ace value 1", AceValueOne)

var e : int := GUI.CreateButton (200, 50, 0, "Ace value 11",
AceValueEleven)
var f : int := GUI.CreateButton (300, 50, 0, "HighScore", highScore)



loop
exit when GUI.ProcessEvent
end loop

Author:  Dan [ Tue Dec 11, 2007 11:54 am ]
Post subject:  RE:BlackJack >. HELP ME I SUCK AT PROGRAMMING

You did not say what your program is at all. Also you should use code or syntax tags when posting code.

Author:  shakin cookie [ Wed Jan 09, 2008 5:09 pm ]
Post subject:  RE:BlackJack >. HELP ME I SUCK AT PROGRAMMING

there is a post at the very top of this forum that asks very nicely for people not to post "I need help" titles. I suggest that this post be moved to the help forum, or the name changed to something more appropriate.

Author:  Zampano [ Wed Jan 09, 2008 5:56 pm ]
Post subject:  Re: BlackJack >. HELP ME I SUCK AT PROGRAMMING

As it happens, the problem is pretty simple. You used the locate procedure to locate to a row greater than maxrow. After changing two locate procedure arguments, the program worked.
It might have helped if you specified the problem to get a response sooner.

Oh, shakin cookie, I think there is also a rule (or tacit reminder) to use the edit function when possible and appropriate. :D

Author:  shakin cookie [ Wed Jan 09, 2008 7:59 pm ]
Post subject:  RE:BlackJack >. HELP ME I SUCK AT PROGRAMMING

oh, ok... i thought that that was only for the initial submitter...


: