Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

game.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de>
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this program; if not, write to the Free
00016  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 #ifndef GAME_H_INCLUDED
00020 #define GAME_H_INCLUDED
00021 
00022 #include <qwidget.h>
00023 #include <qcanvas.h>
00024 
00025 class QTimer;
00026 class JezzField;
00027 
00028 #define FIELD_WIDTH 26 
00029 #define FIELD_HEIGHT 26 
00030 
00031 class Arrow : public QCanvasSprite
00032 {
00033  public:
00034     Arrow(QCanvasPixmapArray* array, QCanvas* canvas);
00035 
00036     void update();
00037     void changeDirection();
00038 
00039  protected:
00040     bool m_vertical;
00041 };
00042 
00043 class Ball : public QCanvasSprite
00044 {
00045  public:
00046     Ball(QCanvasPixmapArray* array, QCanvas* canvas);
00047 
00048     void update();
00049     void advance(int stage);
00050     bool collide( double dx=0, double dy=0 );
00051 
00052  protected:
00053     int m_animDelay;
00054     int m_soundDelay;
00055 };
00056 
00057 
00058 class Wall : public QObject
00059 {
00060    Q_OBJECT
00061 public:
00062    enum Direction { Up, Down, Left, Right };
00063 
00064    Wall( JezzField *field, int x, int y, Direction dir, int tile,
00065          QObject *parent=0, const char *name=0 );
00066 
00067    void finish();
00068    void fill( bool black );
00069 
00070 signals:
00071    void finished( Wall *wall, int tile );
00072 
00073 public slots:
00074    void advance();
00075    void update();
00076 
00077 private:
00078    bool isFree( int x, int y );
00079 
00080    Direction m_dir;
00081    JezzField *m_field;
00082    int m_dx, m_dy;
00083    int m_x, m_y;
00084    int m_startX, m_startY;
00085    int m_tile;
00086    int m_delay;
00087    bool m_active;
00088 };
00089 
00090 
00091 class JezzField : public QCanvas
00092 {
00093    Q_OBJECT
00094 public:
00095    JezzField( QPixmap tiles, QObject* parent = 0, const char* name = 0 );
00096 
00097    void setGameTile( int x, int y, bool black );
00098 
00099 signals:
00100    void ballCollision( Ball *ball, int x, int y, int tile );
00101 
00102 private:
00103    friend class Ball;
00104    QPixmap m_tiles;
00105 
00106    void setPixmaps( QPixmap tiles );
00107    void emitBallCollisiton( Ball *ball, int x, int y, int tile )
00108       { emit ballCollision( ball, x, y, tile ); };
00109 
00110 };
00111 
00112 
00113 class JezzView : public QCanvasView
00114 {
00115   Q_OBJECT
00116 public:
00117    JezzView(QCanvas* viewing=0, QWidget* parent=0, const char* name=0, WFlags f=0);
00118    void changeCursor();
00119 
00120 signals:
00121    void buildWall( int x, int y, bool vertical );
00122 
00123 protected:
00124    void viewportMouseReleaseEvent( QMouseEvent * );
00125 
00126 private:
00127    bool m_vertical;
00128 };
00129 
00130 
00131 class JezzGame : public QWidget
00132 {
00133    Q_OBJECT
00134 
00135 public:
00136    JezzGame( int ballNum, QWidget *parent=0, const char *name=0 );
00137    ~JezzGame();
00138 
00139    int percent();
00140    void display( QString text, int size=20 );
00141    void changeCursor();
00142 
00143 signals:
00144    void died();
00145    void newPercent( int percent );
00146 
00147 public slots:
00148    void start();
00149    void stop();
00150 
00151 protected slots:
00152    void tick();
00153    void buildWall( int x, int y, bool vertical );
00154    void wallFinished( Wall *wall, int tile );
00155    void ballCollision( Ball *ball, int x, int y, int tile );
00156 
00157 protected:
00158    void makeBlack();
00159    void fill( int x, int y );
00160    void fillLeft( int x, int y );
00161    int m_buf[FIELD_WIDTH][FIELD_HEIGHT];
00162 
00163    JezzField *m_field;
00164    JezzView *m_view;
00165 
00166    Wall *m_wall1, *m_wall2;
00167 
00168    QList<Ball> m_balls;
00169    QCanvasPixmapArray *m_ballPixmaps;
00170    QCanvasPixmapArray *m_arrowPixmaps;
00171    QCanvasText *m_text;
00172    Arrow *arrow;
00173 
00174    QTimer *m_clock;
00175    bool m_running;
00176    int m_percent;
00177    bool m_pictured;
00178 
00179 };
00180 
00181 #endif

Generated on Sat Nov 5 16:17:19 2005 for OPIE by  doxygen 1.4.2