File indexing completed on 2024-04-21 04:05:23

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 DISPLAY_TWO_H
0009 #define DISPLAY_TWO_H
0010 
0011 // Qt includes
0012 #include <QGraphicsScene>
0013 #include <QHash>
0014 #include <QPixmap>
0015 
0016 // KF includes
0017 
0018 // Local includes
0019 #include "abstractdisplay.h"
0020 #include "deck.h"
0021 #include "lskat_debug.h"
0022 #include "player.h"
0023 #include "thememanager.h"
0024 
0025 // Forward declaration
0026 class PixmapSprite;
0027 class ScoreSprite;
0028 class TextSprite;
0029 
0030 /**
0031  * The display engine for a two player game.
0032  */
0033 class DisplayTwo : public AbstractDisplay, public virtual Themable
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038     /**
0039      * Constructor for the engine
0040      * @param deck The card deck
0041      * @param scene The graphics scene to work with
0042      * @param theme The theme manager
0043      * @param advancePeriod The advance period [ms]
0044      * @param parent The parent object
0045      */
0046     DisplayTwo(Deck *deck, QGraphicsScene *scene, ThemeManager *theme, int advancePeriod, QGraphicsView *parent);
0047 
0048     /**
0049      * Start the display.
0050      */
0051     void start() override;
0052 
0053     /**
0054      * Main theme function. Called by the theme manager. Redraw and resize
0055      * display.
0056      */
0057     void changeTheme() override;
0058 
0059     /**
0060      * Init a player on a given position. Create sprites etc.
0061      * @param player The player object
0062      * @param position The position to place the player (0,1)
0063      */
0064     void deal(Player *player, int position);
0065 
0066     /**
0067      * Play a card on the display. The card is moved from
0068      * its current position to the card deposit.
0069      * @param cardNumber The card number (0-7)
0070      * @param playerNumber The player number (0-1)
0071      * @param phase Movement phase (1st part, 2nd part, etc) [optional]
0072      */
0073     void play(int cardNumber, int playerNumber, int phase) override;
0074 
0075     /**
0076      * Turn a card on the display. The card is flipped backside
0077      * to frontside.
0078      * @param cardNumber The card number (0-31)
0079      */
0080     void turn(int cardNumber) override;
0081 
0082     /**
0083      * Remove the given card from the display.
0084      * @param winnerPosition  The position of the winner (0,1)
0085      * @param cardNumber The number of the card
0086      * @param delta Card offset from target position (0,1,2,...)
0087      */
0088     void remove(int winnerPosition, int cardNumber, int delta) override;
0089 
0090     /**
0091      * Display the score on the game board.
0092      * @param position Which player position
0093      * @param score The score to display
0094      */
0095     void showScore(int position, int score);
0096 
0097     /**
0098      * Display a text on the game board.
0099      * @param text The text to display
0100      */
0101     void showText(const QString &text);
0102 
0103     /**
0104      * Show the move icon for the given player
0105      * @param no The player number (-1: show none)
0106      */
0107     void showMove(int no = -1);
0108 
0109 public Q_SLOTS:
0110     /**
0111      * Convert the position of a mouse click to a logical
0112      * game position, that is position (up/down) and a
0113      * card number (0-7)
0114      * @param mouse        The mouse coordinates [screen coordinates]
0115      * @param playerNumber The resulting player number [0-1]
0116      * @param cardNumber   The resulting card number [0-7]
0117      */
0118     void convertMousePress(const QPoint &mouse, int &playerNumber, int &cardNumber) override;
0119 
0120     /**
0121      * Connect a player with the score widget by setting the player properties
0122      * to the score board.
0123      * @param player The player to set
0124      */
0125     void updatePlayer(Player *player);
0126 
0127     /**
0128      * Checks whether the shuffling is still ongoing (timer).
0129      */
0130     void checkShuffle();
0131 
0132 Q_SIGNALS:
0133     /**
0134      * Signal is emitted when the dealing animation is done.
0135      * Game can logically start then.
0136      */
0137     void dealingDone();
0138 
0139 protected:
0140     /**
0141      * Calculate the x,y position values from a card number.
0142      * @param cardNumber The card number [0-7]
0143      * @param x          The board x coordinate [0-3]
0144      * @param y          The board y coordinate [0-1]
0145      */
0146     void calcXYFromNumber(int cardNumber, int &x, int &y);
0147 
0148     /**
0149      * Get a card sprite for a card value.
0150      * @param cardValue The card value [0-31]
0151      * @return The sprite.
0152      */
0153     CardSprite *getCardSprite(int cardValue);
0154 
0155 private:
0156     // Pixmap for movement sprite
0157     QPixmap *mMovePixmap;
0158     // Store all move sprites
0159     QHash<int, PixmapSprite *> mMoveSprites;
0160     // The score sprites
0161     ScoreSprite *mScoreBoard[2];
0162     // The card area background sprites
0163     PixmapSprite *mCardArea[2];
0164     // The play area background sprite
0165     PixmapSprite *mPlayArea;
0166     // The text sprites
0167     TextSprite   *mText[3];
0168 };
0169 
0170 #endif