File indexing completed on 2024-11-10 06:45:25
0001 /* 0002 This file is part of the KDE project "KBounce" 0003 0004 SPDX-FileCopyrightText: 2000-2005 Stefan Schimanski <1Stein@gmx.de> 0005 SPDX-FileCopyrightText: 2007 Tomasz Boczkowski <tboczkowski@onet.pl> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef GAME_WIDGET_H 0011 #define GAME_WIDGET_H 0012 0013 #include <QGraphicsView> 0014 #include <QGraphicsScene> 0015 #include <QGraphicsPixmapItem> 0016 #include <QMouseEvent> 0017 0018 #include <KGameSound> 0019 #include <KGameDifficulty> 0020 0021 #include "board.h" 0022 #include "renderer.h" 0023 0024 class KBounceGameWidget : public QGraphicsView 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 enum State { BeforeFirstGame, Running, BetweenLevels, Paused, Suspended, GameOver }; 0030 0031 explicit KBounceGameWidget( QWidget* parent = nullptr ); 0032 ~KBounceGameWidget() override; 0033 0034 int level(); 0035 int score(); 0036 KBounceGameWidget::State state() const { return m_state; } 0037 KBounceRenderer* renderer() { return &m_renderer; } 0038 0039 QSize minimumSizeHint() const override; 0040 0041 public Q_SLOTS: 0042 void closeGame(); 0043 void newGame(); 0044 void setPaused( bool ); 0045 void settingsChanged(); 0046 void setSuspended( bool ); 0047 void handleLevelChanged(); 0048 0049 Q_SIGNALS: 0050 void gameOver(); 0051 void levelChanged( int level ); 0052 void scoreChanged( int score ); 0053 void filledChanged( int filled ); 0054 void livesChanged( int lives ); 0055 void timeChanged( int time ); 0056 void stateChanged( KBounceGameWidget::State state ); 0057 0058 protected Q_SLOTS: 0059 void onFillChanged( int filled ); 0060 void onLivesChanged( int lives ); 0061 void onWallDied(); 0062 void tick(); 0063 0064 protected: 0065 void resizeEvent( QResizeEvent* event ) override; 0066 void mouseReleaseEvent( QMouseEvent* event ) override; 0067 void focusOutEvent(QFocusEvent *event) override; 0068 void closeLevel(); 0069 void newLevel(); 0070 void updateCursor(); 0071 void redraw(); 0072 void setGameDifficulty(const KGameDifficultyLevel *); 0073 0074 KBounceRenderer m_renderer; 0075 0076 QTimer* m_clock; 0077 KBounceBoard* m_board; 0078 State m_state; 0079 int m_bonus; 0080 int m_level; 0081 int m_score; 0082 int m_lives; 0083 int m_time; 0084 0085 QGraphicsPixmapItem* m_overlay; 0086 void generateOverlay(); 0087 0088 bool m_vertical; 0089 QGraphicsScene m_scene; 0090 KGameSound m_soundTimeout; 0091 }; 0092 0093 #endif