1 #ifndef GAMETARGETCONTROL_H 2 #define GAMETARGETCONTROL_H 3 4 #include <QtGui> 5 6 #include "scaler.h" 7 8 //////////////////////////////////////////////////////////////////////////////// 9 10 const int TARGET_SIZE = 64; 11 12 class GameTarget 13 { 14 friend class GameTargetControl; 15 16 public: 17 enum CheckResult { Ignored, Used, Completed }; 18 19 GameTarget(QPixmap *pixOn, QPixmap *pixOff, int targetScore = 30); 20 virtual ~GameTarget(); 21 22 virtual void repaint(); 23 virtual void paint(QPainter &p); 24 25 void setOrder(int order); 26 27 virtual void setPos(const QPoint &coords); rect()28 QRect rect() const { return QRect( QPoint(DX(myX),DY(myY)), myPixmapBuffer.size() ); } 29 bool isHover(const QPoint &pos) const; 30 31 virtual CheckResult checkChain(int size, int id, int score); 32 hint()33 virtual QString hint() const { return ""; } 34 35 protected: 36 static void init(const QString &name, 37 QPixmap **pixOn, QPixmap **pixOff 38 ); 39 40 QPixmap *myPixmapOn, *myPixmapOff; 41 42 int myX,myY; 43 QPixmap myPixmapBuffer; 44 45 int myScore, myTargetScore; 46 47 struct GameTargetPrivate *priv; 48 }; 49 50 //////////////////////////////////////////////////////////////////////////////// 51 52 class GameTargetControl 53 { 54 public: 55 enum TargetsType { 56 TT_BASE, TT_COLOR, TT_NUMBER, TT_FALLING, 57 TT_RANDOM 58 }; 59 60 GameTargetControl(); 61 ~GameTargetControl(); 62 targetsLeft()63 inline int targetsLeft() const { return myTargets.count(); } targetsCreated()64 inline int targetsCreated() const { return myTargetsCreated; } 65 66 void initGraphics(); 67 68 void createTargets(TargetsType types = TT_RANDOM); 69 70 void checkChain(int size, int id, int score); 71 bool checkMouseHover(const QPoint &pos); 72 73 void paint(QPainter &p); 74 75 protected: 76 void reposite(); 77 78 int myTargetsCreated; 79 QList<GameTarget*> myTargets; 80 81 struct GameTargetControlPrivate *priv; 82 }; 83 84 extern GameTargetControl * targetControl; 85 86 //////////////////////////////////////////////////////////////////////////////// 87 88 #endif // GAMETARGETCONTROL_H 89