File indexing completed on 2024-04-28 04:02:06

0001 /*
0002     This file is part of the KDE games kwin4 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_GAME_H
0009 #define DISPLAY_GAME_H
0010 
0011 // own
0012 #include "thememanager.h"
0013 // Qt
0014 #include <QGraphicsView>
0015 #include <QList>
0016 #include <QTimer>
0017 
0018 // Forward declaration
0019 class ThemeManager;
0020 class PieceSprite;
0021 class SpriteNotify;
0022 class PixmapSprite;
0023 class ScoreSprite;
0024 class ReflectionGraphicsScene;
0025 
0026 /**
0027  * The display engine for the actual game.
0028  */
0029 class DisplayGame : public QObject, public virtual Themeable
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     /**
0035      * Constructor for the game display.
0036      *  @param scene         The graphics scene
0037      *  @param theme         The theme manager
0038      *  @param parent        The parent window
0039      */
0040     DisplayGame(ReflectionGraphicsScene *scene, ThemeManager *theme, QGraphicsView *parent = nullptr);
0041 
0042     /**
0043      * Destructor
0044      */
0045     ~DisplayGame() override;
0046 
0047     /**
0048      * Start the display (setup and initialization)
0049      */
0050     void start();
0051 
0052     /**
0053      * Main theme function. Called by the theme manager. Redraw and resize
0054      * display.
0055      */
0056     void changeTheme() override;
0057 
0058     /**
0059      * Set a game piece to a certain position on the game board. If an animation
0060      * is requested the piece 'falls' to this position.
0061      * @param x         The x-position on the game board [0-6]
0062      * @param y         The y-position on the game board [0-5]
0063      * @param color     Which color to use for the piece [0:hide piece, 1: yellow, 2: red]
0064      * @param no        Which sprite to use for the piece [0-41]
0065      * @param animation True to use animation, false to just plot the piece
0066      * @return The sprite notification object. Its signal indicate the end of the animation.
0067      */
0068     SpriteNotify *displayPiece(int x, int y, int color, int no, bool animation);
0069 
0070     /**
0071      * Sets the movement indicator arrow to the given position.
0072      * @param x      The x position [0-6]
0073      * @param color  The arrow color [0:hide piece, 1: yellow, 2: red]
0074      */
0075     void displayArrow(int x, int color);
0076 
0077     /**
0078      * Sets the hint indicator on the game board. This is a little symbol to suggest
0079      * where the next move is recommended to go.
0080      * @param x         The x-position on the game board [0-6]
0081      * @param y         The y-position on the game board [0-5]
0082      * @param show      True to show the indicator, false to hide it.
0083      */
0084     void displayHint(int x, int y, bool show);
0085 
0086     /**
0087      * Sets on of the winning move indicator sprites on the game board.
0088      * They should be set on top of the winning pieces to show them.
0089      * @param x         The x-position on the game board [0-6]
0090      * @param y         The y-position on the game board [0-5]
0091      * @param no        Which sprite to use for the piece [0-3]
0092      */
0093     void displayStar(int x, int y, int no);
0094 
0095     /**
0096      * Transform the mouse coordinates to a game board movement coordinate.
0097      * That is a coordinate [0-6] corresponding to a move on the board.
0098      * @param pos  The mouse position.
0099      * @return     The game board position [0-6] or [-1] on error.
0100      */
0101     int mapMouseToMove(const QPoint &pos);
0102 
0103     /**
0104      * Shows the game over sprite.
0105      */
0106     void displayEnd();
0107 
0108     /**
0109      * Retrieve the score status sprite.
0110      * @return The score sprite.
0111      */
0112     ScoreSprite *score();
0113 
0114 protected Q_SLOTS:
0115     /**
0116      * Run the main game animation (if existent). This is done via a periodic timer.
0117      */
0118     void advance();
0119 
0120 private:
0121     // The theme manager
0122     ThemeManager *mTheme;
0123 
0124     // The grapics scene used for display
0125     ReflectionGraphicsScene *mScene;
0126 
0127     // The graphics view used for display
0128     QGraphicsView *mView;
0129 
0130     // List of all sprites used
0131     QList<QGraphicsItem *> mSprites;
0132 
0133     // List of all game pieces used #=42
0134     QList<PieceSprite *> mPieces;
0135 
0136     // The game boad sprite
0137     PixmapSprite *mBoard;
0138 
0139     // All arrow sprites
0140     QList<PixmapSprite *> mArrows;
0141 
0142     // The score sprite
0143     ScoreSprite *mScoreBoard;
0144 
0145     // The winning indicator sprites
0146     QList<PixmapSprite *> mStars;
0147 
0148     // The hint sprite
0149     PixmapSprite *mHint;
0150 
0151     // The time used for advance()
0152     QTimer *mTimer;
0153 };
0154 
0155 #endif