Diffstat (limited to 'noncore/games/solitaire/carddeck.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/solitaire/carddeck.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/noncore/games/solitaire/carddeck.cpp b/noncore/games/solitaire/carddeck.cpp index 87c043a..a2d0076 100644 --- a/noncore/games/solitaire/carddeck.cpp +++ b/noncore/games/solitaire/carddeck.cpp | |||
@@ -14,65 +14,75 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <time.h> | 21 | #include <time.h> |
22 | #include "card.h" | 22 | #include "card.h" |
23 | #include "carddeck.h" | 23 | #include "carddeck.h" |
24 | 24 | ||
25 | 25 | ||
26 | CardDeck::CardDeck(int jokers) : numberOfJokers(jokers), deckCreated(FALSE) | 26 | CardDeck::CardDeck(int jokers, int numOfDecks) : numberOfJokers(jokers), numberOfDecks(numOfDecks), deckCreated(FALSE) |
27 | { | 27 | { |
28 | cards = new (Card *)[getNumberOfCards()]; | 28 | cards = new (Card *)[getNumberOfCards()]; |
29 | } | 29 | } |
30 | 30 | ||
31 | 31 | ||
32 | CardDeck::~CardDeck() | 32 | CardDeck::~CardDeck() |
33 | { | 33 | { |
34 | for (int i = 0; i < getNumberOfCards(); i++) | 34 | for (int i = 0; i < getNumberOfCards(); i++) |
35 | delete cards[i]; | 35 | delete cards[i]; |
36 | delete cards; | 36 | delete cards; |
37 | } | 37 | } |
38 | 38 | ||
39 | 39 | ||
40 | void CardDeck::createDeck() | 40 | void CardDeck::createDeck() |
41 | { | 41 | { |
42 | if (!deckCreated) { | 42 | if (!deckCreated) { |
43 | for (int i = 0; i < 52; i++) | 43 | for (int j = 0; j < getNumberOfDecks(); j++) { |
44 | cards[i] = newCard( (eValue)((i % 13) + 1), (eSuit)((i / 13) + 1), FALSE ); | 44 | for (int i = 0; i < 52; i++) { |
45 | cards[i+j*52] = newCard( (eValue)((i % 13) + 1), (eSuit)((i / 13) + 1), FALSE); | ||
46 | cards[i+j*52]->setDeckNumber(j); | ||
47 | } | ||
48 | } | ||
45 | for (int i = 0; i < getNumberOfJokers(); i++) | 49 | for (int i = 0; i < getNumberOfJokers(); i++) |
46 | cards[52 + i] = newCard( jokerVal, jokerSuit, FALSE ); | 50 | cards[52*getNumberOfDecks() + i] = newCard( jokerVal, jokerSuit, FALSE); |
47 | deckCreated = TRUE; | 51 | deckCreated = TRUE; |
48 | } | 52 | } |
49 | } | 53 | } |
50 | 54 | ||
51 | 55 | ||
52 | void CardDeck::shuffle() | 56 | void CardDeck::shuffle() |
53 | { | 57 | { |
54 | srand(time(NULL)); | 58 | srand(time(NULL)); |
55 | for (int i = 0; i < getNumberOfCards(); i++) { | 59 | for (int i = 0; i < getNumberOfCards(); i++) { |
56 | int index = rand() % getNumberOfCards(); | 60 | int index = rand() % getNumberOfCards(); |
57 | Card *tmpCard = cards[i]; | 61 | Card *tmpCard = cards[i]; |
58 | cards[i] = cards[index]; | 62 | cards[i] = cards[index]; |
59 | cards[index] = tmpCard; | 63 | cards[index] = tmpCard; |
60 | } | 64 | } |
61 | } | 65 | } |
62 | 66 | ||
63 | 67 | ||
64 | int CardDeck::getNumberOfCards() | 68 | int CardDeck::getNumberOfCards() |
65 | { | 69 | { |
66 | return 52 + getNumberOfJokers(); | 70 | return 52*getNumberOfDecks() + getNumberOfJokers(); |
71 | } | ||
72 | |||
73 | |||
74 | int CardDeck::getNumberOfDecks() | ||
75 | { | ||
76 | return numberOfDecks; | ||
67 | } | 77 | } |
68 | 78 | ||
69 | 79 | ||
70 | int CardDeck::getNumberOfJokers() | 80 | int CardDeck::getNumberOfJokers() |
71 | { | 81 | { |
72 | return numberOfJokers; | 82 | return numberOfJokers; |
73 | } | 83 | } |
74 | 84 | ||
75 | 85 | ||
76 | Card *CardDeck::newCard( eValue v, eSuit s, bool f ) | 86 | Card *CardDeck::newCard( eValue v, eSuit s, bool f ) |
77 | { | 87 | { |
78 | return new Card(v, s, f); | 88 | return new Card(v, s, f); |