1 | /* |
2 | * Copyright (C) 2000-2005 Stefan Schimanski <1Stein@gmx.de> |
3 | * Copyright (C) 2007 Tomasz Boczkowski <tboczkowski@onet.pl> |
4 | * |
5 | * This file is part of the KDE project "KBounce" |
6 | * |
7 | * KBounce is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. |
11 | * |
12 | * KBounce is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Library General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU Library General Public |
18 | * License along with KBounce; if not, write to the Free |
19 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #ifndef GAME_WIDGET_H |
23 | #define GAME_WIDGET_H |
24 | |
25 | #include <QGraphicsView> |
26 | #include <QGraphicsScene> |
27 | #include <QGraphicsPixmapItem> |
28 | |
29 | #include <KgSound> |
30 | #include <KgDifficulty> |
31 | #include <QMouseEvent> |
32 | |
33 | #include "board.h" |
34 | #include "renderer.h" |
35 | |
36 | class KBounceGameWidget : public QGraphicsView |
37 | { |
38 | Q_OBJECT |
39 | |
40 | public: |
41 | enum State { BeforeFirstGame, Running, BetweenLevels, Paused, Suspended, GameOver }; |
42 | |
43 | explicit KBounceGameWidget( QWidget* parent = 0 ); |
44 | ~KBounceGameWidget(); |
45 | |
46 | int level(); |
47 | int score(); |
48 | KBounceGameWidget::State state() const { return m_state; } |
49 | KBounceRenderer* renderer() { return &m_renderer; } |
50 | |
51 | QSize minimumSizeHint() const; |
52 | |
53 | public slots: |
54 | void closeGame(); |
55 | void newGame(); |
56 | void setPaused( bool ); |
57 | void settingsChanged(); |
58 | void setSuspended( bool ); |
59 | void levelChanged(); |
60 | |
61 | signals: |
62 | void gameOver(); |
63 | void levelChanged( int level ); |
64 | void scoreChanged( int score ); |
65 | void filledChanged( int filled ); |
66 | void livesChanged( int lives ); |
67 | void timeChanged( int time ); |
68 | void stateChanged( KBounceGameWidget::State state ); |
69 | |
70 | protected slots: |
71 | void onFillChanged( int filled ); |
72 | void onLivesChanged( int lives ); |
73 | void onWallDied(); |
74 | void tick(); |
75 | |
76 | protected: |
77 | virtual void resizeEvent( QResizeEvent* event ); |
78 | virtual void mouseReleaseEvent( QMouseEvent* event ); |
79 | void focusOutEvent(QFocusEvent *event); |
80 | void closeLevel(); |
81 | void newLevel(); |
82 | void updateCursor(); |
83 | void redraw(); |
84 | void setGameDifficulty(const KgDifficultyLevel *); |
85 | |
86 | KBounceRenderer m_renderer; |
87 | |
88 | QTimer* m_clock; |
89 | KBounceBoard* m_board; |
90 | State m_state; |
91 | int m_bonus; |
92 | int m_level; |
93 | int m_score; |
94 | int m_lives; |
95 | int m_time; |
96 | |
97 | QGraphicsPixmapItem* m_overlay; |
98 | void generateOverlay(); |
99 | |
100 | bool m_vertical; |
101 | QGraphicsScene m_scene; |
102 | KgSound m_soundTimeout; |
103 | }; |
104 | |
105 | #endif |
106 | |
107 | |