source:
trunk/tutorial/t14/cannon.h
Last change on this file was 2, checked in by , 20 years ago | |
---|---|
|
|
File size: 1.7 KB |
Line | |
---|---|
1 | /**************************************************************** |
2 | ** |
3 | ** Definition of CannonField class, Qt tutorial 14 |
4 | ** |
5 | ****************************************************************/ |
6 | |
7 | #ifndef CANNON_H |
8 | #define CANNON_H |
9 | |
10 | class QTimer; |
11 | |
12 | |
13 | #include <qwidget.h> |
14 | |
15 | |
16 | class CannonField : public QWidget |
17 | { |
18 | Q_OBJECT |
19 | public: |
20 | CannonField( QWidget *parent=0, const char *name=0 ); |
21 | |
22 | int angle() const { return ang; } |
23 | int force() const { return f; } |
24 | bool gameOver() const { return gameEnded; } |
25 | bool isShooting() const; |
26 | QSize sizeHint() const; |
27 | QSizePolicy sizePolicy() const; |
28 | |
29 | public slots: |
30 | void setAngle( int degrees ); |
31 | void setForce( int newton ); |
32 | void shoot(); |
33 | void newTarget(); |
34 | void setGameOver(); |
35 | void restartGame(); |
36 | |
37 | private slots: |
38 | void moveShot(); |
39 | |
40 | signals: |
41 | void hit(); |
42 | void missed(); |
43 | void angleChanged( int ); |
44 | void forceChanged( int ); |
45 | void canShoot( bool ); |
46 | |
47 | protected: |
48 | void paintEvent( QPaintEvent * ); |
49 | void mousePressEvent( QMouseEvent * ); |
50 | void mouseMoveEvent( QMouseEvent * ); |
51 | void mouseReleaseEvent( QMouseEvent * ); |
52 | |
53 | private: |
54 | void paintShot( QPainter * ); |
55 | void paintTarget( QPainter * ); |
56 | void paintBarrier( QPainter * ); |
57 | void paintCannon( QPainter * ); |
58 | QRect cannonRect() const; |
59 | QRect shotRect() const; |
60 | QRect targetRect() const; |
61 | QRect barrierRect() const; |
62 | bool barrelHit( const QPoint & ) const; |
63 | |
64 | int ang; |
65 | int f; |
66 | |
67 | int timerCount; |
68 | QTimer * autoShootTimer; |
69 | float shoot_ang; |
70 | float shoot_f; |
71 | |
72 | QPoint target; |
73 | |
74 | bool gameEnded; |
75 | bool barrelPressed; |
76 | }; |
77 | |
78 | |
79 | #endif // CANNON_H |
Note:
See TracBrowser
for help on using the repository browser.