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

Username:   Password: 
 RegisterRegister   
 breaking an array up? 0o
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SpaceDude




PostPosted: Mon Jun 07, 2004 2:14 pm   Post subject: breaking an array up? 0o

lol
hmm ok lets say this is for a card game ok?
so i make one array of 52
and then i want to split the array into 4 parts cuz there is 4 suits for the deck, and i want to split them in different colours, like red for diamond, purple for club, pink for hearts and black for spades, so how would i do it?

cuz i tried this way and it wouldn't work lol...

var Deck : array 1 .. 52 of int


%Diamonds
color (3)
Deck (1) := Ace
Deck (2) := 2
Deck (3) := 3
Deck (4) := 4
Deck (5) := 5
Deck (6) := 6
Deck (7) := 7
Deck (8) := 8
Deck (9) := 9
Deck (10) := 10
Deck (11) := JACK
Deck (12) := QUEN
Deck (13) := KING

%Clubs
color (5)
Deck (14) := Ace
Deck (15) := 2
Deck (16) := 3
Deck (17) := 4
Deck (18) := 5
Deck (19) := 6
Deck (20) := 7
Deck (21) := 8
Deck (22) := 9
Deck (23) := 10
Deck (24) := JACK
Deck (25) := QUEN
Deck (26) := KING

~~~
and so forth, so hmm is there a easier way to break this 52 array into 4 pieces easier? and can keep the colour?

thanks
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Mon Jun 07, 2004 2:43 pm   Post subject: (No subject)

code:

var Deck : array 1 .. 52 of string

for i : 0 .. 3
    Deck (i * 13 + 1) := "Ace"
    for j : 2 .. 10
        Deck (i * 13 + j) := intstr (j)
    end for
    Deck (i * 13 + 11) := "Jack"
    Deck (i * 13 + 12) := "Queen"
    Deck (i * 13 + 13) := "King"
end for


EDIT: Hm... perhaps that wasn't what you wanted.
Well, just remember that every 13 cards is a different suit. So, 1-13 spades, 13-26 clubs, etc.
SpaceDude




PostPosted: Tue Jun 08, 2004 2:40 am   Post subject: (No subject)

ic thanks, i guess i know how to do it now
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  [ 3 Posts ]
Jump to:   


Style:  
Search: