Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Crazy 8's
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CrazedCoder




PostPosted: Sun Dec 18, 2016 1:25 pm   Post subject: Crazy 8's

What is it you are trying to achieve?
Im trying to allow a human player to be able to click a card and have that card move to a a face up pile and then have the turn switch to a second human player


What is the problem you are having?
I can't figure out how to move the card to the faceup pile


Describe what you have tried to solve this problem
I've tried to draw the picture of the card in the other place then erase it but it wasn't working out right


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Heres my code so far

Turing:


var winMain : int := Window.Open ("graphics:781;541")
var pic : array 1 .. 52 of int
var deck : array 1 .. 52 of int
var rancard : int
var p1hand, p2hand, faceup, facedown : array 1 .. 52 of int
var p1cnt, p2cnt, fucnt, fdcnt, x, pturn : int

for i : 1 .. 52
    deck (i) := 0
end for

drawfillbox (0, 0, maxx, maxy, 7)

pic (1) := Pic.FileNew ("AH.JPG")
pic (2) := Pic.FileNew ("2H.JPG")
pic (3) := Pic.FileNew ("3H.JPG")
pic (4) := Pic.FileNew ("4H.JPG")
pic (5) := Pic.FileNew ("5H.JPG")
pic (6) := Pic.FileNew ("6H.JPG")
pic (7) := Pic.FileNew ("7H.JPG")
pic (8) := Pic.FileNew ("8H.JPG")
pic (9) := Pic.FileNew ("9H.JPG")
pic (10) := Pic.FileNew ("10H.JPG")
pic (11) := Pic.FileNew ("JH.JPG")
pic (12) := Pic.FileNew ("QH.JPG")
pic (13) := Pic.FileNew ("KH.JPG")
pic (14) := Pic.FileNew ("AD.JPG")
pic (15) := Pic.FileNew ("2D.JPG")
pic (16) := Pic.FileNew ("3D.JPG")
pic (17) := Pic.FileNew ("4D.JPG")
pic (18) := Pic.FileNew ("5D.JPG")
pic (19) := Pic.FileNew ("6D.JPG")
pic (20) := Pic.FileNew ("7D.JPG")
pic (21) := Pic.FileNew ("8D.JPG")
pic (22) := Pic.FileNew ("9D.JPG")
pic (23) := Pic.FileNew ("10D.JPG")
pic (24) := Pic.FileNew ("JD.JPG")
pic (25) := Pic.FileNew ("QD.JPG")
pic (26) := Pic.FileNew ("KD.JPG")
pic (27) := Pic.FileNew ("AC.JPG")
pic (28) := Pic.FileNew ("2C.JPG")
pic (29) := Pic.FileNew ("3C.JPG")
pic (30) := Pic.FileNew ("4C.JPG")
pic (31) := Pic.FileNew ("5C.JPG")
pic (32) := Pic.FileNew ("6C.JPG")
pic (33) := Pic.FileNew ("7C.JPG")
pic (34) := Pic.FileNew ("8C.JPG")
pic (35) := Pic.FileNew ("9C.JPG")
pic (36) := Pic.FileNew ("10C.JPG")
pic (37) := Pic.FileNew ("JC.JPG")
pic (38) := Pic.FileNew ("QC.JPG")
pic (39) := Pic.FileNew ("KC.JPG")
pic (40) := Pic.FileNew ("AS.JPG")
pic (41) := Pic.FileNew ("2S.JPG")
pic (42) := Pic.FileNew ("3S.JPG")
pic (43) := Pic.FileNew ("4S.JPG")
pic (44) := Pic.FileNew ("5S.JPG")
pic (45) := Pic.FileNew ("6S.JPG")
pic (46) := Pic.FileNew ("7S.JPG")
pic (47) := Pic.FileNew ("8S.JPG")
pic (48) := Pic.FileNew ("9S.JPG")
pic (49) := Pic.FileNew ("10S.JPG")
pic (50) := Pic.FileNew ("JS.JPG")
pic (51) := Pic.FileNew ("QS.JPG")
pic (52) := Pic.FileNew ("KS.JPG")

procedure initialdeal
    for i : 1 .. 7
        loop
            randint (rancard, 1, 52)
            exit when deck (rancard) = 0
        end loop
        deck (rancard) := 1
        p1hand (i) := rancard
    end for

    for i : 1 .. 7
        loop
            randint (rancard, 1, 52)
            exit when deck (rancard) = 0
        end loop
        deck (rancard) := 1
        p2hand (i) := rancard
    end for

    for i : 1 .. 37
        loop
            randint (rancard, 1, 52)
            exit when deck (rancard) = 0
        end loop
        deck (rancard) := 1
        facedown (i) := rancard
    end for

    for i : 1 .. 1
        loop
            randint (rancard, 1, 52)
            exit when deck (rancard) = 0
        end loop
        deck (rancard) := 1
        faceup (i) := rancard
    end for

    p1cnt := 7
    p2cnt := 7
    fdcnt := 37
    fucnt := 1

end initialdeal

procedure exposecards

    x := 0

    for i : 1 .. p1cnt
        Pic.Draw (pic (p1hand (i)), x, 100, picCopy)
        x := x + 12
    end for

    x := 0

    for i : 1 .. p2cnt
        Pic.Draw (pic (p2hand (i)), (maxx div 2) + x, 100, picCopy)
        x := x + 12
    end for

    x := 0

    for i : 1 .. fdcnt
        Pic.Draw (pic (facedown (i)), x, 440, picCopy)
        x := x + 12
    end for

    x := 0

    for i : 1 .. fucnt
        Pic.Draw (pic (faceup (i)), x, 340, picCopy)
        x := x + 12
    end for
    x := 0

end exposecards

procedure playerturn



Please specify what version of Turing you are using
I'm using turing 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
CrazedCoder




PostPosted: Sun Dec 18, 2016 1:42 pm   Post subject: RE:Crazy 8\'s

i forgot to put it in the code but after end exposecards there should be two lines on that says: initialdeal, and the other which says: exposecards
CrazedCoder




PostPosted: Sun Dec 18, 2016 1:46 pm   Post subject: Re: Crazy 8's

this is the end result


Crazy 8's Output.bmp
 Description:
 Filesize:  1.61 MB
 Viewed:  688 Time(s)

Crazy 8's Output.bmp


CrazedCoder




PostPosted: Sun Dec 18, 2016 1:48 pm   Post subject: RE:Crazy 8\'s

player 1's hand is the bottom left, player 2's hand is the bottom right, facedown is the top, and faceup is one down from the top
Insectoid




PostPosted: Mon Dec 19, 2016 11:45 am   Post subject: RE:Crazy 8\'s

You've already got all the pieces here, you just need to put them together.

Break down the problem into parts. To move a card from one deck to another, you have to remove it from the first deck, and add it to the other deck. Adding to the other deck is easy, just increase the size by 1 and add it to the end. Deleting is the hard part. If you just set deck (n) := 0, there's a hole in your deck. Keeping track of holes is hard. It's a lot easier to shuffle everything left by one. If we started with this deck:

1 5 3 7 2

and delete 3 we get

1 5 0 7 2

To get rid of the 0, shift the 7 and 2 to the left:

1 5 7 2 0

Now there's no gaps, so interacting with the deck is still simple.

As far as how to shift everything to the left, I'll leave to you for homework.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: