summaryrefslogtreecommitdiff
path: root/noncore/games/zlines/klines.cpp
Unidiff
Diffstat (limited to 'noncore/games/zlines/klines.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/zlines/klines.cpp214
1 files changed, 214 insertions, 0 deletions
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