File indexing completed on 2024-09-15 03:46:15
0001 /* 0002 This file is part of the KDE games lskat program 0003 SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef DECK_H 0009 #define DECK_H 0010 0011 // Qt includes 0012 #include <QList> 0013 #include <QObject> 0014 #include <QRandomGenerator> 0015 0016 #include "lskat_debug.h" 0017 0018 /** 0019 * The card, suite and trump names 0020 */ 0021 namespace CardDeck 0022 { 0023 // Suite names 0024 enum Suite {Club = 0, Spade = 1, Heart = 2, Diamond = 3, Grand = 4}; 0025 // Card types. 0026 enum CardType {Ace = 0, King = 1, Queen = 2, Jack = 3, Ten = 4, Nine = 5, Eight = 6, Seven = 7}; 0027 } 0028 0029 using namespace CardDeck; 0030 0031 /** 0032 * The deck stores a card deck, handles random functions like 0033 * shuffling and deals the cards. 0034 */ 0035 class Deck : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 /** 0041 * Constructor for the deck. 0042 * @param seed The random seed 0043 * @param parent The parent object 0044 */ 0045 Deck(quint32 seed, QObject *parent); 0046 0047 /** 0048 * Destructor 0049 */ 0050 ~Deck() override; 0051 0052 /** 0053 * Retrieve number of cards in this deck. 0054 * @return Number of cards. 0055 */ 0056 int cardNumber(); 0057 0058 /** 0059 * Shuffle the cards and reset the pile. 0060 */ 0061 void shuffle(); 0062 0063 /** 0064 * Draw a random trump from all cards. This is 0065 * done by drawing a random card and choosing its 0066 * suite as trump. In case a Jack is drawn a Grand 0067 * is made trump. 0068 * @return A random trump. 0069 */ 0070 Suite randomTrump(); 0071 0072 /** 0073 * Draw a random card out of the pile of existing ones. 0074 * @return A random card 0075 */ 0076 int drawCard(); 0077 0078 /** 0079 * Get the suite (Club, ...) of a given card (number) 0080 * @param card The card number 0081 * @return The suite. 0082 */ 0083 static Suite getSuite(int card); 0084 0085 /** 0086 * Get the card type (ace, king, ...) of a given card (number) 0087 * @param card The card number 0088 * @return The card type (ace, king, ...). 0089 */ 0090 static CardType getCardType(int card); 0091 0092 /** 0093 * Get the card number (0, 1, ...) of a card given by suite and type. 0094 * @param suite The card suite (Club, ...) 0095 * @param type The card type (Ace, ...) 0096 * @return The card number. 0097 */ 0098 static int getCard(Suite suite, CardType type); 0099 0100 /** 0101 * Get the value in points of the given card (number). 0102 * @param card The card number 0103 * @return The card value [0, 2, 3, 4, 10, 11]. 0104 */ 0105 static int getCardValue(int card); 0106 0107 /** 0108 * Returns a verbose name for a card. 0109 * @param suite The card suite 0110 * @param type The card type 0111 * @return A descriptive string. 0112 */ 0113 static QString name(Suite suite, CardType type); 0114 0115 /** 0116 * Returns a verbose name for a card. 0117 * @param card The card as integer 0118 * @return A descriptive string. 0119 */ 0120 static QString name(int card); 0121 0122 /** 0123 * Returns a verbose name for a card type. 0124 * @param type The card type (e.g. Ace) 0125 * @return A descriptive string. 0126 */ 0127 static QString name(CardType type); 0128 0129 /** 0130 * Returns a verbose name for a suite. 0131 * @param suite The suite (e.g. Heart) 0132 * @return A descriptive string. 0133 */ 0134 static QString name(Suite suite); 0135 0136 private: 0137 // Array of card numbers 0138 QList<int> mCards; 0139 // Random generator 0140 QRandomGenerator mRandom; 0141 }; 0142 0143 #endif