Comparing and counting cards
Author |
Message |
gilbamy
|
Posted: Tue Jun 20, 2006 7:23 am Post subject: Comparing and counting cards |
|
|
what i need to do is have my cards compare then see who wins and those cards go in to the deck and i need to have the count for how many cards each player has .
code: | %Amy Gilbank
%June 1 2006
%war1.t
%a game of war
var winMain : int := Window.Open ("graphics:800;600")
var font1, font2, font3, font4, font5 : int
var Randomcard, x1, x2, y1, y2, y3, y4, x3, x4, button : int
var h,P1,P2 :string
var p1value, p2value, deck, deckvalue, decktest, cards, cardvalue, p1, checkdeck, p2 : array 1 .. 52 of int
%The mus procedure is my music for my logo.
process mus
Music.Play ("2acfega4c4c4cfgeaeg2d4adfe2fg")
end mus
%This is my logo where the lines and squeres appear and music plays .
procedure logo
drawfillbox (0, 600, 800, 0, 7)
font3 := Font.New ("Allegro BT:25:")
Font.Draw ("Sabriel", 320, 260, font3, 0)
fork mus
delay (500)
drawbox (300, 480, 360, 420, 0)
delay (500)
drawline (300, 480, 360, 340, 0)
delay (500)
drawline (300, 420, 360, 280, 0)
delay (500)
drawline (360, 420, 420, 280, 0)
delay (500)
drawline (360, 480, 420, 340, 0)
delay (500)
drawbox (360, 340, 420, 280, 0)
delay (500)
drawline (420, 240, 340, 140, 0)
delay (500)
drawline (420, 240, 540, 240, 0)
delay (500)
drawline (540, 240, 500, 140, 0)
delay (500)
drawline (340, 140, 500, 140, 0)
delay (500)
drawline (420, 240, 340, 140, 0)
delay (500)
drawline (500, 140, 420, 280, 0)
delay (500)
drawline (420, 240, 420, 280, 0)
delay (500)
drawline (340, 140, 420, 280, 0)
delay (500)
drawline (540, 240, 420, 280, 0)
delay (500)
end logo
procedure intro
font4 := Font.New ("Allegro BT:50:")
font5 := Font.New ("Allegro BT:25:")
x3 := 360
y3 := 455
x4 := 475
y4 := 500
drawfillbox (0, 600, 800, 0, 19)
drawfillbox (360, 455, 475, 500, 105)
drawfillbox (520, 420, 320, 375, 105)
drawfillbox (350, 330, 480, 295, 105)
drawfillbox (365, 225, 455, 260, 105)
Font.Draw ("War!", 340, 530, font4, 56)
Font.Draw ("Play", 385, 460, font5, 56)
Font.Draw ("Instructions", 335, 380, font5, 56)
Font.Draw ("Options", 365, 300, font5, 56)
Font.Draw ("Quit", 380, 230, font5, 56)
%This is where if i click on the play button it will bring me to my spot to decide who goes first.
loop
Mouse.Where (x3, y3, button)
if (x3 > x4 and x3 < x4) and (y3 > y4 and y3 < y4) then
button := 1
end if
if button = 1 then
locatexy (maxx div 4, maxy div 2)
delay (500)
cls
end if
end loop
end intro
%This code goes between the number 1 and 2 which means 1 is p1 and 2 is p2 the last number that is chossen is who goes first its random .
procedure wgf
var Randnum : int
for i : 1 .. 7
Randnum := Rand.Int (1, 2)
put Randnum
end for
if Randnum = 2 then
put "Player two goes first"
elsif Randnum = 1 then
put "Player one goes first"
end if
end wgf
procedure war
%my war layout like my background boxs and my fonts
drawfillbox (0, 600, 800, 0, 199)
%Battle area
drawfillbox (20, 100, 95, 200, 78)
drawfillbox (120, 100, 195, 200, 78)
drawfillbox (220, 100, 295, 200, 78)
drawfillbox (320, 100, 395, 200, 78)
drawfillbox (420, 100, 495, 200, 78)
drawfillbox (520, 100, 595, 200, 78)
drawfillbox (620, 100, 695, 200, 78)
drawfillbox (720, 100, 795, 200, 78)
%Deck and cards spot
drawfillbox (200, 400, 275, 500, 79)
drawfillbox (500, 400, 575, 500, 80)
drawfillbox (300, 400, 375, 500, 0)
drawfillbox (400, 400, 475, 500, 0)
%Scoreboard and card number spots
drawfillbox (320, 360, 360, 380, 0)
drawfillbox (420, 360, 460, 380, 0)
%Fonts
font1 := Font.New ("Vineta BT:45: bold,underline")
Font.Draw ("WAR!", 260, 550, font1, red)
font2 := Font.New ("New Times Roman :11:")
Font.Draw ("Player 1", 300, 310, font2, 27)
Font.Draw ("Player 2", 410, 310, font2, 27)
Font.Draw ("Deck", 220, 510, font2, 27)
Font.Draw ("Deck", 520, 510, font2, 27)
%Cards
%Inserting my cards into my program
cards (1) := Pic.FileNew ("10C.jpg")
cards (2) := Pic.FileNew ("10D.jpg")
cards (3) := Pic.FileNew ("10H.jpg")
cards (4) := Pic.FileNew ("10S.jpg")
cards (5) := Pic.FileNew ("2C.jpg")
cards (6) := Pic.FileNew ("2D.jpg")
cards (7) := Pic.FileNew ("2H.jpg")
cards (8) := Pic.FileNew ("2S.jpg")
cards (9) := Pic.FileNew ("3C.jpg")
cards (10) := Pic.FileNew ("3D.jpg")
cards (11) := Pic.FileNew ("3H.jpg")
cards (12) := Pic.FileNew ("3S.jpg")
cards (13) := Pic.FileNew ("4C.jpg")
cards (14) := Pic.FileNew ("4D.jpg")
cards (15) := Pic.FileNew ("4H.jpg")
cards (16) := Pic.FileNew ("4S.jpg")
cards (17) := Pic.FileNew ("5C.jpg")
cards (18) := Pic.FileNew ("5D.jpg")
cards (19) := Pic.FileNew ("5H.jpg")
cards (20) := Pic.FileNew ("5S.jpg")
cards (21) := Pic.FileNew ("6C.jpg")
cards (22) := Pic.FileNew ("6D.jpg")
cards (23) := Pic.FileNew ("6H.jpg")
cards (24) := Pic.FileNew ("6S.jpg")
cards (25) := Pic.FileNew ("7C.jpg")
cards (26) := Pic.FileNew ("7D.jpg")
cards (27) := Pic.FileNew ("7H.jpg")
cards (28) := Pic.FileNew ("7S.jpg")
cards (29) := Pic.FileNew ("8C.jpg")
cards (30) := Pic.FileNew ("8D.jpg")
cards (31) := Pic.FileNew ("8H.jpg")
cards (32) := Pic.FileNew ("8S.jpg")
cards (33) := Pic.FileNew ("9C.jpg")
cards (34) := Pic.FileNew ("9D.jpg")
cards (35) := Pic.FileNew ("9H.jpg")
cards (36) := Pic.FileNew ("9S.jpg")
cards (37) := Pic.FileNew ("QC.jpg")
cards (38) := Pic.FileNew ("QD.jpg")
cards (39) := Pic.FileNew ("QH.jpg")
cards (40) := Pic.FileNew ("QS.jpg")
cards (41) := Pic.FileNew ("AC.jpg")
cards (42) := Pic.FileNew ("AD.jpg")
cards (43) := Pic.FileNew ("AH.jpg")
cards (44) := Pic.FileNew ("AS.jpg")
cards (45) := Pic.FileNew ("JC.jpg")
cards (46) := Pic.FileNew ("JD.jpg")
cards (47) := Pic.FileNew ("JH.jpg")
cards (48) := Pic.FileNew ("JS.jpg")
cards (49) := Pic.FileNew ("KC.jpg")
cards (50) := Pic.FileNew ("KD.jpg")
cards (51) := Pic.FileNew ("KH.jpg")
cards (52) := Pic.FileNew ("KS.jpg")
%card values
cardvalue (1) := 10
cardvalue (2) := 10
cardvalue (3) := 10
cardvalue (4) := 10
cardvalue (5) := 2
cardvalue (6) := 2
cardvalue (7) := 2
cardvalue (8) := 2
cardvalue (9) := 3
cardvalue (10) := 3
cardvalue (11) := 3
cardvalue (12) := 3
cardvalue (13) := 4
cardvalue (14) := 4
cardvalue (15) := 4
cardvalue (16) := 4
cardvalue (17) := 5
cardvalue (18) := 5
cardvalue (19) := 5
cardvalue (20) := 5
cardvalue (21) := 6
cardvalue (22) := 6
cardvalue (23) := 6
cardvalue (24) := 6
cardvalue (25) := 7
cardvalue (26) := 7
cardvalue (27) := 7
cardvalue (28) := 7
cardvalue (29) := 8
cardvalue (30) := 8
cardvalue (31) := 8
cardvalue (32) := 8
cardvalue (33) := 9
cardvalue (34) := 9
cardvalue (35) := 9
cardvalue (36) := 9
cardvalue (37) := 12
cardvalue (38) := 12
cardvalue (39) := 12
cardvalue (40) := 12
cardvalue (41) := 14
cardvalue (42) := 14
cardvalue (43) := 14
cardvalue (44) := 14
cardvalue (45) := 11
cardvalue (46) := 11
cardvalue (47) := 11
cardvalue (48) := 11
cardvalue (49) := 13
cardvalue (50) := 13
cardvalue (51) := 13
cardvalue (52) := 13
%Dealing the cards to P1 and P2
x1 := 300
y1 := 400
x2 := 400
y2 := 400
for i : 1 .. 52
checkdeck (i) := 1
end for
for i : 1 .. 26
loop
Randomcard := Rand.Int (1, 52)
exit when checkdeck (Randomcard) = 1
end loop
checkdeck (Randomcard) := 0
p1 (i) := cards (Randomcard)
end for
for i : 1 .. 26
loop
Randomcard := Rand.Int (1, 52)
exit when checkdeck (Randomcard) = 1
end loop
checkdeck (Randomcard) := 1
p2 (i) := cards (Randomcard)
end for
for i : 1 .. 26
Pic.Draw (p1 (i), x1, y1, 0)
Pic.Draw (p2 (i), x2, y2, 0)
end for
loop
put "Please enter h if wanting to see players hands:" get h
var winMain : int := Window.Open ("graphics:800;600")
put "Please enter P1 or P2 to view hands :.."get P1,P2
cls
end loop
end war
war
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Tue Jun 20, 2006 8:54 am Post subject: (No subject) |
|
|
y not just use your values for the cards? just have a simple if that checks the values? if the card is greater than the other, you win, if its smaller u lose, if its a tie initiate a war |
|
|
|
|
|
Guest
|
Posted: Tue Jun 20, 2006 9:05 am Post subject: (No subject) |
|
|
Yes. An if statment works as follows:
code: |
var guess, num : int
put "Guess my number bewteen 1 and 10: " .. %the .. continues next statment on same line
get guess %stores the guess
num := Rand.Int (1, 10) %num is now a random interger from 1-10
if guess > num then %checks if your guess is greater than the random int
put "Guess is too high! " ..
elsif guess < num then %checks if guess is lower than rand int
put "Guess is too low! " ..
else %anything else that happens will excecute (such as your guess matching the Rand.Int)
put "Answer must be correct! " ..
end if
put "Answer is ", num
|
|
|
|
|
|
|
gilbamy
|
Posted: Tue Jun 20, 2006 1:08 pm Post subject: (No subject) |
|
|
okay well what i need to do is have the number of the card that its worth then it compare it and who has the highest gets those cards so i am kinda lost with this hole thing |
|
|
|
|
|
Delos
|
Posted: Tue Jun 20, 2006 3:34 pm Post subject: (No subject) |
|
|
vahnx's code essentially does that, though in a convoluted manner. He has provided you with the tools with which you'll be able to solve this problem. Have a look at what he's coded, run it a few times, play around with it, pretend that the values you're inputting are values of cards and see where that line of thinking takes you.
Once you get an idea of how you should be approaching your own code, take a look at his and notice the way he's set it up - what sort of comparisons he's made, how he determines which numbers are high and low, etc etc. |
|
|
|
|
|
gilbamy
|
Posted: Wed Jun 21, 2006 7:12 pm Post subject: (No subject) |
|
|
this is what i have so far but i am not quite sure on how do the one where bothe cards are tied cause then it goes into a war thing wioth the cards .
code: | %War code
var winMain : int := Window.Open ("graphics:800;600")
var font1, font2, font3, font4, font5 : int
var h, P1, P2 : string
var Randomcard, x1, x2, y1, y2, button, p1next, p2next : int
var deck, deckvalue, decktest, cards, cardvalue, p1, checkdeck, p2 : array 1 .. 52 of int
var p1value, p2value : array 1 .. 52 of int
var key : string (1)
procedure start
%my war layout like my background boxs and my fonts
drawfillbox (0, 600, 800, 0, 199)
%Battle area
drawfillbox (20, 100, 95, 200, 78)
drawfillbox (120, 100, 195, 200, 78)
drawfillbox (220, 100, 295, 200, 78)
drawfillbox (320, 100, 395, 200, 78)
drawfillbox (420, 100, 495, 200, 78)
drawfillbox (520, 100, 595, 200, 78)
drawfillbox (620, 100, 695, 200, 78)
drawfillbox (720, 100, 795, 200, 78)
%Deck and cards spot
drawfillbox (200, 400, 275, 500, 79)
drawfillbox (500, 400, 575, 500, 80)
drawfillbox (300, 400, 375, 500, 0)
drawfillbox (400, 400, 475, 500, 0)
%Scoreboard and card number spots
drawfillbox (320, 360, 360, 380, 0)
drawfillbox (420, 360, 460, 380, 0)
%Fonts
font1 := Font.New ("Vineta BT:45: bold,underline")
font2 := Font.New ("New Times Roman :11:")
Font.Draw ("WAR!", 260, 550, font1, red)
Font.Draw ("Player 1", 300, 310, font2, 27)
Font.Draw ("Player 2", 410, 310, font2, 27)
Font.Draw ("Deck", 220, 510, font2, 27)
Font.Draw ("Deck", 520, 510, font2, 27)
%Cards
%Inserting my cards into my program
cards (1) := Pic.FileNew ("10C.jpg")
cards (2) := Pic.FileNew ("10D.jpg")
cards (3) := Pic.FileNew ("10H.jpg")
cards (4) := Pic.FileNew ("10S.jpg")
cards (5) := Pic.FileNew ("2C.jpg")
cards (6) := Pic.FileNew ("2D.jpg")
cards (7) := Pic.FileNew ("2H.jpg")
cards (8) := Pic.FileNew ("2S.jpg")
cards (9) := Pic.FileNew ("3C.jpg")
cards (10) := Pic.FileNew ("3D.jpg")
cards (11) := Pic.FileNew ("3H.jpg")
cards (12) := Pic.FileNew ("3S.jpg")
cards (13) := Pic.FileNew ("4C.jpg")
cards (14) := Pic.FileNew ("4D.jpg")
cards (15) := Pic.FileNew ("4H.jpg")
cards (16) := Pic.FileNew ("4S.jpg")
cards (17) := Pic.FileNew ("5C.jpg")
cards (18) := Pic.FileNew ("5D.jpg")
cards (19) := Pic.FileNew ("5H.jpg")
cards (20) := Pic.FileNew ("5S.jpg")
cards (21) := Pic.FileNew ("6C.jpg")
cards (22) := Pic.FileNew ("6D.jpg")
cards (23) := Pic.FileNew ("6H.jpg")
cards (24) := Pic.FileNew ("6S.jpg")
cards (25) := Pic.FileNew ("7C.jpg")
cards (26) := Pic.FileNew ("7D.jpg")
cards (27) := Pic.FileNew ("7H.jpg")
cards (28) := Pic.FileNew ("7S.jpg")
cards (29) := Pic.FileNew ("8C.jpg")
cards (30) := Pic.FileNew ("8D.jpg")
cards (31) := Pic.FileNew ("8H.jpg")
cards (32) := Pic.FileNew ("8S.jpg")
cards (33) := Pic.FileNew ("9C.jpg")
cards (34) := Pic.FileNew ("9D.jpg")
cards (35) := Pic.FileNew ("9H.jpg")
cards (36) := Pic.FileNew ("9S.jpg")
cards (37) := Pic.FileNew ("QC.jpg")
cards (38) := Pic.FileNew ("QD.jpg")
cards (39) := Pic.FileNew ("QH.jpg")
cards (40) := Pic.FileNew ("QS.jpg")
cards (41) := Pic.FileNew ("AC.jpg")
cards (42) := Pic.FileNew ("AD.jpg")
cards (43) := Pic.FileNew ("AH.jpg")
cards (44) := Pic.FileNew ("AS.jpg")
cards (45) := Pic.FileNew ("JC.jpg")
cards (46) := Pic.FileNew ("JD.jpg")
cards (47) := Pic.FileNew ("JH.jpg")
cards (48) := Pic.FileNew ("JS.jpg")
cards (49) := Pic.FileNew ("KC.jpg")
cards (50) := Pic.FileNew ("KD.jpg")
cards (51) := Pic.FileNew ("KH.jpg")
cards (52) := Pic.FileNew ("KS.jpg")
%card values
cardvalue (1) := 10
cardvalue (2) := 10
cardvalue (3) := 10
cardvalue (4) := 10
cardvalue (5) := 2
cardvalue (6) := 2
cardvalue (7) := 2
cardvalue (8) := 2
cardvalue (9) := 3
cardvalue (10) := 3
cardvalue (11) := 3
cardvalue (12) := 3
cardvalue (13) := 4
cardvalue (14) := 4
cardvalue (15) := 4
cardvalue (16) := 4
cardvalue (17) := 5
cardvalue (18) := 5
cardvalue (19) := 5
cardvalue (20) := 5
cardvalue (21) := 6
cardvalue (22) := 6
cardvalue (23) := 6
cardvalue (24) := 6
cardvalue (25) := 7
cardvalue (26) := 7
cardvalue (27) := 7
cardvalue (28) := 7
cardvalue (29) := 8
cardvalue (30) := 8
cardvalue (31) := 8
cardvalue (32) := 8
cardvalue (33) := 9
cardvalue (34) := 9
cardvalue (35) := 9
cardvalue (36) := 9
cardvalue (37) := 12
cardvalue (38) := 12
cardvalue (39) := 12
cardvalue (40) := 12
cardvalue (41) := 14
cardvalue (42) := 14
cardvalue (43) := 14
cardvalue (44) := 14
cardvalue (45) := 11
cardvalue (46) := 11
cardvalue (47) := 11
cardvalue (48) := 11
cardvalue (49) := 13
cardvalue (50) := 13
cardvalue (51) := 13
cardvalue (52) := 13
end start
procedure deal
x1 := 300
y1 := 400
x2 := 400
y2 := 400
for i : 1 .. 52
checkdeck (i) := 1
end for
for i : 1 .. 26
loop
Randomcard := Rand.Int (1, 52)
exit when checkdeck (Randomcard) = 1
end loop
checkdeck (Randomcard) := 0
p1 (i) := cards (Randomcard)
p1value (i) := cardvalue (Randomcard)
loop
Randomcard := Rand.Int (1, 52)
exit when checkdeck (Randomcard) = 1
end loop
checkdeck (Randomcard) := 0
p2 (i) := cards (Randomcard)
p2value (i) := cardvalue (Randomcard)
end for
end deal
procedure compare
loop
for i : 1 .. 52
Pic.Draw (p1 (i), x1, y1, 0)
delay (100)
Pic.Draw (p2 (i), x2, y2, 0)
getch (key)
exit when key = "W"
p1next := 28
p2next := 28
if p1value (1) < p2value (1) then
p1 (p1next) := p2 (1)
p1value (p1next) := p2 (1)
p1next := p1next + 1
p1 (1) := p1 (1) + 1
p2 (1) := p2 (p2next) - 1
p2value (p2 (1)) := p2value (p2next) - 1
p2next := p2next - 1
elsif p1value (1) > p2value (1) then
p2 (p2next) := p1 (p1next)
p2value (p2next) := p1 (1)
p2next := p2next + 1
p2 (1) := p2 (1) + 1
p1 (1) := p1 (p1next - 1)
p1value (p1 (1)) := +p1value (p1next - 1)
p1next := p1next - 1
p1value (1) := p2value (1)
elsif p1value (1) = p2value (1) then
end if
end for
end loop
end compare
start
deal
compare
|
|
|
|
|
|
|
|
|