00001 /********************************************************************** 00002 ** Copyright (C) 2000 Trolltech AS. All rights reserved. 00003 ** 00004 ** This file is part of Qtopia Environment. 00005 ** 00006 ** This file may be distributed and/or modified under the terms of the 00007 ** GNU General Public License version 2 as published by the Free Software 00008 ** Foundation and appearing in the file LICENSE.GPL included in the 00009 ** packaging of this file. 00010 ** 00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 ** 00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00015 ** 00016 ** Contact info@trolltech.com if any conditions of this licensing are 00017 ** not clear to you. 00018 ** 00019 **********************************************************************/ 00020 #include <qcanvas.h> 00021 #include <qtimer.h> 00022 00023 class Snake : public QObject 00024 { 00025 Q_OBJECT 00026 00027 public: 00028 enum Direction{ left, right, up, down}; 00029 00030 Snake(QCanvas*); 00031 ~Snake(); 00032 void go(int newkey); 00033 void move(Direction dir); 00034 void changeHead(int last); 00035 void changeTail(); 00036 void detectCrash(); 00037 void createSnake(); 00038 void extendSnake(); 00039 int lookUpPiece(Direction currentdir, Direction newdir); 00040 void setScore(int amount); 00041 int getScore(); 00042 00043 signals: 00044 void dead(); 00045 void targethit(); 00046 void scorechanged(); 00047 00048 private slots: 00049 void moveSnake(); 00050 void increaseSpeed(); 00051 00052 private: 00053 QCanvasPixmapArray* snakeparts; 00054 QList<QCanvasSprite>snakelist; 00055 QTimer* autoMoveTimer; 00056 QCanvas* canvas; 00057 int grow; 00058 int last; 00059 int speed; 00060 int score; 00061 Direction currentdir; 00062 Direction newdir; 00063 }; 00064
1.4.2