import GUI
 
type card :
 
    record
 
 %acces by using var kingodspades:card
 
        value : int    %               kingofspades.suit:=spades
 
        pic : int
 
        number : int
 
    end record
 
 
 
var c : array 0 .. 53 of card
 
c (0).pic := Pic.FileNew ("0.bmp")
 
c (1).pic := Pic.FileNew ("1.spade.bmp")
 
c (2).pic := Pic.FileNew ("1.dia.bmp")
 
c (3).pic := Pic.FileNew ("1.club.bmp")
 
c (4).pic := Pic.FileNew ("1.heart.bmp")
 
c (5).pic := Pic.FileNew ("2.spade.bmp")
 
c (6).pic := Pic.FileNew ("2.dia.bmp")
 
c (7).pic := Pic.FileNew ("2.club.bmp")
 
c (8).pic := Pic.FileNew ("2.heart.bmp")
 
c (9).pic := Pic.FileNew ("3.spade.bmp")
 
c (10).pic := Pic.FileNew ("3.dia.bmp")
 
c (11).pic := Pic.FileNew ("3.club.bmp")
 
c (12).pic := Pic.FileNew ("3.heart.bmp")
 
c (13).pic := Pic.FileNew ("4.spade.bmp")
 
c (14).pic := Pic.FileNew ("4.dia.bmp")
 
c (15).pic := Pic.FileNew ("4.club.bmp")
 
c (16).pic := Pic.FileNew ("4.heart.bmp")
 
c (17).pic := Pic.FileNew ("5.spade.bmp")
 
c (18).pic := Pic.FileNew ("5.dia.bmp")
 
c (19).pic := Pic.FileNew ("5.club.bmp")
 
c (20).pic := Pic.FileNew ("5.heart.bmp")
 
c (21).pic := Pic.FileNew ("6.spade.bmp")
 
c (22).pic := Pic.FileNew ("6.dia.bmp")
 
c (23).pic := Pic.FileNew ("6.club.bmp")
 
c (24).pic := Pic.FileNew ("6.heart.bmp")
 
c (25).pic := Pic.FileNew ("7.spade.bmp")
 
c (26).pic := Pic.FileNew ("7.dia.bmp")
 
c (27).pic := Pic.FileNew ("7.club.bmp")
 
c (28).pic := Pic.FileNew ("7.heart.bmp")
 
c (29).pic := Pic.FileNew ("8.spade.bmp")
 
c (30).pic := Pic.FileNew ("8.dia.bmp")
 
c (31).pic := Pic.FileNew ("8.club.bmp")
 
c (32).pic := Pic.FileNew ("8.heart.bmp")
 
c (33).pic := Pic.FileNew ("9.spade.bmp")
 
c (34).pic := Pic.FileNew ("9.dia.bmp")
 
c (35).pic := Pic.FileNew ("9.club.bmp")
 
c (36).pic := Pic.FileNew ("9.heart.bmp")
 
c (37).pic := Pic.FileNew ("10.spade.bmp")
 
c (38).pic := Pic.FileNew ("10.dia.bmp")
 
c (39).pic := Pic.FileNew ("10.club.bmp")
 
c (40).pic := Pic.FileNew ("10.heart.bmp")
 
c (41).pic := Pic.FileNew ("11.spade.bmp")
 
c (42).pic := Pic.FileNew ("11.dia.bmp")
 
c (43).pic := Pic.FileNew ("11.club.bmp")
 
c (44).pic := Pic.FileNew ("11.heart.bmp")
 
c (45).pic := Pic.FileNew ("12.spade.bmp")
 
c (46).pic := Pic.FileNew ("12.dia.bmp")
 
c (47).pic := Pic.FileNew ("12.club.bmp")
 
c (48).pic := Pic.FileNew ("12.heart.bmp")
 
c (49).pic := Pic.FileNew ("13.spade.bmp")
 
c (50).pic := Pic.FileNew ("13.dia.bmp")
 
c (51).pic := Pic.FileNew ("13.club.bmp")
 
c (52).pic := Pic.FileNew ("13.heart.bmp")
 
 
var font1 : int
 
font1 := Font.New ("serif:40") %fonts
 
assert font1 > 0
 
%%%%%Game variables%%%%%%
 
var name : string
 
var size : int := 52  %size of deck to be shuffled
 
var deck : array 1 .. size of card %array to store card values randomized
 
var userDeck : array 1 .. 26 of card
 
