summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--apps/Games/zlines.desktop5
-rw-r--r--noncore/games/zlines/ballpainter.cpp135
-rw-r--r--noncore/games/zlines/ballpainter.h57
-rw-r--r--noncore/games/zlines/cell.cpp41
-rw-r--r--noncore/games/zlines/cell.h41
-rw-r--r--noncore/games/zlines/cfg.h47
-rw-r--r--noncore/games/zlines/config.in4
-rw-r--r--noncore/games/zlines/field.cpp132
-rw-r--r--noncore/games/zlines/field.h63
-rw-r--r--noncore/games/zlines/klines.cpp214
-rw-r--r--noncore/games/zlines/klines.h86
-rw-r--r--noncore/games/zlines/linesboard.cpp591
-rw-r--r--noncore/games/zlines/linesboard.h103
-rw-r--r--noncore/games/zlines/main.cpp30
-rw-r--r--noncore/games/zlines/mwidget.cpp84
-rw-r--r--noncore/games/zlines/mwidget.h49
-rw-r--r--noncore/games/zlines/prompt.cpp89
-rw-r--r--noncore/games/zlines/prompt.h54
-rw-r--r--noncore/games/zlines/zlines.pro10
-rw-r--r--packages1
-rw-r--r--pics/zlines/balls.pngbin0 -> 112765 bytes
-rw-r--r--pics/zlines/field.pngbin0 -> 96 bytes
-rw-r--r--pics/zlines/fire.pngbin0 -> 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 @@
1[Desktop Entry]
2Type=Application
3Exec=zlines
4Icon=zlines/zlines
5Name=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 @@
1/***************************************************************************
2 ballpainter.cpp - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20#include <qpe/resource.h>
21
22#include <qapplication.h>
23#include "ballpainter.h"
24//#include "shotcounter.h"
25#include <qpainter.h>
26#include "linesboard.h"
27//#include <qcolor.h>
28#include <qjpegio.h>
29
30
31#define PIXSIZE 21
32
33int colorLinesArr[NCOLORS] =
34{0x0000ff, 0x00ff00, 0xff0000, 0x00ffff, 0xff00ff, 0xffff00, 0x005080};
35// 0x00bbggrr
36// red , green , blue , yellow , violet , cyan , brown
37
38
39
40BallPainter::BallPainter()
41 : QObject()
42{
43 createPixmap();
44}
45
46BallPainter::~BallPainter()
47{
48}
49
50QPixmap* BallPainter::pixmap( enum Pixmaps pix )
51{
52 QString name;
53 switch(pix) {
54 case Field:
55 name = QString::fromLatin1("zlines/field");
56 break;
57 case Balls:
58 name = QString::fromLatin1("zlines/balls");
59 break;
60 case Fire:
61 name = QString::fromLatin1("zlines/fire");
62 break;
63 }
64
65 return new QPixmap(Resource::loadPixmap(name) );
66}
67
68void BallPainter::createPixmap()
69{
70 // warning( kapp->kde_datadir() +"/klines/data/balls.bmp");
71 backgroundPix = pixmap(Field);
72 QPixmap *balls = pixmap(Balls);
73 QPixmap *fire = pixmap(Fire);
74 if (balls->isNull() ||backgroundPix->isNull() || fire->isNull() )
75 fatal("Cannot open data files.\nHave you correctly installed klines?");
76
77 warning("Pixsize %i", PIXSIZE);
78 for(int c=0; c<NCOLORS; c++)
79 {
80 for(int t=0; t<PIXTIME + FIREBALLS + BOOMBALLS + 1 ; t++)
81 {
82 imgCash[c][t] = new QPixmap(CELLSIZE, CELLSIZE);
83 QPainter p(imgCash[c][t]);
84 p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE);
85 p.drawPixmap(1,1,(*balls),t*PIXSIZE,c*PIXSIZE,PIXSIZE,PIXSIZE);
86 }
87 for(int t=0; t < FIREPIX ; t++)
88 {
89 firePix[t] = new QPixmap(CELLSIZE, CELLSIZE);
90 QPainter p(firePix[t]);
91 p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE);
92 p.drawPixmap(1,1,(*fire),t*PIXSIZE,0,PIXSIZE,PIXSIZE);
93 }
94 }
95 delete balls;
96 delete fire;
97}
98
99
100QPixmap* BallPainter::GetBall(int color, int animstep, int panim)
101{
102 // return backgroundPix;
103
104 if( (color<0) || (color>=NCOLORS) || (animstep<0) || color == NOBALL )
105 {
106 // warning("BallPainter::Background");
107 return backgroundPix;
108 }
109 if ( panim == ANIM_JUMP )
110 {
111 if ( ( animstep < 0 ) || ( animstep >= PIXTIME ) )
112 return backgroundPix;
113 else
114 return imgCash[color][animstep];
115 }
116 else if ( panim == ANIM_BURN )
117 {
118 if ( animstep < FIREBALLS )
119 return imgCash[color][animstep + PIXTIME + BOOMBALLS + 1];
120 else if ( animstep < FIREBALLS + FIREPIX )
121 return firePix[animstep - FIREBALLS];
122 }
123 else if ( panim == ANIM_BORN )
124 {
125 if ( animstep < BOOMBALLS )
126 return imgCash[color][animstep + PIXTIME];
127 else
128 return imgCash[color][NORMALBALL];
129 }
130 // rest is not imlemented yet
131 return imgCash[color][NORMALBALL];
132
133}
134
135
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 @@
1/***************************************************************************
2 ballpainter.h - description
3 -------------------
4begin : Fri May 19 2000
5copyright : (C) 2000 by Roman Merzlyakov
6email : roman@sbrf.barrt.ru
7copyright : (C) 2000 by Roman Razilov
8email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#ifndef __BALLPAINTER_H
20#define __BALLPAINTER_H
21
22#include <qobject.h>
23#include <qpixmap.h>
24#include "cfg.h"
25
26#define CELLSIZE 21
27
28class BallPainter : public QObject
29{
30Q_OBJECT
31
32 enum Pixmaps {
33 Field,
34 Balls,
35 Fire
36 };
37 QPixmap *pixmap( enum Pixmaps );
38 QPixmap* imgCash[NCOLORS][PIXTIME + FIREBALLS + BOOMBALLS + 1];
39 QPixmap* backgroundPix;
40 QPixmap* firePix[FIREPIX];
41
42 void createPixmap();
43
44public:
45
46 BallPainter();
47 ~BallPainter();
48
49
50 // QPixmap* GetAnimatedBall(int color, int shot);
51 QPixmap* GetBall( int color, int animstep, int panim );
52 QPixmap* GetNormalBall(int color) {return GetBall(color,0,ANIM_NO);}
53 QPixmap* GetBackgroundPix() { return GetBall(NOBALL,0,ANIM_NO);}
54
55};
56
57#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 @@
1/***************************************************************************
2 cell.cpp - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Razilov
6 email : Roman.Razilov@gmx.de
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#include "cell.h"
18
19Cell::Cell()
20{
21 clear();
22}
23
24void Cell::clear()
25{
26 color = NOBALL;
27 anim = ANIM_NO;
28}
29
30Cell& Cell::moveBall(Cell& cell)
31{
32 *this = cell;
33 cell.clear();
34 return *this;
35}
36Cell& Cell::operator= (const Cell& cell)
37{
38 color = cell.color;
39 anim = cell.anim;
40 return *this;
41}
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 @@
1/***************************************************************************
2 cell.h - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Razilov
6 email : Roman.Razilov@gmx.de
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef __cell_h
18#define __cell_h
19#include "cfg.h"
20
21
22// enum int AnimType {ANIM_NO,ANIM_BORN,ANIM_JUMP,ANIM_RUN,ANIM_BURN,ANIM_BLOCK};
23
24class Cell {
25 int color;
26 int anim;
27public:
28 Cell();
29
30 int getColor() {return ( color );}
31 int getAnim() {return ( anim );}
32 bool isFree() { return (( color == NOBALL )? true:false);}
33
34 void setColor(int c) {color = c;}
35 void setAnim(int a) {anim = a;}
36 void clear();
37 Cell& operator = (const Cell& c);
38
39 Cell& moveBall(Cell& cell);
40};
41#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 @@
1/***************************************************************************
2 cfg.h - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Razilov
6 email : Roman.Razilov@gmx.de
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef __CFG_H
18#define __CFG_H 1
19
20#define LINESVERSION "0.6.1"
21
22#define NCOLORS 7
23#define BALLSDROP 3
24
25#define NOBALL -1
26#define PIXTIME 10
27#define FIREBALLS 4
28#define BOOMBALLS 4
29#define FIREPIX 5
30#define STEPTIME 3
31#define NORMALBALL PIXTIME + BOOMBALLS
32#define TIMERCLOCK 25
33
34enum Anim
35{
36 ANIM_NO,
37 ANIM_JUMP,
38 ANIM_RUN,
39 ANIM_BORN,
40 ANIM_BURN,
41 ANIM_YES,
42 ANIM_BLOCK
43};
44
45//#define _DBG_
46
47#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 @@
1 config ZLINES
2 boolean "opie-zlines ()"
3 default "y"
4 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 @@
1/***************************************************************************
2 field.cpp - description
3 -------------------
4begin : Fri May 19 2000
5copyright : (C) 2000 by Roman Merzlyakov
6email : roman@sbrf.barrt.ru
7copyright : (C) 2000 by Roman Razilov
8email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#include <stdlib.h>
20#include "cfg.h"
21#include "field.h"
22
23Field::Field(QWidget* parent, const char* name)
24 : QWidget( parent, name )
25{
26 clearField();
27}
28
29Field::~Field()
30{
31}
32
33void Field::clearField()
34{
35 for(int y=0; y<NUMCELLSH; y++)
36 for(int x=0; x<NUMCELLSW; x++)
37 field[y][x].clear();
38}
39void Field::clearAnim()
40{
41 for(int y=0; y<NUMCELLSH; y++)
42 for(int x=0; x<NUMCELLSW; x++)
43 field[y][x].setAnim( ANIM_NO );
44}
45int Field::deleteAnimatedBalls()
46{
47 int deleted = 0;
48 for(int y=0; y<NUMCELLSH; y++)
49 for(int x=0; x<NUMCELLSW; x++)
50 {
51 if ( field[y][x].getAnim() != ANIM_NO )
52 {
53 deleted++;
54 field[y][x].clear();
55 }
56 }
57 return deleted;
58}
59
60bool Field::checkBounds(int x, int y)
61{
62 return (x>=0) && (x<NUMCELLSW) && (y>=0) && (y<NUMCELLSH);
63}
64
65void Field::putBall(int x, int y, int color)
66{
67 if( checkBounds(x,y) )
68 field[y][x].setColor(color);
69}
70/*
71 void Field::putBall(int x, int y, char color)
72 {
73 if( checkBounds(x,y) ){
74 field[y][x].setColor(color);
75 erase5Balls();
76 repaint(FALSE);
77 }
78 }*/
79void Field::moveBall(int xa, int ya, int xb, int yb)
80{
81 if( checkBounds(xa,ya) && checkBounds(xb,yb) &&
82 field[yb][xb].isFree() && ( xa != xb || ya != yb) ) {
83 field[yb][xb].moveBall(field[ya][xa]);
84 }
85}
86
87int Field::getBall(int x, int y)
88{
89 if( checkBounds(x,y) )
90 return field[y][x].getColor();
91 else
92 return NOBALL;
93}
94int Field::getAnim(int x, int y)
95{
96 if( checkBounds(x,y) )
97 return field[y][x].getAnim();
98 else
99 return NOBALL;
100}
101void Field::setAnim(int x, int y, int anim)
102{
103 if( checkBounds(x,y) )
104 field[y][x].setAnim( anim );
105}
106
107void Field::removeBall(int x, int y )
108{
109 if( checkBounds(x,y) ) field[y][x].clear();
110}
111
112int Field::freeSpace()
113{
114 int s = 0;
115 for(int y=0; y<NUMCELLSH; y++)
116 for(int x=0; x<NUMCELLSW; x++)
117 if(field[y][x].isFree()) s++;
118 return s;
119}
120void Field::saveUndo()
121{
122 void clearAnim();
123 for(int y=0; y<NUMCELLSH; y++)
124 for(int x=0; x<NUMCELLSW; x++)
125 field_undo[y][x] = field[y][x];
126}
127void Field::restoreUndo()
128{
129 for(int y=0; y<NUMCELLSH; y++)
130 for(int x=0; x<NUMCELLSW; x++)
131 field[y][x] = field_undo[y][x];
132}
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 @@
1/***************************************************************************
2 field.h - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#ifndef __FIELD_H
20#define __FIELD_H
21
22#include <qobject.h>
23#include <qwidget.h>
24#include "cell.h"
25
26// size of game field
27#define NUMCELLSW 11
28#define NUMCELLSH 11
29
30class Field: public QWidget
31{
32 Q_OBJECT
33public:
34 void clearField();
35
36protected:
37 Field(QWidget* parent, const char* name);
38 ~Field();
39
40 void putBall(int x, int y, int color);
41 void putBallRun(int x, int y, int color);
42 void removeBall(int x, int y );
43 int getBall(int x, int y);
44 int getAnim(int x, int y);
45 void setAnim(int x, int y, int anim );
46 void clearAnim();
47 int deleteAnimatedBalls();
48 void moveBall(int xa, int ya, int xb, int yb);
49
50 bool checkBounds( int x, int y );
51// virtual int erase5Balls(){ return 0;}
52 int freeSpace();
53 void saveUndo();
54 void restoreUndo();
55
56private:
57 Cell field[NUMCELLSH][NUMCELLSW];
58 Cell field_undo[NUMCELLSH][NUMCELLSW];
59// void search5Balls();
60
61};
62
63#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 @@
1/***************************************************************************
2 klines.cpp - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19/* changes
2021.05.2000 Roman Razilov Menu game/Next
21*/
22//
23// The implementation of the KLines widget
24//
25
26#include <qkeycode.h>
27#include <qlabel.h>
28#include <qpushbutton.h>
29#include <qtooltip.h>
30#include <qstring.h>
31#include <stdlib.h>
32#include <unistd.h>
33#include <time.h>
34
35#include <qapplication.h>
36#include <qmenubar.h>
37#include <qpopupmenu.h>
38
39
40#include "cfg.h"
41#include <qstatusbar.h>
42#include "klines.h"
43
44
45/*
46 Creates the KLines widget and sets saved options (if any).
47 */
48
49KLines::KLines(QWidget *par, const char* n, WFlags fl) : QMainWindow(par,n,fl)
50{
51 time_t t;
52 time(&t);
53 srand((unsigned int)t + getpid());
54
55 setCaption(QString("ZLines"));
56
57 mwidget = new MainWidget(this);
58 setCentralWidget( mwidget );
59
60 lsb = mwidget->GetLsb();
61 lPrompt = mwidget->GetPrompt();
62
63 menu = menuBar();
64 game = new QPopupMenu;
65 edit = new QPopupMenu;
66
67 game->insertItem(tr("&New game"), this, SLOT(stopGame()), CTRL+Key_N );
68 game->insertSeparator();
69 game->insertItem(tr("Ne&xt"), this, SLOT(makeTurn()), Key_N );
70 game->insertSeparator();
71 idMenuPrompt = game->insertItem( tr("&Show next"), this, SLOT(switchPrompt()), CTRL+Key_P );
72 game->setCheckable(true);
73 game->setItemChecked(idMenuPrompt, lPrompt->getState());
74 game->insertSeparator();
75 game->insertItem(tr("&Quit"), qApp, SLOT(quit()), CTRL+Key_Q );
76
77 idMenuUndo = edit->insertItem(tr("Und&o"), this, SLOT(undo()), CTRL+Key_Z );
78
79 menu->insertItem( tr("&Game"), game );
80 menu->insertItem( tr("&Edit"), edit );
81
82 menu->show();
83
84 score = 0;
85 prev_score = 0;
86
87 mwidget->setMessage(tr("Points: 0"));
88
89 startGame();
90}
91
92/*
93 Saves the options and destroys the KLines widget.
94 */
95
96KLines::~KLines()
97{
98}
99
100/*
101 Resize event of the KLines widget.
102 */
103
104void KLines::resizeEvent( QResizeEvent *e )
105{
106 QMainWindow::resizeEvent(e);
107}
108
109void KLines::setMinSize()
110{
111 // setMinimumSize( gr->wHint(), gr->hHint() + menu->height() + stat->height() +
112 // tool->height() );
113}
114
115void KLines::startGame()
116{
117 score = 0;
118 prev_score = 0;
119 bUndo=TRUE;
120
121 lsb->clearField();
122 generateRandomBalls();
123 placeBalls();
124 generateRandomBalls();
125 edit->setItemEnabled(idMenuUndo, FALSE );
126 updateStat();
127}
128void KLines::stopGame()
129{
130 debug("Klines::stopGame");
131 endGame();
132}
133
134void KLines::searchBallsLine()
135{
136}
137
138void KLines::generateRandomBalls()
139{
140
141 for( int i = 0 ; i < BALLSDROP ; i++ )
142 {
143 nextBalls_undo[i] = nextBalls[i];
144 nextBalls[i] = bUndo ?
145 rand() % NCOLORS:
146 nextBalls_redo[i];
147 }
148 lPrompt->SetBalls(nextBalls);
149}
150
151void KLines::placeBalls()
152{
153 lsb->placeBalls(nextBalls);
154 debug("exit from placeBalls");
155}
156
157void KLines::undo()
158{
159 debug("Undo");
160 if (!bUndo)
161 return;
162 for( int i = 0 ; i < BALLSDROP ; i++ )
163 {
164 nextBalls_redo[i] = nextBalls[i];
165 nextBalls[i] = nextBalls_undo[i];
166 }
167 lPrompt->SetBalls(nextBalls);
168 lsb->undo();
169 switchUndo(FALSE);
170}
171
172void KLines::makeTurn()
173{
174 placeBalls();
175 generateRandomBalls();
176 switchUndo(TRUE);
177}
178
179void KLines::addScore(int ballsErased)
180{ if(ballsErased >= 5){
181 score += 2*ballsErased*ballsErased - 20*ballsErased + 60 ;
182 if( !lPrompt->getState() ) score+= 1;
183 updateStat();
184 };
185}
186
187void KLines::updateStat()
188{
189 mwidget->setMessage(tr(" Score: %1 ").arg(score));
190}
191
192void KLines::endGame()
193{
194 startGame();
195}
196
197void KLines::switchPrompt()
198{
199 lPrompt->setPrompt(!lPrompt->getState());
200 game->setItemChecked(idMenuPrompt, lPrompt->getState());
201}
202
203void KLines::switchUndo(bool bu)
204{
205 bUndo = bu;
206 edit->setItemEnabled(idMenuUndo, bUndo );
207}
208
209void KLines::help()
210{
211 // KApplication::getKApplication()->invokeHTMLHelp("", "");
212}
213
214
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 @@
1/***************************************************************************
2 klines.h - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Razilov
6 email : Roman.Razilov@gmx.de
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef KLINES_H
18#define KLINES_H
19
20#include <qwidget.h>
21#include <qmenubar.h>
22#include <qlabel.h>
23#include <qpushbutton.h>
24#include <qmainwindow.h>
25#include "linesboard.h"
26#include "mwidget.h"
27#include "prompt.h"
28
29#define LSCORE 0
30#define LRECORD 1
31
32class KLines : public QMainWindow
33{
34 Q_OBJECT
35public:
36 KLines(QWidget *parent,const char* name, WFlags f);
37 ~KLines();
38
39 static QString appName() { return QString::fromLatin1("zlines"); }
40
41public slots:
42 void startGame();
43 void stopGame();
44 void makeTurn();
45 void addScore(int ballsErased);
46 void switchPrompt();
47 void help();
48 void undo();
49
50protected:
51 void resizeEvent( QResizeEvent * );
52
53private slots:
54
55// bool setSize( int w, int h );
56 void setMinSize();
57
58private:
59 QMenuBar *menu;
60 int idMenuPrompt;
61 int idMenuUndo;
62
63 QPopupMenu *game;
64 QPopupMenu *edit;
65 QToolBar *tool;
66 QStatusBar *stat;
67 LinesBoard* lsb;
68 MainWidget *mwidget;
69 LinesPrompt *lPrompt;
70
71 int score, prev_score;
72
73 int nextBalls[BALLSDROP];
74 int nextBalls_undo[BALLSDROP];
75 int nextBalls_redo[BALLSDROP];
76 bool bUndo;
77
78 void searchBallsLine();
79 void generateRandomBalls();
80 void placeBalls();
81 void updateStat();
82 void endGame();
83 void switchUndo( bool bu );
84};
85
86#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 @@
1/***************************************************************************
2 linesboard.cpp - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#include <qpainter.h>
20#include <qpixmap.h>
21#include <qcolor.h>
22#include <qkeycode.h>
23#include <stdlib.h>
24
25#include "linesboard.h"
26
27/*
28 Constructs a LinesBoard widget.
29*/
30
31LinesBoard::LinesBoard( BallPainter * abPainter, QWidget* parent, const char* name )
32 : Field( parent, name )
33{
34 anim = ANIM_NO;
35// waypos = 0;
36// waylen = 0;
37// jumpingRow = -1;
38// jumpingCol = -1;
39 painting = 0;
40 way = new Waypoints[NUMCELLSW*NUMCELLSH];
41
42 bPainter = abPainter;
43
44 setFocusPolicy( NoFocus );
45 setBackgroundColor( gray );
46
47 setMouseTracking( FALSE );
48 setFixedSize(wHint(), hHint());
49
50 timer = new QTimer(this);
51 connect( timer, SIGNAL(timeout()), SLOT(timerSlot()) );
52 timer->start( TIMERCLOCK, FALSE );
53
54}
55
56/*
57 Destructor: deallocates memory for contents
58*/
59
60LinesBoard::~LinesBoard()
61{
62 // debug("stop");
63 timer->stop();
64 delete timer;
65 delete []way;
66}
67
68
69void LinesBoard::placeBalls(int pnextBalls[BALLSDROP])
70{
71 debug("LinesBoard::placeBalls( )");
72 for(int i=0; i < BALLSDROP; i++){
73 nextBalls[i] = pnextBalls[i];
74 }
75 nextBallToPlace = 0;
76 placeBall();
77 debug("LinesBoard::placeBalls End ");
78}
79void LinesBoard::placeBall( )
80{
81 int color = nextBalls[nextBallToPlace];
82 debug("LinesBoard::placeBall( ) color=%i, nextBallToPlace = %i", color, nextBallToPlace);
83 char* xx = (char*)malloc( sizeof(char)*NUMCELLSW*NUMCELLSH );
84 char* yy = (char*)malloc( sizeof(char)*NUMCELLSW*NUMCELLSH );
85// int nb=3;
86// if( freeSpace() < 3) nb = freeSpace();
87 int empty=0;
88 for(int y=0; y<NUMCELLSH; y++)
89 for(int x=0; x<NUMCELLSW; x++)
90 if( getBall(x,y) == NOBALL )
91 {
92 xx[empty] = x;
93 yy[empty] = y;
94 empty++;
95 };
96// debug("empty = %i",empty);
97 if ( empty > 0)
98 {
99 int pos = rand()%empty;
100 putBall( xx[pos], yy[pos], color );
101 clearAnim();
102 setAnim( xx[pos], yy[pos], ANIM_BORN );
103 nextBallToPlace++;
104 AnimStart(ANIM_BORN);
105 free(xx);
106 free(yy);
107 }
108 else
109 {
110 free(xx);
111 free(yy);
112 emit endGame();
113 }
114 debug("LinesBoard::placeBall END");
115}
116
117
118/*id LinesBoard::doAfterBalls() {
119 erase5Balls();
120 repaint(FALSE);
121}
122*/
123/*
124 Sets the size of the table
125*/
126
127int LinesBoard::width() { return CELLSIZE * NUMCELLSW; }
128int LinesBoard::height() { return CELLSIZE * NUMCELLSH; }
129int LinesBoard::wHint() { return width(); }
130int LinesBoard::hHint() { return height(); }
131
132
133
134void LinesBoard::paintEvent( QPaintEvent* )
135{
136// debug("LinesBoard::paintEvent ");
137 QPixmap pixmap(width(), height());
138 QPainter paint(&pixmap, this);
139
140 for( int y=0; y < NUMCELLSH; y++ ){
141 for( int x=0; x < NUMCELLSW; x++ ){
142 if( getBall(x,y) == NOBALL )
143 {
144// debug("draw empty %i %i", x, y );
145 paint.drawPixmap(x*CELLSIZE, y*CELLSIZE, *(bPainter->GetBackgroundPix()) );
146 }
147 else
148 {
149// debug("draw empty %i %i %c", x, y, getBall(x,y) );
150 paint.drawPixmap(x*CELLSIZE, y*CELLSIZE,
151 *(bPainter->GetBall(getBall(x,y),animstep,getAnim(x,y))));
152 }
153 }
154 }
155
156 bitBlt(this, 0,0, &pixmap, 0,0, width(), height(), CopyROP);
157}
158
159/*
160 Handles mouse press events for the LinesBoard widget.
161*/
162void LinesBoard::mousePressEvent( QMouseEvent* e )
163{
164 debug("LinesBoard::mousePressEvent START");
165 int curRow = e->y() / CELLSIZE;
166 int curCol = e->x() / CELLSIZE;
167 //debug
168 debug("Mouse pressed: curRow=%i, curCol=%i", curRow, curCol);
169
170 //check range
171 if (!checkBounds( curCol, curRow ) )
172 return;
173// if( running || anim != ANIM_NO ) return;
174 if(anim != ANIM_JUMP && anim != ANIM_NO) return;
175 if ( anim == ANIM_JUMP )
176 {
177 if ( getBall(curCol,curRow) == NOBALL )
178 {
179 if(existPath(jumpingCol, jumpingRow, curCol, curRow))
180 {
181 saveUndo();
182 AnimStart(ANIM_RUN);
183 }
184 }
185 else
186 AnimJump(curCol,curRow);
187 }
188 else
189 AnimJump(curCol,curRow);
190 debug("LinesBoard::mousePressEvent END");
191}
192void LinesBoard::AnimJump(int x, int y ) {
193 debug("LinesBoard::AnimJump( %i,%i)", x,y );
194 if ( getBall(x,y) != NOBALL )
195 if (!( anim == ANIM_JUMP && jumpingCol == x && jumpingRow == y ))
196 if ( AnimEnd() )
197 {
198 clearAnim();
199 setAnim(x,y,ANIM_JUMP);
200 jumpingCol = x;
201 jumpingRow = y;
202 AnimStart(ANIM_JUMP);
203 }
204 debug("LinesBoard::AnimJump END");
205}
206void LinesBoard::AnimStart(int panim) {
207 debug("LinesBoard::AnimStart( %i )", panim);
208 if (anim != ANIM_NO)
209 AnimEnd();
210 animstep = 0;
211 animdelaystart = 1;
212 switch(panim) {
213 case ANIM_NO:
214 break;
215 case ANIM_BORN:
216 debug("LinesBoard::AnimStart( ANIM_BORN )");
217 animdelaystart=1;
218 animmax = BOOMBALLS;
219 break;
220 case ANIM_JUMP:
221 direction = -1;
222 animstep = 4;
223 animmax = PIXTIME -1;
224 break;
225 case ANIM_RUN:
226 animdelaystart=3;
227 // do first step on next timer;
228 animdelaycount = 0;
229 // animmax already set
230 break;
231 case ANIM_BURN:
232 animdelaystart=1;
233 animmax = FIREBALLS + FIREPIX - 1;
234 break;
235 default:
236 ;
237 }
238 anim = panim;
239 animdelaycount = animdelaystart;
240 debug("LinesBoard::AnimStart END");
241}
242int LinesBoard::AnimEnd( )
243{
244 debug("LinesBoard::AnimEnd( %i )",anim );
245 if (anim == ANIM_NO ) return true;
246 int oldanim = anim;
247 anim = ANIM_NO;
248 if (oldanim == ANIM_RUN) {
249 if (animstep != animmax) {
250 moveBall(way[animstep].x,way[animstep].y,way[animmax].x,way[animmax].y);
251 }
252 if ( erase5Balls() == 0 ) {
253 // debug("end turn");
254 emit endTurn();
255 debug("LinesBoard::AnimEnd END true 1");
256 return true;
257 }
258 else
259 debug("LinesBoard::AnimEnd END false 2");
260 return false;
261 } else if ( oldanim == ANIM_BURN )
262 {
263 emit eraseLine( deleteAnimatedBalls() );
264 repaint(FALSE);
265 if ( nextBallToPlace < BALLSDROP )
266 {
267 placeBall();
268 // continue with born
269 debug("LinesBoard::AnimEnd END false 3");
270 return false;
271 }
272 else
273 {
274 // emit endTurn();
275 debug("LinesBoard::AnimEnd END true 4");
276 return true;
277 }
278 } else if ( oldanim == ANIM_BORN )
279 {
280 if ( erase5Balls() == 0 )
281 {
282 if ( freeSpace() > 0)
283 {
284 if ( nextBallToPlace < BALLSDROP )
285 {
286 placeBall();
287 debug("LinesBoard::AnimEnd END false 5");
288 return false;
289 }
290 else
291 {
292 debug("LinesBoard::AnimEnd END true 6");
293 return true;
294 }
295 }
296 else
297 {
298 debug("emit endGame");
299 emit endGame();
300 debug("LinesBoard::AnimEnd END false 7");
301 return false;
302 }
303 }
304 else
305 {
306 // wait for user input
307 debug("LinesBoard::AnimEnd END true 8");
308 return true;
309 }
310 }
311 else
312 {
313 debug("LinesBoard::AnimEnd END true");
314 return true;
315 }
316 return true;
317}
318void LinesBoard::AnimNext() {
319 if ( anim != ANIM_NO )
320 {
321 debug("LinesBoard::AnimNext( ) anim %i animstep %i",anim,animstep);
322 if ( anim == ANIM_JUMP ) {
323 if ( (direction > 0 && animstep == animmax) || ( direction < 0 && animstep == 0))
324 direction = -direction;
325 animstep += direction;
326 repaint(FALSE);
327 } else {
328 if ( animstep >= animmax )
329 AnimEnd();
330 else {
331 animdelaycount--;
332 if (animdelaycount <= 0) {
333 debug("LinesBoard::AnimNext step %i", animstep);
334 if ( anim == ANIM_RUN )
335 moveBall(way[animstep].x,way[animstep].y,way[animstep+1].x,way[animstep+1].y);
336 animstep++;
337 animdelaycount = animdelaystart;
338 repaint( FALSE );
339 }
340 }
341 }
342 debug("LinesBoard::AnimNext END");
343 }
344}
345int LinesBoard::getAnim( int x, int y )
346{
347// debug("LinesBoard::getAnim( %i,%i )",x,y);
348 return (( Field::getAnim(x,y) != ANIM_NO )? anim : ANIM_NO);
349}
350
351void LinesBoard::timerSlot()
352{
353// debug("LinesBoard::Timer() anim = %i",anim );
354 AnimNext();
355}
356
357int LinesBoard::erase5Balls()
358{
359 //debug
360 debug("LinesBoard::erase5Balls()");
361
362 int nb=5; // minimum balls for erasure
363
364 bool bit_erase[NUMCELLSH][NUMCELLSW]; //bool array for balls, that must be erased
365 for(int y=0; y<NUMCELLSH; y++)
366 for(int x=0; x<NUMCELLSW; x++)
367 bit_erase[y][x] = false;
368
369 int color,newcolor;
370 int count;
371 //for horisontal
372 //debug("entering to horiz");
373
374 for(int y=0; y<NUMCELLSH; y++) {
375 count = 1;
376 color = NOBALL;
377 for(int x=0; x<NUMCELLSW; x++){
378 if ( (newcolor = getBall(x,y)) == color) {
379 if ( color != NOBALL) {
380 count++;
381 if ( count >= nb )
382 if ( count == nb )
383 for (int i = 0; i < nb; i++)
384 bit_erase[y][x-i] = true;
385 else bit_erase[y][x] = true;
386 }
387 } else {
388 color = newcolor;
389 count = 1;
390 }
391 }
392 }
393
394 //for vertical
395 //debug("entering to vert");
396 for(int x=0; x<NUMCELLSW; x++) {
397 count = 0;
398 color = NOBALL;
399 for(int y=0; y<NUMCELLSH; y++){
400 if ( (newcolor = getBall(x,y)) == color) {
401 if ( color != NOBALL) {
402 count++;
403 if ( count >= nb )
404 if ( count == nb )
405 for (int i = 0; i < nb; i++)
406 bit_erase[y-i][x] = true;
407 else bit_erase[y][x] = true;
408 }
409 } else {
410 color = newcolor;
411 count = 1;
412 }
413 }
414 }
415
416
417 // debug("entering to diag1");
418 //for left-down to rigth-up diagonal
419 for ( int xs = NUMCELLSW-1,ys = NUMCELLSH-nb; xs >= nb-1; ) {
420 count = 0;
421 color = NOBALL;
422 for ( int x = xs, y = ys; x >= 0 && y < NUMCELLSH; x--, y++ ) {
423 if ( (newcolor = getBall(x,y)) == color) {
424 if ( color != NOBALL) {
425 count++;
426 if ( count >= nb )
427 if ( count == nb )
428 for (int i = 0; i < nb; i++)
429 bit_erase[y-i][x+i] = true;
430 else bit_erase[y][x] = true;
431 }
432 } else {
433 color = newcolor;
434 count = 1;
435 }
436 }
437 if ( ys > 0 ) ys--; else xs--;
438 }
439
440 //debug("entering to diag2");
441
442 //for left-up to rigth-down diagonal
443 for ( int xs = 0,ys = NUMCELLSH-nb; xs <= NUMCELLSW-nb; )
444 {
445 count = 0;
446 color = NOBALL;
447 for ( int x = xs, y = ys; x < NUMCELLSW && y < NUMCELLSH; x++, y++ )
448 {
449 if ( (newcolor = getBall(x,y)) == color)
450 {
451 if ( color != NOBALL)
452 {
453 count++;
454 if ( count >= nb )
455 if ( count == nb )
456 for (int i = 0; i < nb; i++)
457 bit_erase[y-i][x-i] = true;
458 else
459 bit_erase[y][x] = true;
460 }
461 }
462 else
463 {
464 color = newcolor;
465 count = 1;
466 }
467 }
468 if ( ys > 0 ) ys--; else xs++;
469 }
470
471 //remove all lines balls, that more than nb
472 int cb=0;
473 for(int y=0; y < NUMCELLSH; y++)
474 for(int x=0; x < NUMCELLSW; x++)
475 {
476 if (bit_erase[y][x])
477 {
478 setAnim(x,y,ANIM_YES);
479 cb++;
480 }
481 else
482 {
483 setAnim(x,y,ANIM_NO);
484 }
485 }
486 //debug
487 debug("LinesBoard::erase5Balls marked %i balls", cb);
488 if ( cb > 0 )
489 {
490 AnimStart(ANIM_BURN);
491 //emit eraseLine(cb);
492 }
493
494 //debug
495 debug("LinesBoard::erase5Balls END");
496 return cb;
497}
498
499
500#define GO_EMPTY 4
501#define GO_A 5
502#define GO_B 6
503#define GO_BALL 7
504
505bool LinesBoard::existPath(int bx, int by, int ax, int ay)
506{
507 debug("LinesBoard::existPath( %i, %i, %i, %i )", bx, by, ax, ay);
508 int dx[4]={1,-1, 0, 0};
509 int dy[4]={0, 0, 1,-1};
510
511 // debug("path %i %i %i %i",bx,by,ax,ay);
512 if (getBall(ax,ay) != NOBALL)
513 return false;
514
515 char pf[NUMCELLSH][NUMCELLSW];
516 for(int y=0; y<NUMCELLSH; y++)
517 for(int x=0; x<NUMCELLSW; x++)
518 pf[y][x] = (getBall(x,y) == NOBALL) ? GO_EMPTY:GO_BALL;
519
520 Waypoints lastchanged[2][NUMCELLSH*NUMCELLSW];
521
522 int lastChangedCount[2];
523 int currentchanged = 0;
524 int nextchanged = 1;
525 lastchanged[currentchanged][0].x = ax;
526 lastchanged[currentchanged][0].y = ay;
527 lastChangedCount[currentchanged] = 1;
528 pf[ay][ax]=GO_A;
529 pf[by][bx]=GO_B;
530
531 // int expanded;
532 bool B_reached = false;
533
534 do
535 {
536 lastChangedCount[nextchanged] = 0;
537 for(int dir=0; dir<4; dir++)
538 {
539 for ( int i = 0 ; i < lastChangedCount[currentchanged]; i++ )
540 {
541 int nx = lastchanged[currentchanged][i].x + dx[dir];
542 int ny = lastchanged[currentchanged][i].y + dy[dir];
543 if( (nx>=0) && (nx<NUMCELLSW) && (ny>=0) && (ny<NUMCELLSH) )
544 {
545 if( pf[ny][nx]==GO_EMPTY ||( nx==bx && ny==by ))
546 {
547 pf[ny][nx] = dir;
548 lastchanged[nextchanged][lastChangedCount[nextchanged]].x = nx;
549 lastchanged[nextchanged][lastChangedCount[nextchanged]].y = ny;
550 lastChangedCount[nextchanged]++;
551 };
552 if( (nx==bx) && (ny==by) )
553 {
554 B_reached = true;
555 break;
556 }
557 }
558 }
559 }
560 nextchanged = nextchanged ^ 1;
561 currentchanged = nextchanged ^ 1;
562 // debug("currentchanged %i lastChangedCount[currentchanged] %i",
563 // currentchanged,lastChangedCount[currentchanged]);
564 } while(!B_reached && lastChangedCount[currentchanged] != 0);
565 //debug("B_reached %i ", B_reached );
566
567 if (B_reached) {
568 AnimStart( ANIM_BLOCK);
569 animmax = 0;
570// waypos = 0;
571 int x, y,dir;
572 for( x = bx, y = by,dir; (dir = pf[y][x]) != GO_A;x -=dx[dir],y -= dy[dir]) {
573 way[animmax].x = x;
574 way[animmax].y = y;
575 //debug("%i %i %i %i",dir,waylen,x,y);
576 animmax++;
577 }
578 way[animmax].x = x;
579 way[animmax].y = y;
580 }
581 debug("LinesBoard::existPath END %s", B_reached?"true":"false" );
582 return B_reached;
583}
584
585void LinesBoard::undo()
586{
587 AnimEnd();
588 restoreUndo();
589 repaint( FALSE );
590}
591
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 @@
1/***************************************************************************
2 linesboard.h - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#ifndef __linesboard_h
20#define __linesboard_h
21
22#include <qwidget.h>
23#include <qpixmap.h>
24#include <qtimer.h>
25
26#include "field.h"
27//#include "shotcounter.h"
28#include "ballpainter.h"
29
30#ifdef Q_WS_QWS
31 #define debug (void)
32#else
33 #define debug qDebug
34#endif
35#define fatal qFatal
36#define warning qWarning
37
38class LinesBoard : public Field
39{
40 Q_OBJECT
41public:
42 LinesBoard( BallPainter * abPainter, QWidget* parent=0, const char* name=0 );
43 ~LinesBoard();
44
45 int width();
46 int height();
47 int wHint();
48 int hHint();
49// void doAfterBalls();
50 void placeBalls(int nextBalls[BALLSDROP]);
51 void undo();
52
53signals:
54 void endTurn();
55 void endGame();
56 void eraseLine(int nb);
57
58private:
59 int anim;
60
61 struct Waypoints {
62 int x,y;
63 } *way;
64 int nextBalls[BALLSDROP];
65
66 int animmax;
67
68 //used for running and animation phase
69 int painting;
70 int animstep;
71 int animdelaycount;
72 int animdelaystart;
73 int direction;
74
75
76 int nextBallToPlace;
77 int jumpingCol;
78 int jumpingRow;
79
80
81 QTimer* timer;
82// ShotCounter* shCounter;
83 BallPainter* bPainter;
84
85 void paintEvent( QPaintEvent* );
86 void mousePressEvent( QMouseEvent* );
87
88 void AnimStart(int panim);
89 void AnimNext();
90 int AnimEnd();
91 int getAnim(int x, int y ); // returns if the specifyed cell is animated..
92 void AnimJump( int col, int row );
93
94 int erase5Balls();
95 bool existPath(int ax, int ay, int bx, int by);
96 void placeBall();
97
98protected slots:
99 void timerSlot();
100
101};
102
103#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 @@
1/***************************************************************************
2 main.cpp - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19 /*
20 * Roman Razilov 2000-05-19 debug dummmy
21 * Roman Razilov 2000-05-21 qimgio
22*/
23
24#include <qglobal.h>
25
26
27#include <opie/oapplicationfactory.h>
28#include "klines.h"
29
30OPIE_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 @@
1/***************************************************************************
2 mwidget.cpp - description
3 -------------------
4begin : Fri May 19 2000
5copyright : (C) 2000 by Roman Merzlyakov
6email : roman@sbrf.barrt.ru
7copyright : (C) 2000 by Roman Razilov
8email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#include "mwidget.h"
20#include <qlayout.h>
21#include "ballpainter.h"
22#include <qhbox.h>
23#include <qlabel.h>
24
25MainWidget::MainWidget( QWidget* parent, const char* name )
26 : QFrame( parent, name )
27{
28 BallPainter *bPainter = new BallPainter();
29
30 QGridLayout *Form1Layout = new QGridLayout( this );
31 Form1Layout->setSpacing( 4 );
32 Form1Layout->setMargin( 4 );
33 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
34 Form1Layout->addItem( spacer, 0, 0 );
35
36 lsb = new LinesBoard(bPainter, this);
37
38 Form1Layout->addWidget( lsb, 0, 1 );
39 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
40 Form1Layout->addItem( spacer_2, 0, 2 );
41
42 QHBox *bottom=new QHBox(this);
43
44 mPoints=new QLabel(bottom);
45 bottom->setStretchFactor(mPoints, 2);
46
47 lPrompt = new LinesPrompt(bPainter, bottom);
48
49 Form1Layout->addWidget( bottom, 1, 1 );
50 QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
51 Form1Layout->addItem( spacer_3, 2, 1 );
52
53
54 connect(lsb, SIGNAL(endTurn()), parent, SLOT(makeTurn()));
55 connect(lsb, SIGNAL(eraseLine(int)), parent, SLOT(addScore(int)));
56 connect(lsb, SIGNAL(endGame()), parent, SLOT(stopGame()));
57
58 connect(lPrompt, SIGNAL(PromptPressed()), parent, SLOT(switchPrompt()));
59
60}
61
62void MainWidget::setMessage(const QString &message)
63{
64 mPoints->setText(message);
65}
66
67
68/*
69Destructor: deallocates memory for contents
70 */
71
72MainWidget::~MainWidget()
73{
74}
75
76LinesBoard * MainWidget::GetLsb()
77{
78 return lsb;
79}
80
81LinesPrompt * MainWidget::GetPrompt()
82{
83 return lPrompt;
84}
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 @@
1/***************************************************************************
2 mwidget.h - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20#ifndef MWIDGET_H
21#define MWIDGET_H
22
23#include <qwidget.h>
24#include <qpixmap.h>
25#include <qtimer.h>
26#include <qframe.h>
27#include "linesboard.h"
28#include "prompt.h"
29
30class QLabel;
31
32class MainWidget : public QFrame
33{
34Q_OBJECT
35 LinesBoard * lsb;
36 LinesPrompt * lPrompt;
37 QLabel *mPoints;
38
39public:
40 MainWidget( QWidget* parent=0, const char* name=0 );
41 ~MainWidget();
42 LinesBoard * GetLsb();
43 LinesPrompt * GetPrompt();
44
45public slots:
46 void setMessage(const QString &message);
47};
48
49#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 @@
1/***************************************************************************
2 prompt.cpp - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#include <qpainter.h>
20#include "prompt.h"
21
22LinesPrompt::LinesPrompt( BallPainter * abPainter, QWidget* parent, const char* name )
23 : QWidget( parent, name )
24{
25
26 bPainter = abPainter;
27
28 setFocusPolicy( NoFocus );
29 setBackgroundColor( gray );
30
31 setMouseTracking( FALSE );
32 setFixedSize(wPrompt(), hPrompt());
33
34 PromptEnabled = true;
35 cb[0]=NOBALL;
36 cb[1]=NOBALL;
37 cb[2]=NOBALL;
38}
39
40LinesPrompt::~LinesPrompt()
41{
42}
43
44int LinesPrompt::width() { return CELLSIZE * 3 ; }
45int LinesPrompt::height() { return CELLSIZE ; }
46
47int LinesPrompt::wPrompt() { return CELLSIZE * 3 ; }
48int LinesPrompt::hPrompt() { return CELLSIZE ; }
49
50void LinesPrompt::paintEvent( QPaintEvent* )
51{
52 QPainter paint( this );
53 if(PromptEnabled){
54 paint.drawPixmap(0, 0, *(bPainter->GetNormalBall(cb[0])) );
55 paint.drawPixmap(CELLSIZE, 0, *(bPainter->GetNormalBall(cb[1])) );
56 paint.drawPixmap(2*CELLSIZE, 0, *(bPainter->GetNormalBall(cb[2])) );
57 }
58 else{
59 paint.drawPixmap(0, 0, *(bPainter->GetBackgroundPix()) );
60 paint.drawPixmap(CELLSIZE, 0, *(bPainter->GetBackgroundPix()) );
61 paint.drawPixmap(2*CELLSIZE, 0, *(bPainter->GetBackgroundPix()) );
62 }
63}
64
65/*
66 Handles mouse press events for the LinesPrompt widget.
67*/
68void LinesPrompt::mousePressEvent( QMouseEvent* e )
69{
70 emit PromptPressed();
71}
72
73void LinesPrompt::SetBalls( int *pcb )
74{
75 for (int i = 0; i<BALLSDROP; i++)
76 cb[i] = pcb[i];
77
78 update();
79}
80
81bool LinesPrompt::getState()
82{
83 return PromptEnabled;
84}
85void LinesPrompt::setPrompt(bool enabled)
86{
87 PromptEnabled = enabled;
88 update();
89}
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 @@
1/***************************************************************************
2 prompt.h - description
3 -------------------
4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#ifndef PROMPT_H
20#define PROMPT_H
21
22#include <qwidget.h>
23#include "ballpainter.h"
24
25class LinesPrompt : public QWidget
26{
27 Q_OBJECT
28
29 BallPainter* bPainter;
30 bool PromptEnabled;
31 int cb[BALLSDROP];
32
33 void paintEvent( QPaintEvent* );
34 void mousePressEvent( QMouseEvent* );
35
36public:
37 LinesPrompt( BallPainter * abPainter, QWidget * parent=0, const char * name=0 );
38 ~LinesPrompt();
39
40 void setPrompt(bool enabled);
41 bool getState(); // enabled = true
42 void SetBalls( int *pcb );
43
44 int width();
45 int height();
46 int wPrompt();
47 int hPrompt();
48
49signals:
50 void PromptPressed();
51
52};
53
54#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 @@
1 CONFIG = qt quick-app
2 HEADERS = ballpainter.h cfg.h linesboard.h prompt.h cell.h field.h klines.h mwidget.h
3 SOURCES = ballpainter.cpp field.cpp klines.cpp main.cpp prompt.cpp cell.cpp linesboard.cpp mwidget.cpp
4 TARGET = zlines
5 LIBS += -lqpe
6 INCLUDEPATH+= $(OPIEDIR)/include/
7 DEPENDPATH+= $(OPIEDIR)/include/
8
9
10include ($(OPIEDIR)/include.pro)
diff --git a/packages b/packages
index 40bcdc7..0f39681 100644
--- a/packages
+++ b/packages
@@ -199,3 +199,4 @@ CONFIG_EXAMPLE_MENU examples/menuapplet menuapplet.pro
199 CONFIG_EXAMPLE_BOARD examples/inputmethodexample.pro 199 CONFIG_EXAMPLE_BOARD examples/inputmethodexample.pro
200 CONFIG_EXAMPLE_VPN examples/networksettingsexample.pro 200 CONFIG_EXAMPLE_VPN examples/networksettingsexample.pro
201 CONFIG_ZSAME noncore/games/zsame zsame.pro 201 CONFIG_ZSAME noncore/games/zsame zsame.pro
202 CONFIG_ZLINES noncore/games/zlines zlines.pro
diff --git a/pics/zlines/balls.png b/pics/zlines/balls.png
new file mode 100644
index 0000000..846de25
--- a/dev/null
+++ b/pics/zlines/balls.png
Binary files differ
diff --git a/pics/zlines/field.png b/pics/zlines/field.png
new file mode 100644
index 0000000..ddab110
--- a/dev/null
+++ b/pics/zlines/field.png
Binary files differ
diff --git a/pics/zlines/fire.png b/pics/zlines/fire.png
new file mode 100644
index 0000000..9c9698d
--- a/dev/null
+++ b/pics/zlines/fire.png
Binary files differ