source: trunk/tutorial/t14/cannon.h@ 81

Last change on this file since 81 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
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
10class QTimer;
11
12
13#include <qwidget.h>
14
15
16class CannonField : public QWidget
17{
18 Q_OBJECT
19public:
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
29public slots:
30 void setAngle( int degrees );
31 void setForce( int newton );
32 void shoot();
33 void newTarget();
34 void setGameOver();
35 void restartGame();
36
37private slots:
38 void moveShot();
39
40signals:
41 void hit();
42 void missed();
43 void angleChanged( int );
44 void forceChanged( int );
45 void canShoot( bool );
46
47protected:
48 void paintEvent( QPaintEvent * );
49 void mousePressEvent( QMouseEvent * );
50 void mouseMoveEvent( QMouseEvent * );
51 void mouseReleaseEvent( QMouseEvent * );
52
53private:
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.