author | zecke <zecke> | 2004-02-17 16:24:32 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-17 16:24:32 (UTC) |
commit | 62b3979c6b23627eeca3b89f6feb491cdab97b08 (patch) (side-by-side diff) | |
tree | 8545969e2a2bf63a618b50e4b0d8fbf7f73bedbd | |
parent | 1207607ebbc59841718b79508fc222cb4eee9fde (diff) | |
download | opie-62b3979c6b23627eeca3b89f6feb491cdab97b08.zip opie-62b3979c6b23627eeca3b89f6feb491cdab97b08.tar.gz opie-62b3979c6b23627eeca3b89f6feb491cdab97b08.tar.bz2 |
Add the zLines port to Opie
-rw-r--r-- | apps/Games/zlines.desktop | 5 | ||||
-rw-r--r-- | noncore/games/zlines/ballpainter.cpp | 135 | ||||
-rw-r--r-- | noncore/games/zlines/ballpainter.h | 57 | ||||
-rw-r--r-- | noncore/games/zlines/cell.cpp | 41 | ||||
-rw-r--r-- | noncore/games/zlines/cell.h | 41 | ||||
-rw-r--r-- | noncore/games/zlines/cfg.h | 47 | ||||
-rw-r--r-- | noncore/games/zlines/config.in | 4 | ||||
-rw-r--r-- | noncore/games/zlines/field.cpp | 132 | ||||
-rw-r--r-- | noncore/games/zlines/field.h | 63 | ||||
-rw-r--r-- | noncore/games/zlines/klines.cpp | 214 | ||||
-rw-r--r-- | noncore/games/zlines/klines.h | 86 | ||||
-rw-r--r-- | noncore/games/zlines/linesboard.cpp | 591 | ||||
-rw-r--r-- | noncore/games/zlines/linesboard.h | 103 | ||||
-rw-r--r-- | noncore/games/zlines/main.cpp | 30 | ||||
-rw-r--r-- | noncore/games/zlines/mwidget.cpp | 84 | ||||
-rw-r--r-- | noncore/games/zlines/mwidget.h | 49 | ||||
-rw-r--r-- | noncore/games/zlines/prompt.cpp | 89 | ||||
-rw-r--r-- | noncore/games/zlines/prompt.h | 54 | ||||
-rw-r--r-- | noncore/games/zlines/zlines.pro | 10 | ||||
-rw-r--r-- | packages | 1 | ||||
-rw-r--r-- | pics/zlines/balls.png | bin | 0 -> 112765 bytes | |||
-rw-r--r-- | pics/zlines/field.png | bin | 0 -> 96 bytes | |||
-rw-r--r-- | pics/zlines/fire.png | bin | 0 -> 4397 bytes |
23 files changed, 1836 insertions, 0 deletions
diff --git a/apps/Games/zlines.desktop b/apps/Games/zlines.desktop new file mode 100644 index 0000000..7b74319 --- a/dev/null +++ b/apps/Games/zlines.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=Application +Exec=zlines +Icon=zlines/zlines +Name=Zlines diff --git a/noncore/games/zlines/ballpainter.cpp b/noncore/games/zlines/ballpainter.cpp new file mode 100644 index 0000000..c2b34e1 --- a/dev/null +++ b/noncore/games/zlines/ballpainter.cpp @@ -0,0 +1,135 @@ +/*************************************************************************** + ballpainter.cpp - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include <qpe/resource.h> + +#include <qapplication.h> +#include "ballpainter.h" +//#include "shotcounter.h" +#include <qpainter.h> +#include "linesboard.h" +//#include <qcolor.h> +#include <qjpegio.h> + + +#define PIXSIZE 21 + +int colorLinesArr[NCOLORS] = +{0x0000ff, 0x00ff00, 0xff0000, 0x00ffff, 0xff00ff, 0xffff00, 0x005080}; +// 0x00bbggrr +// red , green , blue , yellow , violet , cyan , brown + + + +BallPainter::BallPainter() + : QObject() +{ + createPixmap(); +} + +BallPainter::~BallPainter() +{ +} + +QPixmap* BallPainter::pixmap( enum Pixmaps pix ) +{ + QString name; + switch(pix) { + case Field: + name = QString::fromLatin1("zlines/field"); + break; + case Balls: + name = QString::fromLatin1("zlines/balls"); + break; + case Fire: + name = QString::fromLatin1("zlines/fire"); + break; + } + + return new QPixmap(Resource::loadPixmap(name) ); +} + +void BallPainter::createPixmap() +{ + // warning( kapp->kde_datadir() +"/klines/data/balls.bmp"); + backgroundPix = pixmap(Field); + QPixmap *balls = pixmap(Balls); + QPixmap *fire = pixmap(Fire); + if (balls->isNull() ||backgroundPix->isNull() || fire->isNull() ) + fatal("Cannot open data files.\nHave you correctly installed klines?"); + + warning("Pixsize %i", PIXSIZE); + for(int c=0; c<NCOLORS; c++) + { + for(int t=0; t<PIXTIME + FIREBALLS + BOOMBALLS + 1 ; t++) + { + imgCash[c][t] = new QPixmap(CELLSIZE, CELLSIZE); + QPainter p(imgCash[c][t]); + p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); + p.drawPixmap(1,1,(*balls),t*PIXSIZE,c*PIXSIZE,PIXSIZE,PIXSIZE); + } + for(int t=0; t < FIREPIX ; t++) + { + firePix[t] = new QPixmap(CELLSIZE, CELLSIZE); + QPainter p(firePix[t]); + p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); + p.drawPixmap(1,1,(*fire),t*PIXSIZE,0,PIXSIZE,PIXSIZE); + } + } + delete balls; + delete fire; +} + + +QPixmap* BallPainter::GetBall(int color, int animstep, int panim) +{ + // return backgroundPix; + + if( (color<0) || (color>=NCOLORS) || (animstep<0) || color == NOBALL ) + { + // warning("BallPainter::Background"); + return backgroundPix; + } + if ( panim == ANIM_JUMP ) + { + if ( ( animstep < 0 ) || ( animstep >= PIXTIME ) ) + return backgroundPix; + else + return imgCash[color][animstep]; + } + else if ( panim == ANIM_BURN ) + { + if ( animstep < FIREBALLS ) + return imgCash[color][animstep + PIXTIME + BOOMBALLS + 1]; + else if ( animstep < FIREBALLS + FIREPIX ) + return firePix[animstep - FIREBALLS]; + } + else if ( panim == ANIM_BORN ) + { + if ( animstep < BOOMBALLS ) + return imgCash[color][animstep + PIXTIME]; + else + return imgCash[color][NORMALBALL]; + } + // rest is not imlemented yet + return imgCash[color][NORMALBALL]; + +} + + diff --git a/noncore/games/zlines/ballpainter.h b/noncore/games/zlines/ballpainter.h new file mode 100644 index 0000000..339c70f --- a/dev/null +++ b/noncore/games/zlines/ballpainter.h @@ -0,0 +1,57 @@ +/*************************************************************************** + ballpainter.h - description + ------------------- +begin : Fri May 19 2000 +copyright : (C) 2000 by Roman Merzlyakov +email : roman@sbrf.barrt.ru +copyright : (C) 2000 by Roman Razilov +email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef __BALLPAINTER_H +#define __BALLPAINTER_H + +#include <qobject.h> +#include <qpixmap.h> +#include "cfg.h" + +#define CELLSIZE 21 + +class BallPainter : public QObject +{ +Q_OBJECT + + enum Pixmaps { + Field, + Balls, + Fire + }; + QPixmap *pixmap( enum Pixmaps ); + QPixmap* imgCash[NCOLORS][PIXTIME + FIREBALLS + BOOMBALLS + 1]; + QPixmap* backgroundPix; + QPixmap* firePix[FIREPIX]; + + void createPixmap(); + +public: + + BallPainter(); + ~BallPainter(); + + + // QPixmap* GetAnimatedBall(int color, int shot); + QPixmap* GetBall( int color, int animstep, int panim ); + QPixmap* GetNormalBall(int color) {return GetBall(color,0,ANIM_NO);} + QPixmap* GetBackgroundPix() { return GetBall(NOBALL,0,ANIM_NO);} + +}; + +#endif diff --git a/noncore/games/zlines/cell.cpp b/noncore/games/zlines/cell.cpp new file mode 100644 index 0000000..61d9431 --- a/dev/null +++ b/noncore/games/zlines/cell.cpp @@ -0,0 +1,41 @@ +/*************************************************************************** + cell.cpp - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "cell.h" + +Cell::Cell() +{ + clear(); +} + +void Cell::clear() +{ + color = NOBALL; + anim = ANIM_NO; +} + +Cell& Cell::moveBall(Cell& cell) +{ + *this = cell; + cell.clear(); + return *this; +} +Cell& Cell::operator= (const Cell& cell) +{ + color = cell.color; + anim = cell.anim; + return *this; +} diff --git a/noncore/games/zlines/cell.h b/noncore/games/zlines/cell.h new file mode 100644 index 0000000..a124f4c --- a/dev/null +++ b/noncore/games/zlines/cell.h @@ -0,0 +1,41 @@ +/*************************************************************************** + cell.h - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef __cell_h +#define __cell_h +#include "cfg.h" + + +// enum int AnimType {ANIM_NO,ANIM_BORN,ANIM_JUMP,ANIM_RUN,ANIM_BURN,ANIM_BLOCK}; + +class Cell { + int color; + int anim; +public: + Cell(); + + int getColor() {return ( color );} + int getAnim() {return ( anim );} + bool isFree() { return (( color == NOBALL )? true:false);} + + void setColor(int c) {color = c;} + void setAnim(int a) {anim = a;} + void clear(); + Cell& operator = (const Cell& c); + + Cell& moveBall(Cell& cell); +}; +#endif diff --git a/noncore/games/zlines/cfg.h b/noncore/games/zlines/cfg.h new file mode 100644 index 0000000..5bb5e0c --- a/dev/null +++ b/noncore/games/zlines/cfg.h @@ -0,0 +1,47 @@ +/*************************************************************************** + cfg.h - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef __CFG_H +#define __CFG_H 1 + +#define LINESVERSION "0.6.1" + +#define NCOLORS 7 +#define BALLSDROP 3 + +#define NOBALL -1 +#define PIXTIME 10 +#define FIREBALLS 4 +#define BOOMBALLS 4 +#define FIREPIX 5 +#define STEPTIME 3 +#define NORMALBALL PIXTIME + BOOMBALLS +#define TIMERCLOCK 25 + +enum Anim +{ + ANIM_NO, + ANIM_JUMP, + ANIM_RUN, + ANIM_BORN, + ANIM_BURN, + ANIM_YES, + ANIM_BLOCK +}; + +//#define _DBG_ + +#endif //__CFG_H diff --git a/noncore/games/zlines/config.in b/noncore/games/zlines/config.in new file mode 100644 index 0000000..521c013 --- a/dev/null +++ b/noncore/games/zlines/config.in @@ -0,0 +1,4 @@ + config ZLINES + boolean "opie-zlines ()" + default "y" + depends ( LIBQPE || LIBQPE-X11 ) diff --git a/noncore/games/zlines/field.cpp b/noncore/games/zlines/field.cpp new file mode 100644 index 0000000..2a87739 --- a/dev/null +++ b/noncore/games/zlines/field.cpp @@ -0,0 +1,132 @@ +/*************************************************************************** + field.cpp - description + ------------------- +begin : Fri May 19 2000 +copyright : (C) 2000 by Roman Merzlyakov +email : roman@sbrf.barrt.ru +copyright : (C) 2000 by Roman Razilov +email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include <stdlib.h> +#include "cfg.h" +#include "field.h" + +Field::Field(QWidget* parent, const char* name) + : QWidget( parent, name ) +{ + clearField(); +} + +Field::~Field() +{ +} + +void Field::clearField() +{ + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + field[y][x].clear(); +} +void Field::clearAnim() +{ + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + field[y][x].setAnim( ANIM_NO ); +} +int Field::deleteAnimatedBalls() +{ + int deleted = 0; + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + { + if ( field[y][x].getAnim() != ANIM_NO ) + { + deleted++; + field[y][x].clear(); + } + } + return deleted; +} + +bool Field::checkBounds(int x, int y) +{ + return (x>=0) && (x<NUMCELLSW) && (y>=0) && (y<NUMCELLSH); +} + +void Field::putBall(int x, int y, int color) +{ + if( checkBounds(x,y) ) + field[y][x].setColor(color); +} +/* + void Field::putBall(int x, int y, char color) + { + if( checkBounds(x,y) ){ + field[y][x].setColor(color); + erase5Balls(); + repaint(FALSE); + } + }*/ +void Field::moveBall(int xa, int ya, int xb, int yb) +{ + if( checkBounds(xa,ya) && checkBounds(xb,yb) && + field[yb][xb].isFree() && ( xa != xb || ya != yb) ) { + field[yb][xb].moveBall(field[ya][xa]); + } +} + +int Field::getBall(int x, int y) +{ + if( checkBounds(x,y) ) + return field[y][x].getColor(); + else + return NOBALL; +} +int Field::getAnim(int x, int y) +{ + if( checkBounds(x,y) ) + return field[y][x].getAnim(); + else + return NOBALL; +} +void Field::setAnim(int x, int y, int anim) +{ + if( checkBounds(x,y) ) + field[y][x].setAnim( anim ); +} + +void Field::removeBall(int x, int y ) +{ + if( checkBounds(x,y) ) field[y][x].clear(); +} + +int Field::freeSpace() +{ + int s = 0; + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + if(field[y][x].isFree()) s++; + return s; +} +void Field::saveUndo() +{ + void clearAnim(); + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + field_undo[y][x] = field[y][x]; +} +void Field::restoreUndo() +{ + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + field[y][x] = field_undo[y][x]; +} diff --git a/noncore/games/zlines/field.h b/noncore/games/zlines/field.h new file mode 100644 index 0000000..b6cf845 --- a/dev/null +++ b/noncore/games/zlines/field.h @@ -0,0 +1,63 @@ +/*************************************************************************** + field.h - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef __FIELD_H +#define __FIELD_H + +#include <qobject.h> +#include <qwidget.h> +#include "cell.h" + +// size of game field +#define NUMCELLSW 11 +#define NUMCELLSH 11 + +class Field: public QWidget +{ + Q_OBJECT +public: + void clearField(); + +protected: + Field(QWidget* parent, const char* name); + ~Field(); + + void putBall(int x, int y, int color); + void putBallRun(int x, int y, int color); + void removeBall(int x, int y ); + int getBall(int x, int y); + int getAnim(int x, int y); + void setAnim(int x, int y, int anim ); + void clearAnim(); + int deleteAnimatedBalls(); + void moveBall(int xa, int ya, int xb, int yb); + + bool checkBounds( int x, int y ); +// virtual int erase5Balls(){ return 0;} + int freeSpace(); + void saveUndo(); + void restoreUndo(); + +private: + Cell field[NUMCELLSH][NUMCELLSW]; + Cell field_undo[NUMCELLSH][NUMCELLSW]; +// void search5Balls(); + +}; + +#endif diff --git a/noncore/games/zlines/klines.cpp b/noncore/games/zlines/klines.cpp new file mode 100644 index 0000000..02ff0db --- a/dev/null +++ b/noncore/games/zlines/klines.cpp @@ -0,0 +1,214 @@ +/*************************************************************************** + klines.cpp - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/* changes +21.05.2000 Roman Razilov Menu game/Next +*/ +// +// The implementation of the KLines widget +// + +#include <qkeycode.h> +#include <qlabel.h> +#include <qpushbutton.h> +#include <qtooltip.h> +#include <qstring.h> +#include <stdlib.h> +#include <unistd.h> +#include <time.h> + +#include <qapplication.h> +#include <qmenubar.h> +#include <qpopupmenu.h> + + +#include "cfg.h" +#include <qstatusbar.h> +#include "klines.h" + + +/* + Creates the KLines widget and sets saved options (if any). + */ + +KLines::KLines(QWidget *par, const char* n, WFlags fl) : QMainWindow(par,n,fl) +{ + time_t t; + time(&t); + srand((unsigned int)t + getpid()); + + setCaption(QString("ZLines")); + + mwidget = new MainWidget(this); + setCentralWidget( mwidget ); + + lsb = mwidget->GetLsb(); + lPrompt = mwidget->GetPrompt(); + + menu = menuBar(); + game = new QPopupMenu; + edit = new QPopupMenu; + + game->insertItem(tr("&New game"), this, SLOT(stopGame()), CTRL+Key_N ); + game->insertSeparator(); + game->insertItem(tr("Ne&xt"), this, SLOT(makeTurn()), Key_N ); + game->insertSeparator(); + idMenuPrompt = game->insertItem( tr("&Show next"), this, SLOT(switchPrompt()), CTRL+Key_P ); + game->setCheckable(true); + game->setItemChecked(idMenuPrompt, lPrompt->getState()); + game->insertSeparator(); + game->insertItem(tr("&Quit"), qApp, SLOT(quit()), CTRL+Key_Q ); + + idMenuUndo = edit->insertItem(tr("Und&o"), this, SLOT(undo()), CTRL+Key_Z ); + + menu->insertItem( tr("&Game"), game ); + menu->insertItem( tr("&Edit"), edit ); + + menu->show(); + + score = 0; + prev_score = 0; + + mwidget->setMessage(tr("Points: 0")); + + startGame(); +} + +/* + Saves the options and destroys the KLines widget. + */ + +KLines::~KLines() +{ +} + +/* + Resize event of the KLines widget. + */ + +void KLines::resizeEvent( QResizeEvent *e ) +{ + QMainWindow::resizeEvent(e); +} + +void KLines::setMinSize() +{ + // setMinimumSize( gr->wHint(), gr->hHint() + menu->height() + stat->height() + + // tool->height() ); +} + +void KLines::startGame() +{ + score = 0; + prev_score = 0; + bUndo=TRUE; + + lsb->clearField(); + generateRandomBalls(); + placeBalls(); + generateRandomBalls(); + edit->setItemEnabled(idMenuUndo, FALSE ); + updateStat(); +} +void KLines::stopGame() +{ + debug("Klines::stopGame"); + endGame(); +} + +void KLines::searchBallsLine() +{ +} + +void KLines::generateRandomBalls() +{ + + for( int i = 0 ; i < BALLSDROP ; i++ ) + { + nextBalls_undo[i] = nextBalls[i]; + nextBalls[i] = bUndo ? + rand() % NCOLORS: + nextBalls_redo[i]; + } + lPrompt->SetBalls(nextBalls); +} + +void KLines::placeBalls() +{ + lsb->placeBalls(nextBalls); + debug("exit from placeBalls"); +} + +void KLines::undo() +{ + debug("Undo"); + if (!bUndo) + return; + for( int i = 0 ; i < BALLSDROP ; i++ ) + { + nextBalls_redo[i] = nextBalls[i]; + nextBalls[i] = nextBalls_undo[i]; + } + lPrompt->SetBalls(nextBalls); + lsb->undo(); + switchUndo(FALSE); +} + +void KLines::makeTurn() +{ + placeBalls(); + generateRandomBalls(); + switchUndo(TRUE); +} + +void KLines::addScore(int ballsErased) +{ if(ballsErased >= 5){ + score += 2*ballsErased*ballsErased - 20*ballsErased + 60 ; + if( !lPrompt->getState() ) score+= 1; + updateStat(); + }; +} + +void KLines::updateStat() +{ + mwidget->setMessage(tr(" Score: %1 ").arg(score)); +} + +void KLines::endGame() +{ + startGame(); +} + +void KLines::switchPrompt() +{ + lPrompt->setPrompt(!lPrompt->getState()); + game->setItemChecked(idMenuPrompt, lPrompt->getState()); +} + +void KLines::switchUndo(bool bu) +{ + bUndo = bu; + edit->setItemEnabled(idMenuUndo, bUndo ); +} + +void KLines::help() +{ + // KApplication::getKApplication()->invokeHTMLHelp("", ""); +} + + diff --git a/noncore/games/zlines/klines.h b/noncore/games/zlines/klines.h new file mode 100644 index 0000000..e36a4a7 --- a/dev/null +++ b/noncore/games/zlines/klines.h @@ -0,0 +1,86 @@ +/*************************************************************************** + klines.h - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef KLINES_H +#define KLINES_H + +#include <qwidget.h> +#include <qmenubar.h> +#include <qlabel.h> +#include <qpushbutton.h> +#include <qmainwindow.h> +#include "linesboard.h" +#include "mwidget.h" +#include "prompt.h" + +#define LSCORE 0 +#define LRECORD 1 + +class KLines : public QMainWindow +{ + Q_OBJECT +public: + KLines(QWidget *parent,const char* name, WFlags f); + ~KLines(); + + static QString appName() { return QString::fromLatin1("zlines"); } + +public slots: + void startGame(); + void stopGame(); + void makeTurn(); + void addScore(int ballsErased); + void switchPrompt(); + void help(); + void undo(); + +protected: + void resizeEvent( QResizeEvent * ); + +private slots: + +// bool setSize( int w, int h ); + void setMinSize(); + +private: + QMenuBar *menu; + int idMenuPrompt; + int idMenuUndo; + + QPopupMenu *game; + QPopupMenu *edit; + QToolBar *tool; + QStatusBar *stat; + LinesBoard* lsb; + MainWidget *mwidget; + LinesPrompt *lPrompt; + + int score, prev_score; + + int nextBalls[BALLSDROP]; + int nextBalls_undo[BALLSDROP]; + int nextBalls_redo[BALLSDROP]; + bool bUndo; + + void searchBallsLine(); + void generateRandomBalls(); + void placeBalls(); + void updateStat(); + void endGame(); + void switchUndo( bool bu ); +}; + +#endif diff --git a/noncore/games/zlines/linesboard.cpp b/noncore/games/zlines/linesboard.cpp new file mode 100644 index 0000000..0965b2c --- a/dev/null +++ b/noncore/games/zlines/linesboard.cpp @@ -0,0 +1,591 @@ +/*************************************************************************** + linesboard.cpp - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include <qpainter.h> +#include <qpixmap.h> +#include <qcolor.h> +#include <qkeycode.h> +#include <stdlib.h> + +#include "linesboard.h" + +/* + Constructs a LinesBoard widget. +*/ + +LinesBoard::LinesBoard( BallPainter * abPainter, QWidget* parent, const char* name ) + : Field( parent, name ) +{ + anim = ANIM_NO; +// waypos = 0; +// waylen = 0; +// jumpingRow = -1; +// jumpingCol = -1; + painting = 0; + way = new Waypoints[NUMCELLSW*NUMCELLSH]; + + bPainter = abPainter; + + setFocusPolicy( NoFocus ); + setBackgroundColor( gray ); + + setMouseTracking( FALSE ); + setFixedSize(wHint(), hHint()); + + timer = new QTimer(this); + connect( timer, SIGNAL(timeout()), SLOT(timerSlot()) ); + timer->start( TIMERCLOCK, FALSE ); + +} + +/* + Destructor: deallocates memory for contents +*/ + +LinesBoard::~LinesBoard() +{ + // debug("stop"); + timer->stop(); + delete timer; + delete []way; +} + + +void LinesBoard::placeBalls(int pnextBalls[BALLSDROP]) +{ + debug("LinesBoard::placeBalls( )"); + for(int i=0; i < BALLSDROP; i++){ + nextBalls[i] = pnextBalls[i]; + } + nextBallToPlace = 0; + placeBall(); + debug("LinesBoard::placeBalls End "); +} +void LinesBoard::placeBall( ) +{ + int color = nextBalls[nextBallToPlace]; + debug("LinesBoard::placeBall( ) color=%i, nextBallToPlace = %i", color, nextBallToPlace); + char* xx = (char*)malloc( sizeof(char)*NUMCELLSW*NUMCELLSH ); + char* yy = (char*)malloc( sizeof(char)*NUMCELLSW*NUMCELLSH ); +// int nb=3; +// if( freeSpace() < 3) nb = freeSpace(); + int empty=0; + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + if( getBall(x,y) == NOBALL ) + { + xx[empty] = x; + yy[empty] = y; + empty++; + }; +// debug("empty = %i",empty); + if ( empty > 0) + { + int pos = rand()%empty; + putBall( xx[pos], yy[pos], color ); + clearAnim(); + setAnim( xx[pos], yy[pos], ANIM_BORN ); + nextBallToPlace++; + AnimStart(ANIM_BORN); + free(xx); + free(yy); + } + else + { + free(xx); + free(yy); + emit endGame(); + } + debug("LinesBoard::placeBall END"); +} + + +/*id LinesBoard::doAfterBalls() { + erase5Balls(); + repaint(FALSE); +} +*/ +/* + Sets the size of the table +*/ + +int LinesBoard::width() { return CELLSIZE * NUMCELLSW; } +int LinesBoard::height() { return CELLSIZE * NUMCELLSH; } +int LinesBoard::wHint() { return width(); } +int LinesBoard::hHint() { return height(); } + + + +void LinesBoard::paintEvent( QPaintEvent* ) +{ +// debug("LinesBoard::paintEvent "); + QPixmap pixmap(width(), height()); + QPainter paint(&pixmap, this); + + for( int y=0; y < NUMCELLSH; y++ ){ + for( int x=0; x < NUMCELLSW; x++ ){ + if( getBall(x,y) == NOBALL ) + { +// debug("draw empty %i %i", x, y ); + paint.drawPixmap(x*CELLSIZE, y*CELLSIZE, *(bPainter->GetBackgroundPix()) ); + } + else + { +// debug("draw empty %i %i %c", x, y, getBall(x,y) ); + paint.drawPixmap(x*CELLSIZE, y*CELLSIZE, + *(bPainter->GetBall(getBall(x,y),animstep,getAnim(x,y)))); + } + } + } + + bitBlt(this, 0,0, &pixmap, 0,0, width(), height(), CopyROP); +} + +/* + Handles mouse press events for the LinesBoard widget. +*/ +void LinesBoard::mousePressEvent( QMouseEvent* e ) +{ + debug("LinesBoard::mousePressEvent START"); + int curRow = e->y() / CELLSIZE; + int curCol = e->x() / CELLSIZE; + //debug + debug("Mouse pressed: curRow=%i, curCol=%i", curRow, curCol); + + //check range + if (!checkBounds( curCol, curRow ) ) + return; +// if( running || anim != ANIM_NO ) return; + if(anim != ANIM_JUMP && anim != ANIM_NO) return; + if ( anim == ANIM_JUMP ) + { + if ( getBall(curCol,curRow) == NOBALL ) + { + if(existPath(jumpingCol, jumpingRow, curCol, curRow)) + { + saveUndo(); + AnimStart(ANIM_RUN); + } + } + else + AnimJump(curCol,curRow); + } + else + AnimJump(curCol,curRow); + debug("LinesBoard::mousePressEvent END"); +} +void LinesBoard::AnimJump(int x, int y ) { + debug("LinesBoard::AnimJump( %i,%i)", x,y ); + if ( getBall(x,y) != NOBALL ) + if (!( anim == ANIM_JUMP && jumpingCol == x && jumpingRow == y )) + if ( AnimEnd() ) + { + clearAnim(); + setAnim(x,y,ANIM_JUMP); + jumpingCol = x; + jumpingRow = y; + AnimStart(ANIM_JUMP); + } + debug("LinesBoard::AnimJump END"); +} +void LinesBoard::AnimStart(int panim) { + debug("LinesBoard::AnimStart( %i )", panim); + if (anim != ANIM_NO) + AnimEnd(); + animstep = 0; + animdelaystart = 1; + switch(panim) { + case ANIM_NO: + break; + case ANIM_BORN: + debug("LinesBoard::AnimStart( ANIM_BORN )"); + animdelaystart=1; + animmax = BOOMBALLS; + break; + case ANIM_JUMP: + direction = -1; + animstep = 4; + animmax = PIXTIME -1; + break; + case ANIM_RUN: + animdelaystart=3; + // do first step on next timer; + animdelaycount = 0; + // animmax already set + break; + case ANIM_BURN: + animdelaystart=1; + animmax = FIREBALLS + FIREPIX - 1; + break; + default: + ; + } + anim = panim; + animdelaycount = animdelaystart; + debug("LinesBoard::AnimStart END"); +} +int LinesBoard::AnimEnd( ) +{ + debug("LinesBoard::AnimEnd( %i )",anim ); + if (anim == ANIM_NO ) return true; + int oldanim = anim; + anim = ANIM_NO; + if (oldanim == ANIM_RUN) { + if (animstep != animmax) { + moveBall(way[animstep].x,way[animstep].y,way[animmax].x,way[animmax].y); + } + if ( erase5Balls() == 0 ) { + // debug("end turn"); + emit endTurn(); + debug("LinesBoard::AnimEnd END true 1"); + return true; + } + else + debug("LinesBoard::AnimEnd END false 2"); + return false; + } else if ( oldanim == ANIM_BURN ) + { + emit eraseLine( deleteAnimatedBalls() ); + repaint(FALSE); + if ( nextBallToPlace < BALLSDROP ) + { + placeBall(); + // continue with born + debug("LinesBoard::AnimEnd END false 3"); + return false; + } + else + { + // emit endTurn(); + debug("LinesBoard::AnimEnd END true 4"); + return true; + } + } else if ( oldanim == ANIM_BORN ) + { + if ( erase5Balls() == 0 ) + { + if ( freeSpace() > 0) + { + if ( nextBallToPlace < BALLSDROP ) + { + placeBall(); + debug("LinesBoard::AnimEnd END false 5"); + return false; + } + else + { + debug("LinesBoard::AnimEnd END true 6"); + return true; + } + } + else + { + debug("emit endGame"); + emit endGame(); + debug("LinesBoard::AnimEnd END false 7"); + return false; + } + } + else + { + // wait for user input + debug("LinesBoard::AnimEnd END true 8"); + return true; + } + } + else + { + debug("LinesBoard::AnimEnd END true"); + return true; + } + return true; +} +void LinesBoard::AnimNext() { + if ( anim != ANIM_NO ) + { + debug("LinesBoard::AnimNext( ) anim %i animstep %i",anim,animstep); + if ( anim == ANIM_JUMP ) { + if ( (direction > 0 && animstep == animmax) || ( direction < 0 && animstep == 0)) + direction = -direction; + animstep += direction; + repaint(FALSE); + } else { + if ( animstep >= animmax ) + AnimEnd(); + else { + animdelaycount--; + if (animdelaycount <= 0) { + debug("LinesBoard::AnimNext step %i", animstep); + if ( anim == ANIM_RUN ) + moveBall(way[animstep].x,way[animstep].y,way[animstep+1].x,way[animstep+1].y); + animstep++; + animdelaycount = animdelaystart; + repaint( FALSE ); + } + } + } + debug("LinesBoard::AnimNext END"); + } +} +int LinesBoard::getAnim( int x, int y ) +{ +// debug("LinesBoard::getAnim( %i,%i )",x,y); + return (( Field::getAnim(x,y) != ANIM_NO )? anim : ANIM_NO); +} + +void LinesBoard::timerSlot() +{ +// debug("LinesBoard::Timer() anim = %i",anim ); + AnimNext(); +} + +int LinesBoard::erase5Balls() +{ + //debug + debug("LinesBoard::erase5Balls()"); + + int nb=5; // minimum balls for erasure + + bool bit_erase[NUMCELLSH][NUMCELLSW]; //bool array for balls, that must be erased + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + bit_erase[y][x] = false; + + int color,newcolor; + int count; + //for horisontal + //debug("entering to horiz"); + + for(int y=0; y<NUMCELLSH; y++) { + count = 1; + color = NOBALL; + for(int x=0; x<NUMCELLSW; x++){ + if ( (newcolor = getBall(x,y)) == color) { + if ( color != NOBALL) { + count++; + if ( count >= nb ) + if ( count == nb ) + for (int i = 0; i < nb; i++) + bit_erase[y][x-i] = true; + else bit_erase[y][x] = true; + } + } else { + color = newcolor; + count = 1; + } + } + } + + //for vertical + //debug("entering to vert"); + for(int x=0; x<NUMCELLSW; x++) { + count = 0; + color = NOBALL; + for(int y=0; y<NUMCELLSH; y++){ + if ( (newcolor = getBall(x,y)) == color) { + if ( color != NOBALL) { + count++; + if ( count >= nb ) + if ( count == nb ) + for (int i = 0; i < nb; i++) + bit_erase[y-i][x] = true; + else bit_erase[y][x] = true; + } + } else { + color = newcolor; + count = 1; + } + } + } + + + // debug("entering to diag1"); + //for left-down to rigth-up diagonal + for ( int xs = NUMCELLSW-1,ys = NUMCELLSH-nb; xs >= nb-1; ) { + count = 0; + color = NOBALL; + for ( int x = xs, y = ys; x >= 0 && y < NUMCELLSH; x--, y++ ) { + if ( (newcolor = getBall(x,y)) == color) { + if ( color != NOBALL) { + count++; + if ( count >= nb ) + if ( count == nb ) + for (int i = 0; i < nb; i++) + bit_erase[y-i][x+i] = true; + else bit_erase[y][x] = true; + } + } else { + color = newcolor; + count = 1; + } + } + if ( ys > 0 ) ys--; else xs--; + } + + //debug("entering to diag2"); + + //for left-up to rigth-down diagonal + for ( int xs = 0,ys = NUMCELLSH-nb; xs <= NUMCELLSW-nb; ) + { + count = 0; + color = NOBALL; + for ( int x = xs, y = ys; x < NUMCELLSW && y < NUMCELLSH; x++, y++ ) + { + if ( (newcolor = getBall(x,y)) == color) + { + if ( color != NOBALL) + { + count++; + if ( count >= nb ) + if ( count == nb ) + for (int i = 0; i < nb; i++) + bit_erase[y-i][x-i] = true; + else + bit_erase[y][x] = true; + } + } + else + { + color = newcolor; + count = 1; + } + } + if ( ys > 0 ) ys--; else xs++; + } + + //remove all lines balls, that more than nb + int cb=0; + for(int y=0; y < NUMCELLSH; y++) + for(int x=0; x < NUMCELLSW; x++) + { + if (bit_erase[y][x]) + { + setAnim(x,y,ANIM_YES); + cb++; + } + else + { + setAnim(x,y,ANIM_NO); + } + } + //debug + debug("LinesBoard::erase5Balls marked %i balls", cb); + if ( cb > 0 ) + { + AnimStart(ANIM_BURN); + //emit eraseLine(cb); + } + + //debug + debug("LinesBoard::erase5Balls END"); + return cb; +} + + +#define GO_EMPTY 4 +#define GO_A 5 +#define GO_B 6 +#define GO_BALL 7 + +bool LinesBoard::existPath(int bx, int by, int ax, int ay) +{ + debug("LinesBoard::existPath( %i, %i, %i, %i )", bx, by, ax, ay); + int dx[4]={1,-1, 0, 0}; + int dy[4]={0, 0, 1,-1}; + + // debug("path %i %i %i %i",bx,by,ax,ay); + if (getBall(ax,ay) != NOBALL) + return false; + + char pf[NUMCELLSH][NUMCELLSW]; + for(int y=0; y<NUMCELLSH; y++) + for(int x=0; x<NUMCELLSW; x++) + pf[y][x] = (getBall(x,y) == NOBALL) ? GO_EMPTY:GO_BALL; + + Waypoints lastchanged[2][NUMCELLSH*NUMCELLSW]; + + int lastChangedCount[2]; + int currentchanged = 0; + int nextchanged = 1; + lastchanged[currentchanged][0].x = ax; + lastchanged[currentchanged][0].y = ay; + lastChangedCount[currentchanged] = 1; + pf[ay][ax]=GO_A; + pf[by][bx]=GO_B; + + // int expanded; + bool B_reached = false; + + do + { + lastChangedCount[nextchanged] = 0; + for(int dir=0; dir<4; dir++) + { + for ( int i = 0 ; i < lastChangedCount[currentchanged]; i++ ) + { + int nx = lastchanged[currentchanged][i].x + dx[dir]; + int ny = lastchanged[currentchanged][i].y + dy[dir]; + if( (nx>=0) && (nx<NUMCELLSW) && (ny>=0) && (ny<NUMCELLSH) ) + { + if( pf[ny][nx]==GO_EMPTY ||( nx==bx && ny==by )) + { + pf[ny][nx] = dir; + lastchanged[nextchanged][lastChangedCount[nextchanged]].x = nx; + lastchanged[nextchanged][lastChangedCount[nextchanged]].y = ny; + lastChangedCount[nextchanged]++; + }; + if( (nx==bx) && (ny==by) ) + { + B_reached = true; + break; + } + } + } + } + nextchanged = nextchanged ^ 1; + currentchanged = nextchanged ^ 1; + // debug("currentchanged %i lastChangedCount[currentchanged] %i", + // currentchanged,lastChangedCount[currentchanged]); + } while(!B_reached && lastChangedCount[currentchanged] != 0); + //debug("B_reached %i ", B_reached ); + + if (B_reached) { + AnimStart( ANIM_BLOCK); + animmax = 0; +// waypos = 0; + int x, y,dir; + for( x = bx, y = by,dir; (dir = pf[y][x]) != GO_A;x -=dx[dir],y -= dy[dir]) { + way[animmax].x = x; + way[animmax].y = y; + //debug("%i %i %i %i",dir,waylen,x,y); + animmax++; + } + way[animmax].x = x; + way[animmax].y = y; + } + debug("LinesBoard::existPath END %s", B_reached?"true":"false" ); + return B_reached; +} + +void LinesBoard::undo() +{ + AnimEnd(); + restoreUndo(); + repaint( FALSE ); +} + diff --git a/noncore/games/zlines/linesboard.h b/noncore/games/zlines/linesboard.h new file mode 100644 index 0000000..97697cd --- a/dev/null +++ b/noncore/games/zlines/linesboard.h @@ -0,0 +1,103 @@ +/*************************************************************************** + linesboard.h - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef __linesboard_h +#define __linesboard_h + +#include <qwidget.h> +#include <qpixmap.h> +#include <qtimer.h> + +#include "field.h" +//#include "shotcounter.h" +#include "ballpainter.h" + +#ifdef Q_WS_QWS +# define debug (void) +#else +# define debug qDebug +#endif +#define fatal qFatal +#define warning qWarning + +class LinesBoard : public Field +{ + Q_OBJECT +public: + LinesBoard( BallPainter * abPainter, QWidget* parent=0, const char* name=0 ); + ~LinesBoard(); + + int width(); + int height(); + int wHint(); + int hHint(); +// void doAfterBalls(); + void placeBalls(int nextBalls[BALLSDROP]); + void undo(); + +signals: + void endTurn(); + void endGame(); + void eraseLine(int nb); + +private: + int anim; + + struct Waypoints { + int x,y; + } *way; + int nextBalls[BALLSDROP]; + + int animmax; + + //used for running and animation phase + int painting; + int animstep; + int animdelaycount; + int animdelaystart; + int direction; + + + int nextBallToPlace; + int jumpingCol; + int jumpingRow; + + + QTimer* timer; +// ShotCounter* shCounter; + BallPainter* bPainter; + + void paintEvent( QPaintEvent* ); + void mousePressEvent( QMouseEvent* ); + + void AnimStart(int panim); + void AnimNext(); + int AnimEnd(); + int getAnim(int x, int y ); // returns if the specifyed cell is animated.. + void AnimJump( int col, int row ); + + int erase5Balls(); + bool existPath(int ax, int ay, int bx, int by); + void placeBall(); + +protected slots: + void timerSlot(); + +}; + +#endif diff --git a/noncore/games/zlines/main.cpp b/noncore/games/zlines/main.cpp new file mode 100644 index 0000000..ff41f95 --- a/dev/null +++ b/noncore/games/zlines/main.cpp @@ -0,0 +1,30 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + /* + * Roman Razilov 2000-05-19 debug dummmy + * Roman Razilov 2000-05-21 qimgio +*/ + +#include <qglobal.h> + + +#include <opie/oapplicationfactory.h> +#include "klines.h" + +OPIE_EXPORT_APP( OApplicationFactory<KLines> ) diff --git a/noncore/games/zlines/mwidget.cpp b/noncore/games/zlines/mwidget.cpp new file mode 100644 index 0000000..6641fa2 --- a/dev/null +++ b/noncore/games/zlines/mwidget.cpp @@ -0,0 +1,84 @@ +/*************************************************************************** + mwidget.cpp - description + ------------------- +begin : Fri May 19 2000 +copyright : (C) 2000 by Roman Merzlyakov +email : roman@sbrf.barrt.ru +copyright : (C) 2000 by Roman Razilov +email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "mwidget.h" +#include <qlayout.h> +#include "ballpainter.h" +#include <qhbox.h> +#include <qlabel.h> + +MainWidget::MainWidget( QWidget* parent, const char* name ) + : QFrame( parent, name ) +{ + BallPainter *bPainter = new BallPainter(); + + QGridLayout *Form1Layout = new QGridLayout( this ); + Form1Layout->setSpacing( 4 ); + Form1Layout->setMargin( 4 ); + QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + Form1Layout->addItem( spacer, 0, 0 ); + + lsb = new LinesBoard(bPainter, this); + + Form1Layout->addWidget( lsb, 0, 1 ); + QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + Form1Layout->addItem( spacer_2, 0, 2 ); + + QHBox *bottom=new QHBox(this); + + mPoints=new QLabel(bottom); + bottom->setStretchFactor(mPoints, 2); + + lPrompt = new LinesPrompt(bPainter, bottom); + + Form1Layout->addWidget( bottom, 1, 1 ); + QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); + Form1Layout->addItem( spacer_3, 2, 1 ); + + + connect(lsb, SIGNAL(endTurn()), parent, SLOT(makeTurn())); + connect(lsb, SIGNAL(eraseLine(int)), parent, SLOT(addScore(int))); + connect(lsb, SIGNAL(endGame()), parent, SLOT(stopGame())); + + connect(lPrompt, SIGNAL(PromptPressed()), parent, SLOT(switchPrompt())); + +} + +void MainWidget::setMessage(const QString &message) +{ + mPoints->setText(message); +} + + +/* +Destructor: deallocates memory for contents + */ + +MainWidget::~MainWidget() +{ +} + +LinesBoard * MainWidget::GetLsb() +{ + return lsb; +} + +LinesPrompt * MainWidget::GetPrompt() +{ + return lPrompt; +} diff --git a/noncore/games/zlines/mwidget.h b/noncore/games/zlines/mwidget.h new file mode 100644 index 0000000..29d01ac --- a/dev/null +++ b/noncore/games/zlines/mwidget.h @@ -0,0 +1,49 @@ +/*************************************************************************** + mwidget.h - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef MWIDGET_H +#define MWIDGET_H + +#include <qwidget.h> +#include <qpixmap.h> +#include <qtimer.h> +#include <qframe.h> +#include "linesboard.h" +#include "prompt.h" + +class QLabel; + +class MainWidget : public QFrame +{ +Q_OBJECT + LinesBoard * lsb; + LinesPrompt * lPrompt; + QLabel *mPoints; + +public: + MainWidget( QWidget* parent=0, const char* name=0 ); + ~MainWidget(); + LinesBoard * GetLsb(); + LinesPrompt * GetPrompt(); + +public slots: + void setMessage(const QString &message); +}; + +#endif diff --git a/noncore/games/zlines/prompt.cpp b/noncore/games/zlines/prompt.cpp new file mode 100644 index 0000000..2834937 --- a/dev/null +++ b/noncore/games/zlines/prompt.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + prompt.cpp - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include <qpainter.h> +#include "prompt.h" + +LinesPrompt::LinesPrompt( BallPainter * abPainter, QWidget* parent, const char* name ) + : QWidget( parent, name ) +{ + + bPainter = abPainter; + + setFocusPolicy( NoFocus ); + setBackgroundColor( gray ); + + setMouseTracking( FALSE ); + setFixedSize(wPrompt(), hPrompt()); + + PromptEnabled = true; + cb[0]=NOBALL; + cb[1]=NOBALL; + cb[2]=NOBALL; +} + +LinesPrompt::~LinesPrompt() +{ +} + +int LinesPrompt::width() { return CELLSIZE * 3 ; } +int LinesPrompt::height() { return CELLSIZE ; } + +int LinesPrompt::wPrompt() { return CELLSIZE * 3 ; } +int LinesPrompt::hPrompt() { return CELLSIZE ; } + +void LinesPrompt::paintEvent( QPaintEvent* ) +{ + QPainter paint( this ); + if(PromptEnabled){ + paint.drawPixmap(0, 0, *(bPainter->GetNormalBall(cb[0])) ); + paint.drawPixmap(CELLSIZE, 0, *(bPainter->GetNormalBall(cb[1])) ); + paint.drawPixmap(2*CELLSIZE, 0, *(bPainter->GetNormalBall(cb[2])) ); + } + else{ + paint.drawPixmap(0, 0, *(bPainter->GetBackgroundPix()) ); + paint.drawPixmap(CELLSIZE, 0, *(bPainter->GetBackgroundPix()) ); + paint.drawPixmap(2*CELLSIZE, 0, *(bPainter->GetBackgroundPix()) ); + } +} + +/* + Handles mouse press events for the LinesPrompt widget. +*/ +void LinesPrompt::mousePressEvent( QMouseEvent* e ) +{ + emit PromptPressed(); +} + +void LinesPrompt::SetBalls( int *pcb ) +{ + for (int i = 0; i<BALLSDROP; i++) + cb[i] = pcb[i]; + + update(); +} + +bool LinesPrompt::getState() +{ + return PromptEnabled; +} +void LinesPrompt::setPrompt(bool enabled) +{ + PromptEnabled = enabled; + update(); +} diff --git a/noncore/games/zlines/prompt.h b/noncore/games/zlines/prompt.h new file mode 100644 index 0000000..d821ac4 --- a/dev/null +++ b/noncore/games/zlines/prompt.h @@ -0,0 +1,54 @@ +/*************************************************************************** + prompt.h - description + ------------------- + begin : Fri May 19 2000 + copyright : (C) 2000 by Roman Merzlyakov + email : roman@sbrf.barrt.ru + copyright : (C) 2000 by Roman Razilov + email : Roman.Razilov@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef PROMPT_H +#define PROMPT_H + +#include <qwidget.h> +#include "ballpainter.h" + +class LinesPrompt : public QWidget +{ + Q_OBJECT + + BallPainter* bPainter; + bool PromptEnabled; + int cb[BALLSDROP]; + + void paintEvent( QPaintEvent* ); + void mousePressEvent( QMouseEvent* ); + +public: + LinesPrompt( BallPainter * abPainter, QWidget * parent=0, const char * name=0 ); + ~LinesPrompt(); + + void setPrompt(bool enabled); + bool getState(); // enabled = true + void SetBalls( int *pcb ); + + int width(); + int height(); + int wPrompt(); + int hPrompt(); + +signals: + void PromptPressed(); + +}; + +#endif diff --git a/noncore/games/zlines/zlines.pro b/noncore/games/zlines/zlines.pro new file mode 100644 index 0000000..e3f8a29 --- a/dev/null +++ b/noncore/games/zlines/zlines.pro @@ -0,0 +1,10 @@ +CONFIG = qt quick-app +HEADERS = ballpainter.h cfg.h linesboard.h prompt.h cell.h field.h klines.h mwidget.h +SOURCES = ballpainter.cpp field.cpp klines.cpp main.cpp prompt.cpp cell.cpp linesboard.cpp mwidget.cpp +TARGET = zlines +LIBS += -lqpe +INCLUDEPATH += $(OPIEDIR)/include/ +DEPENDPATH += $(OPIEDIR)/include/ + + +include ($(OPIEDIR)/include.pro) @@ -170,32 +170,33 @@ CONFIG_TODAY_DATEBOOK core/pim/today/plugins/datebook datebook.pro CONFIG_TODAY_FORTUNE noncore/todayplugins/fortune fortune.pro CONFIG_TODAY_MAIL core/pim/today/plugins/mail mail.pro CONFIG_TODAY_STOCKTICKER noncore/todayplugins/stockticker/stockticker stockticker.pro CONFIG_TODAY_STOCKTICKERLIB noncore/todayplugins/stockticker/stocktickerlib stocktickerlib.pro CONFIG_TODAY_TODOLIST core/pim/today/plugins/todolist todolist.pro CONFIG_TODAY_WEATHER noncore/todayplugins/weather weather.pro CONFIG_TODO core/pim/todo todo.pro CONFIG_UBROWSER noncore/net/ubrowser ubrowser.pro CONFIG_UNIKEYBOARD inputmethods/unikeyboard unikeyboard.pro CONFIG_USERMANAGER noncore/settings/usermanager usermanager.pro CONFIG_VMEMO core/applets/vmemo vmemo.pro CONFIG_VOLUMEAPPLET core/applets/volumeapplet volumeapplet.pro CONFIG_VTAPPLET core/applets/vtapplet vtapplet.pro CONFIG_WAVPLUGIN core/multimedia/opieplayer/wavplugin wavplugin.pro CONFIG_WELLENREITER noncore/net/wellenreiter wellenreiter.pro CONFIG_WIRELESSAPPLET noncore/applets/wirelessapplet wirelessapplet.pro CONFIG_WLAN noncore/settings/networksettings/wlan wlan.pro CONFIG_PPP noncore/settings/networksettings/ppp ppp.pro CONFIG_WORDGAME noncore/games/wordgame wordgame.pro CONFIG_ZSAFE noncore/apps/zsafe zsafe.pro CONFIG_MAIN_TAB_EXAMPLE examples/main-tab example.pro CONFIG_SIMPLE_EXAMPLE examples/simple example.pro CONFIG_SIMPLE_ICON examples/simple-icon example.pro CONFIG_SIMPLE_MAIN examples/simple-main example.pro CONFIG_SIMPLE_PIM examples/simple-pim example.pro CONFIG_BIGSCREEN_EXAMPLE libopie/big-screen/example osplitter_mail.pro CONFIG_APPLET_EXAMPLE examples/applet example.pro CONFIG_TODAY_EXAMPLE examples/todayplugin example.pro CONFIG_EXAMPLE_MENU examples/menuapplet menuapplet.pro CONFIG_EXAMPLE_BOARD examples/inputmethod example.pro CONFIG_EXAMPLE_VPN examples/networksettings example.pro CONFIG_ZSAME noncore/games/zsame zsame.pro +CONFIG_ZLINES noncore/games/zlines zlines.pro diff --git a/pics/zlines/balls.png b/pics/zlines/balls.png Binary files differnew file mode 100644 index 0000000..846de25 --- a/dev/null +++ b/pics/zlines/balls.png diff --git a/pics/zlines/field.png b/pics/zlines/field.png Binary files differnew file mode 100644 index 0000000..ddab110 --- a/dev/null +++ b/pics/zlines/field.png diff --git a/pics/zlines/fire.png b/pics/zlines/fire.png Binary files differnew file mode 100644 index 0000000..9c9698d --- a/dev/null +++ b/pics/zlines/fire.png |