var cpuDeck : array 1 .. 26 of card
 
var count : int := 1 %for the draw procedure and playg
 
 
 
%%%%%%%%%%%%%%%%%%%%%%%%%
 
procedure shuffle
 
    var temp, num : int % num and temp are used to flip the variables in the array around
 
    for i : 1 .. size
 
        deck (i).number := i %gives a value in order from 1 to size to deck
 
    end for
 
    for i : 1 .. size
 
        randint (num, 1, size)   %assigns  a random card number to num
 
        temp := deck (num).number %assigns a random number out of the deck array to temp
 
        deck (num) := deck (i)
 
        %switches the numbers
 
        deck (i).number := temp
 
    end for
 
    var count : int := 0
 
    var count4 : int := 4
 
    for k : 1 .. 13
 
        for i : 1 .. 52
 
            if deck (i).number <= count4 and deck (i).number > count then %This gives all the card numbers a value
 
                deck (i).value := k
 
            end if
 
        end for
 
        count += 4
 
        count4 += 4
 
    end for
 
    for i : 1 .. 26
 
        userDeck (i).number := deck (i).number   %gives the first 26 cards from the deck to the user
 
        userDeck (i).value := deck (i).value
 
    end for
 
    var counter : int := 27
 
    for i : 1 .. 26
 
        cpuDeck (i).number := deck (counter).number     %gives the last 26 cards to the computer
 
        cpuDeck (i).value := deck (counter).value
 
        counter += 1
 
    end for
 
end shuffle
 
 
procedure gfx
 
    var font1 : int
 
    font1 := Font.New ("serif:40")
 
    assert font1 > 0
 
    Font.Draw (name, 1, 1, font1, red)
 
    Pic.Draw (c (0).pic, 50, 50, picCopy) %user card deck
 
    Font.Draw ("CPU", 1, maxy - 50, font1, red)
 
    Pic.Draw (c (0).pic, 50, maxy - 150, picCopy) %pc card deck
 
end gfx
 
 
procedure greet
 
    colourback (15)
 
    locate (maxrow div 2, maxcol div 2 - 20)
 
 
    put "Please enter your name: " ..
 
    get name
 
    drawfillbox (0, 0, maxx, maxy, 15)
 
 
end greet
 
 
procedure WAR
 
    Font.Draw ("WARRRRRRRRRRRRR!!!!!", 400, maxy - 375, font1, red)
 
end WAR
 
 
procedure USERWIN
 
    Font.Draw ("YOU WIN!", 400, maxy - 375, font1, red)
 
end USERWIN
 
 
procedure PCWIN
 
    Font.Draw ("COMPUTER WINS!", 400, maxy - 375, font1, red)
 
end PCWIN
 
var deckC : int := 1  %variable for the next card in the deck
 
 
proc button
 
    for i : 1 .. 52 %loop checks to see what picture to draw for the card drawn from the players hand
 
        if userDeck (deckC).number = (i) then
 
            Pic.Draw (c (i).pic, 300, 250, picCopy)
 
        end if
 
        if cpuDeck (deckC).number = (i) then
 
            Pic.Draw (c (i).pic, 300, maxy - 350, picCopy)
 
        end if
 
        if userDeck (deckC).value > cpuDeck (deckC).value then
 
            USERWIN
 
        elsif userDeck (deckC).value < cpuDeck (deckC).value then
 
            PCWIN
 
        else
 
            WAR
 
        end if
 
 
    end for
 
    deckC += 1
 
    delay (1000)
 
    drawfillbox (400, maxy - 475, 8000, maxy - 100, 15) %covers up the text when someone wins
 
end button
 
 
proc check
 
    if userDeck (deckC).value > cpuDeck (deckC).value then
 
        USERWIN
 
    elsif userDeck (deckC).value < cpuDeck (deckC).value then
 
        PCWIN
 
    else
 
        WAR
 
    end if
 
 
    drawfillbox (400, maxy - 475, 8000, maxy - 100, 15) %covers up the text when someone wins
 
end check
 
 
%start%
 
setscreen ("graphics:1000;700,nobuttonbar")
 
drawfillbox (0, 0, maxx, maxy, 15)
 
shuffle
 
greet
 
gfx
 
var drawbutton : int := GUI.CreateButton (150, 50, 0, "Draw", button) %experimental button drawing
 
loop
 
    exit when GUI.ProcessEvent
 
end loop
 
  |