summaryrefslogtreecommitdiff
authorzecke <zecke>2004-10-15 01:48:45 (UTC)
committer zecke <zecke>2004-10-15 01:48:45 (UTC)
commitfefeafe35f8dac30f4baab9e3bff8e2ffbd1afd0 (patch) (unidiff)
treea59a3bd9b5434657ee014dd6bbf7fbb50f5994d0
parent85ab1a8cc3935538cc1f33fef7c94ba31accb53e (diff)
downloadopie-fefeafe35f8dac30f4baab9e3bff8e2ffbd1afd0.zip
opie-fefeafe35f8dac30f4baab9e3bff8e2ffbd1afd0.tar.gz
opie-fefeafe35f8dac30f4baab9e3bff8e2ffbd1afd0.tar.bz2
Fix #1450 to clear the 'bonus' for removing every stone in the game
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/zsame/StoneField.cpp4
-rw-r--r--noncore/games/zsame/StoneField.h3
-rw-r--r--noncore/games/zsame/StoneWidget.cpp4
-rw-r--r--noncore/games/zsame/StoneWidget.h1
-rw-r--r--noncore/games/zsame/ZSameWidget.cpp1
5 files changed, 12 insertions, 1 deletions
diff --git a/noncore/games/zsame/StoneField.cpp b/noncore/games/zsame/StoneField.cpp
index 49d8eca..56e9dc5 100644
--- a/noncore/games/zsame/StoneField.cpp
+++ b/noncore/games/zsame/StoneField.cpp
@@ -1,390 +1,394 @@
1/* 1/*
2 * ksame 0.4 - simple Game 2 * ksame 0.4 - simple Game
3 * Copyright (C) 1997,1998 Marcus Kreutzberger 3 * Copyright (C) 1997,1998 Marcus Kreutzberger
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or 7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * 18 *
19 */ 19 */
20 20
21#include "StoneField.h" 21#include "StoneField.h"
22#include <assert.h> 22#include <assert.h>
23 23
24StoneFieldState::StoneFieldState(const StoneField &stonefield) 24StoneFieldState::StoneFieldState(const StoneField &stonefield)
25{ 25{
26 field=new unsigned char[stonefield.maxstone]; 26 field=new unsigned char[stonefield.maxstone];
27 for (int i=0;i<stonefield.maxstone;i++) 27 for (int i=0;i<stonefield.maxstone;i++)
28 field[i]=stonefield.field[i].color; 28 field[i]=stonefield.field[i].color;
29 29
30 colors=stonefield.colors; 30 colors=stonefield.colors;
31 board=stonefield.board; 31 board=stonefield.board;
32 score=stonefield.score; 32 score=stonefield.score;
33 gameover=stonefield.gameover; 33 gameover=stonefield.gameover;
34} 34}
35 35
36StoneFieldState::~StoneFieldState() { 36StoneFieldState::~StoneFieldState() {
37 delete[] field; 37 delete[] field;
38} 38}
39 39
40void 40void
41StoneFieldState::restore(StoneField &stonefield) const { 41StoneFieldState::restore(StoneField &stonefield) const {
42 for (int i=0;i<stonefield.maxstone;i++) { 42 for (int i=0;i<stonefield.maxstone;i++) {
43 stonefield.field[i].color=field[i]; 43 stonefield.field[i].color=field[i];
44 stonefield.field[i].changed=true; 44 stonefield.field[i].changed=true;
45 stonefield.field[i].marked=false; 45 stonefield.field[i].marked=false;
46 } 46 }
47 47
48 stonefield.colors=colors; 48 stonefield.colors=colors;
49 stonefield.board=board; 49 stonefield.board=board;
50 stonefield.score=score; 50 stonefield.score=score;
51 stonefield.marked=0; 51 stonefield.marked=0;
52 stonefield.gameover=gameover; 52 stonefield.gameover=gameover;
53} 53}
54 54
55StoneField::StoneField(int width, int height, 55StoneField::StoneField(int width, int height,
56 int colors, unsigned int board, 56 int colors, unsigned int board,
57 bool undoenabled) 57 bool undoenabled)
58{ 58{
59// Q_ASSERT(width>0); 59// Q_ASSERT(width>0);
60// Q_ASSERT(height>0); 60// Q_ASSERT(height>0);
61 61
62 if (undoenabled) undolist=new QList<StoneFieldState>; 62 if (undoenabled) undolist=new QList<StoneFieldState>;
63 else undolist=0; 63 else undolist=0;
64 64
65 sizex=width; 65 sizex=width;
66 sizey=height; 66 sizey=height;
67 maxstone=sizex*sizey; 67 maxstone=sizex*sizey;
68 field=new Stone[maxstone]; 68 field=new Stone[maxstone];
69 newGame(board,colors); 69 newGame(board,colors);
70 m_gotBonus= false; 70 m_gotBonus= false;
71} 71}
72 72
73StoneField::~StoneField() { 73StoneField::~StoneField() {
74 delete[] field; 74 delete[] field;
75 delete undolist; 75 delete undolist;
76// kdDebug() << "~StoneField\n" << endl; 76// kdDebug() << "~StoneField\n" << endl;
77} 77}
78 78
79int 79int
80StoneField::width() const { 80StoneField::width() const {
81 return sizex; 81 return sizex;
82} 82}
83 83
84int 84int
85StoneField::height() const { 85StoneField::height() const {
86 return sizey; 86 return sizey;
87} 87}
88 88
89void 89void
90StoneField::newGame(unsigned int board,int colors) { 90StoneField::newGame(unsigned int board,int colors) {
91// kdDebug() << "StoneField::newgame board " 91// kdDebug() << "StoneField::newgame board "
92// << board << " colors " << colors << endl; 92// << board << " colors " << colors << endl;
93 if (colors<1) colors=3; 93 if (colors<1) colors=3;
94 if (colors>7) colors=7; 94 if (colors>7) colors=7;
95 this->colors=colors; 95 this->colors=colors;
96 this->board=board; 96 this->board=board;
97 reset(); 97 reset();
98} 98}
99 99
100void 100void
101StoneField::reset() { 101StoneField::reset() {
102 random.setSeed(board); 102 random.setSeed(board);
103 103
104 Stone *stone=field; 104 Stone *stone=field;
105 for (int i=0;i<maxstone;i++,stone++) { 105 for (int i=0;i<maxstone;i++,stone++) {
106 stone->color=1+random.getLong(colors); 106 stone->color=1+random.getLong(colors);
107 stone->marked=false; 107 stone->marked=false;
108 stone->changed=true; 108 stone->changed=true;
109 } 109 }
110 110
111 gameover=-1; 111 gameover=-1;
112 score=0; 112 score=0;
113 marked=0; 113 marked=0;
114 114
115 if (undolist) { 115 if (undolist) {
116 undolist->setAutoDelete(true); 116 undolist->setAutoDelete(true);
117 undolist->clear(); 117 undolist->clear();
118 } 118 }
119 119
120 120
121 int c[7]; 121 int c[7];
122 int j; 122 int j;
123 for (j=0;j<7;j++) c[j]=0; 123 for (j=0;j<7;j++) c[j]=0;
124 124
125 for (j=0,stone=field;j<maxstone;j++,stone++) { 125 for (j=0,stone=field;j<maxstone;j++,stone++) {
126 c[stone->color]++; 126 c[stone->color]++;
127 } 127 }
128// kdDebug() << "red " << c[1] << endl; 128// kdDebug() << "red " << c[1] << endl;
129// kdDebug() << "blue " << c[2] << endl; 129// kdDebug() << "blue " << c[2] << endl;
130// kdDebug() << "yellow " << c[3] << endl; 130// kdDebug() << "yellow " << c[3] << endl;
131// kdDebug() << "green " << c[4] << endl; 131// kdDebug() << "green " << c[4] << endl;
132 132
133} 133}
134 134
135int 135int
136StoneField::map(int x,int y) { 136StoneField::map(int x,int y) {
137 assert (!(x<0||y<0||x>=sizex||y>=sizey)); 137 assert (!(x<0||y<0||x>=sizex||y>=sizey));
138 return x+y*sizex; 138 return x+y*sizex;
139} 139}
140 140
141int 141int
142StoneField::mark(int x,int y,bool force) { 142StoneField::mark(int x,int y,bool force) {
143 int index=map(x,y); 143 int index=map(x,y);
144 144
145 if (index<0) { 145 if (index<0) {
146 unmark(); 146 unmark();
147 return 0; 147 return 0;
148 } 148 }
149 149
150 if (field[index].marked) return -1; 150 if (field[index].marked) return -1;
151 unmark(); 151 unmark();
152 152
153 mark(index,field[index].color); 153 mark(index,field[index].color);
154 154
155 if (marked==1&&!force) { 155 if (marked==1&&!force) {
156 field[index].marked=false; 156 field[index].marked=false;
157 marked=0; 157 marked=0;
158 } 158 }
159 return marked; 159 return marked;
160} 160}
161 161
162void 162void
163StoneField::mark(int index,unsigned char color) { 163StoneField::mark(int index,unsigned char color) {
164 if ( index<0 || index>=maxstone ) return; 164 if ( index<0 || index>=maxstone ) return;
165 165
166 Stone &stone=field[index]; 166 Stone &stone=field[index];
167 167
168 if (stone.marked) return; 168 if (stone.marked) return;
169 169
170 if (!stone.color || stone.color!=color) return; 170 if (!stone.color || stone.color!=color) return;
171 171
172 stone.changed=true; 172 stone.changed=true;
173 stone.marked=true; 173 stone.marked=true;
174 marked++; 174 marked++;
175 175
176 // mark left 176 // mark left
177 if ((index%sizex)!=0) mark(index-1,color); 177 if ((index%sizex)!=0) mark(index-1,color);
178 // mark right 178 // mark right
179 if (((index+1)%sizex)!=0) mark(index+1,color); 179 if (((index+1)%sizex)!=0) mark(index+1,color);
180 // mark upward 180 // mark upward
181 if (index>=sizex) mark(index-sizex,color); 181 if (index>=sizex) mark(index-sizex,color);
182 // mark downward 182 // mark downward
183 if (index<(sizex-1)*sizey) mark(index+sizex,color); 183 if (index<(sizex-1)*sizey) mark(index+sizex,color);
184} 184}
185 185
186void 186void
187StoneField::unmark() { 187StoneField::unmark() {
188 if (!marked) return; 188 if (!marked) return;
189 189
190 Stone *stone=field; 190 Stone *stone=field;
191 for (int i=0;i<maxstone;i++,stone++) { 191 for (int i=0;i<maxstone;i++,stone++) {
192 stone->marked=false; 192 stone->marked=false;
193 stone->changed=true; 193 stone->changed=true;
194 } 194 }
195 marked=0; 195 marked=0;
196} 196}
197 197
198int 198int
199StoneField::remove(int x,int y,bool force) { 199StoneField::remove(int x,int y,bool force) {
200 int index=map(x,y); 200 int index=map(x,y);
201 201
202 if (index<0) return 0; 202 if (index<0) return 0;
203 203
204 if (!field[index].marked) { 204 if (!field[index].marked) {
205 mark(x,y,force); 205 mark(x,y,force);
206 } 206 }
207 207
208 if (!marked) return 0; 208 if (!marked) return 0;
209 209
210 // remove a single stone?? 210 // remove a single stone??
211 if (marked==1&&!force) return 0; 211 if (marked==1&&!force) return 0;
212 212
213 // add current field to undolist 213 // add current field to undolist
214 if (undolist) 214 if (undolist)
215 undolist->append(new StoneFieldState(*this)); 215 undolist->append(new StoneFieldState(*this));
216 216
217 // increase score 217 // increase score
218 if (marked>2) 218 if (marked>2)
219 score+=(marked-2)*(marked-2); 219 score+=(marked-2)*(marked-2);
220 220
221 // remove marked stones 221 // remove marked stones
222 Stone *stone=field; 222 Stone *stone=field;
223 for (int i=0;i<maxstone;i++,stone++) { 223 for (int i=0;i<maxstone;i++,stone++) {
224 if (stone->marked) { 224 if (stone->marked) {
225 stone->color=0; 225 stone->color=0;
226 stone->changed=true; 226 stone->changed=true;
227 stone->marked=false; 227 stone->marked=false;
228 } 228 }
229 } 229 }
230 int removed=marked; 230 int removed=marked;
231 marked=0; 231 marked=0;
232 232
233 for (int col=0;col<sizex;col++) { 233 for (int col=0;col<sizex;col++) {
234 int i1=col+maxstone-sizex; 234 int i1=col+maxstone-sizex;
235 while ( i1>=0 && field[i1].color ) i1-=sizex; 235 while ( i1>=0 && field[i1].color ) i1-=sizex;
236 int i2=i1; 236 int i2=i1;
237 while (i2>=0) { 237 while (i2>=0) {
238 while ( i2>=0 && !field[i2].color ) i2-=sizex; 238 while ( i2>=0 && !field[i2].color ) i2-=sizex;
239 while ( i2>=0 && field[i2].color ) { 239 while ( i2>=0 && field[i2].color ) {
240 field[i1].color=field[i2].color; 240 field[i1].color=field[i2].color;
241 field[i1].changed=true; 241 field[i1].changed=true;
242 field[i2].color=0; 242 field[i2].color=0;
243 field[i2].changed=true; 243 field[i2].changed=true;
244 i1-=sizex; 244 i1-=sizex;
245 i2-=sizex; 245 i2-=sizex;
246 } 246 }
247 } 247 }
248 } 248 }
249 249
250 // find the last column that has something 250 // find the last column that has something
251 int lastcol = sizex; 251 int lastcol = sizex;
252 while (lastcol > 0 && !field[map(lastcol-1, sizey-1)].color) { 252 while (lastcol > 0 && !field[map(lastcol-1, sizey-1)].color) {
253 lastcol--; 253 lastcol--;
254 } 254 }
255 255
256 for (int col=0;col<lastcol-1;) { 256 for (int col=0;col<lastcol-1;) {
257 bool empty = true; 257 bool empty = true;
258 for (int row = 0; row < sizey; row++) 258 for (int row = 0; row < sizey; row++)
259 if (field[map(col, row)].color) { 259 if (field[map(col, row)].color) {
260 empty = false; 260 empty = false;
261 break; 261 break;
262 } 262 }
263 if (!empty) { 263 if (!empty) {
264 col++; 264 col++;
265 continue; 265 continue;
266 } 266 }
267 int nextfullcol = col + 1; 267 int nextfullcol = col + 1;
268 while (nextfullcol < sizex && 268 while (nextfullcol < sizex &&
269 !field[map(nextfullcol, sizey - 1)].color) 269 !field[map(nextfullcol, sizey - 1)].color)
270 nextfullcol++; 270 nextfullcol++;
271 271
272 if (nextfullcol > sizex - 1) 272 if (nextfullcol > sizex - 1)
273 break; // we're ready 273 break; // we're ready
274 274
275 for (int row=0; row < sizey; row++) { 275 for (int row=0; row < sizey; row++) {
276 int source = map(nextfullcol, row); 276 int source = map(nextfullcol, row);
277 int dest = map(col, row); 277 int dest = map(col, row);
278 field[dest].color=field[source].color; 278 field[dest].color=field[source].color;
279 field[dest].changed=true; 279 field[dest].changed=true;
280 field[source].color=0; 280 field[source].color=0;
281 field[source].changed=true; 281 field[source].changed=true;
282 } 282 }
283 } 283 }
284 284
285 // add a bonus, if field is empty 285 // add a bonus, if field is empty
286 if (!field[map(0, sizey-1)].color) { 286 if (!field[map(0, sizey-1)].color) {
287 score+=1000; 287 score+=1000;
288 m_gotBonus= true; 288 m_gotBonus= true;
289 } 289 }
290 290
291 // gameover is undefined 291 // gameover is undefined
292 gameover=-1; 292 gameover=-1;
293 return removed; 293 return removed;
294} 294}
295 295
296bool StoneField::undoPossible() const { 296bool StoneField::undoPossible() const {
297 return !(!undolist||undolist->isEmpty()); 297 return !(!undolist||undolist->isEmpty());
298} 298}
299 299
300int 300int
301StoneField::undo(int count) { 301StoneField::undo(int count) {
302 if (!undoPossible()) 302 if (!undoPossible())
303 return 0; 303 return 0;
304 if (count <= 0) 304 if (count <= 0)
305 return 0; 305 return 0;
306 int undocount=1; 306 int undocount=1;
307 StoneFieldState *state=0; 307 StoneFieldState *state=0;
308 undolist->setAutoDelete(true); 308 undolist->setAutoDelete(true);
309 while (--count>0) { 309 while (--count>0) {
310 if (undolist->count()==1) break; 310 if (undolist->count()==1) break;
311 undolist->removeLast(); 311 undolist->removeLast();
312 undocount++; 312 undocount++;
313 } 313 }
314 state=undolist->getLast(); 314 state=undolist->getLast();
315// Q_ASSERT(state); 315// Q_ASSERT(state);
316 state->restore(*this); 316 state->restore(*this);
317 undolist->removeLast(); 317 undolist->removeLast();
318 return undocount; 318 return undocount;
319} 319}
320 320
321bool 321bool
322StoneField::isGameover() const { 322StoneField::isGameover() const {
323 register int i=maxstone-1;; 323 register int i=maxstone-1;;
324 register unsigned char color; 324 register unsigned char color;
325 325
326 if (gameover>=0) return (bool)gameover; 326 if (gameover>=0) return (bool)gameover;
327 // kdDebug() << "-->gameover" << endl; 327 // kdDebug() << "-->gameover" << endl;
328 328
329 while (i>=0) { 329 while (i>=0) {
330 // kdDebug() << i << " " << field[i].color << endl; 330 // kdDebug() << i << " " << field[i].color << endl;
331 // ignore empty fields 331 // ignore empty fields
332 while ( i>=0 && field[i].color==0 ) i--; 332 while ( i>=0 && field[i].color==0 ) i--;
333 // Wenn Stein gefunden, 333 // Wenn Stein gefunden,
334 // dann die Nachbarn auf gleiche Farbe pruefen. 334 // dann die Nachbarn auf gleiche Farbe pruefen.
335 while ( i>=0 && (color=field[i].color) ) { 335 while ( i>=0 && (color=field[i].color) ) {
336 // check left 336 // check left
337 if ( (i%sizex)!=0 && field[i-1].color==color) 337 if ( (i%sizex)!=0 && field[i-1].color==color)
338 goto check_gameover; 338 goto check_gameover;
339 // check upward 339 // check upward
340 if ( i>=sizex && field[i-sizex].color==color) 340 if ( i>=sizex && field[i-sizex].color==color)
341 goto check_gameover; 341 goto check_gameover;
342 i--; 342 i--;
343 } 343 }
344 } 344 }
345 check_gameover: 345 check_gameover:
346 gameover=(i<0); 346 gameover=(i<0);
347 // kdDebug() << "<--gameover" << endl; 347 // kdDebug() << "<--gameover" << endl;
348 return (bool)gameover; 348 return (bool)gameover;
349} 349}
350 350
351bool StoneField::gotBonus() const { 351bool StoneField::gotBonus() const {
352 return m_gotBonus; 352 return m_gotBonus;
353} 353}
354 354
355void StoneField::clearBonus() {
356 m_gotBonus = false;
357}
358
355int 359int
356StoneField::getBoard() const { 360StoneField::getBoard() const {
357 return board; 361 return board;
358} 362}
359 363
360int 364int
361StoneField::getScore() const { 365StoneField::getScore() const {
362 return score; 366 return score;
363} 367}
364 368
365int 369int
366StoneField::getColors() const { 370StoneField::getColors() const {
367 return colors; 371 return colors;
368} 372}
369 373
370int 374int
371StoneField::getMarked() const { 375StoneField::getMarked() const {
372 return marked; 376 return marked;
373} 377}
374 378
375int 379int
376StoneField::getFieldSize() const { 380StoneField::getFieldSize() const {
377 return maxstone; 381 return maxstone;
378} 382}
379 383
380struct Stone * 384struct Stone *
381StoneField::getField() const { 385StoneField::getField() const {
382 return field; 386 return field;
383} 387}
384 388
385 389
386 390
387 391
388 392
389 393
390 394
diff --git a/noncore/games/zsame/StoneField.h b/noncore/games/zsame/StoneField.h
index 80be73a..d32d78d 100644
--- a/noncore/games/zsame/StoneField.h
+++ b/noncore/games/zsame/StoneField.h
@@ -1,113 +1,114 @@
1/* Yo Emacs, this is -*- C++ -*- */ 1/* Yo Emacs, this is -*- C++ -*- */
2/* 2/*
3 * ksame 0.4 - simple Game 3 * ksame 0.4 - simple Game
4 * Copyright (C) 1997,1998 Marcus Kreutzberger 4 * Copyright (C) 1997,1998 Marcus Kreutzberger
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * 19 *
20 */ 20 */
21 21
22#ifndef _STONEFIELD 22#ifndef _STONEFIELD
23#define _STONEFIELD 23#define _STONEFIELD
24 24
25#include <krandomsequence.h> 25#include <krandomsequence.h>
26#include <qlist.h> 26#include <qlist.h>
27 27
28struct Stone { 28struct Stone {
29 unsigned char color; 29 unsigned char color;
30 bool changed; 30 bool changed;
31 bool marked; 31 bool marked;
32}; 32};
33 33
34class StoneField; 34class StoneField;
35class StoneWidget; 35class StoneWidget;
36 36
37class StoneFieldState { 37class StoneFieldState {
38private: 38private:
39 unsigned char *field; 39 unsigned char *field;
40 40
41 int colors; 41 int colors;
42 unsigned int board; 42 unsigned int board;
43 unsigned int score; 43 unsigned int score;
44 int gameover; 44 int gameover;
45 45
46public: 46public:
47 StoneFieldState(const StoneField &stonefield); 47 StoneFieldState(const StoneField &stonefield);
48 ~StoneFieldState(); 48 ~StoneFieldState();
49 void restore(StoneField &stonefield) const; 49 void restore(StoneField &stonefield) const;
50}; 50};
51 51
52 52
53class StoneField { 53class StoneField {
54 friend class StoneFieldState; 54 friend class StoneFieldState;
55 friend class StoneWidget; 55 friend class StoneWidget;
56private: 56private:
57 57
58 int sizex; 58 int sizex;
59 int sizey; 59 int sizey;
60 int maxstone; 60 int maxstone;
61 61
62 struct Stone *field; 62 struct Stone *field;
63 63
64 int colors; 64 int colors;
65 unsigned int board; 65 unsigned int board;
66 unsigned int score; 66 unsigned int score;
67 mutable int gameover; 67 mutable int gameover;
68 bool m_gotBonus; 68 bool m_gotBonus;
69 int marked; 69 int marked;
70 70
71 KRandomSequence random; 71 KRandomSequence random;
72 QList<StoneFieldState> *undolist; 72 QList<StoneFieldState> *undolist;
73public: 73public:
74 StoneField(int width=15,int height=10, 74 StoneField(int width=15,int height=10,
75 int colors=3,unsigned int board=0, 75 int colors=3,unsigned int board=0,
76 bool undoenabled=true); 76 bool undoenabled=true);
77 ~StoneField(); 77 ~StoneField();
78 78
79 int width() const; 79 int width() const;
80 int height() const; 80 int height() const;
81 81
82 void newGame(unsigned int board,int colors); 82 void newGame(unsigned int board,int colors);
83 83
84 void reset(); 84 void reset();
85 85
86 86
87 int mark(int x,int y,bool force=false); 87 int mark(int x,int y,bool force=false);
88 void unmark(); 88 void unmark();
89 89
90 int remove(int x,int y,bool force=false); 90 int remove(int x,int y,bool force=false);
91 91
92 int undo(int count=1); 92 int undo(int count=1);
93 93
94 bool isGameover() const; 94 bool isGameover() const;
95 bool gotBonus() const; 95 bool gotBonus() const;
96 void clearBonus();
96 bool undoPossible() const; 97 bool undoPossible() const;
97 int getBoard() const; 98 int getBoard() const;
98 int getScore() const; 99 int getScore() const;
99 int getColors() const; 100 int getColors() const;
100 int getMarked() const; 101 int getMarked() const;
101 102
102protected: 103protected:
103 int getFieldSize() const; 104 int getFieldSize() const;
104 struct Stone *getField() const; 105 struct Stone *getField() const;
105 106
106 int map(int x,int y); 107 int map(int x,int y);
107 void mark(int index,unsigned char color); 108 void mark(int index,unsigned char color);
108}; 109};
109 110
110#endif 111#endif
111 112
112 113
113 114
diff --git a/noncore/games/zsame/StoneWidget.cpp b/noncore/games/zsame/StoneWidget.cpp
index 646fc9c..5dd0252 100644
--- a/noncore/games/zsame/StoneWidget.cpp
+++ b/noncore/games/zsame/StoneWidget.cpp
@@ -1,345 +1,349 @@
1/* 1/*
2 * ksame 0.4 - simple Game 2 * ksame 0.4 - simple Game
3 * Copyright (C) 1997,1998 Marcus Kreutzberger 3 * Copyright (C) 1997,1998 Marcus Kreutzberger
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or 7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * 18 *
19 */ 19 */
20 20
21#include <stdio.h> 21#include <stdio.h>
22#include <stdlib.h> 22#include <stdlib.h>
23 23
24 24
25 25
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27 27
28#include <time.h> 28#include <time.h>
29#include <assert.h> 29#include <assert.h>
30 30
31#include "StoneWidget.h" 31#include "StoneWidget.h"
32 32
33 33
34 34
35struct StoneSlice { 35struct StoneSlice {
36 QPixmap stone; 36 QPixmap stone;
37}; 37};
38 38
39 39
40StoneWidget::StoneWidget( QWidget *parent, int x, int y ) 40StoneWidget::StoneWidget( QWidget *parent, int x, int y )
41 : QWidget(parent,"StoneWidget"), stonefield(x,y) 41 : QWidget(parent,"StoneWidget"), stonefield(x,y)
42{ 42{
43// setBackgroundPixmap(QPixmap(locate("wallpaper", "Time-For-Lunch-2.jpg"))); 43// setBackgroundPixmap(QPixmap(locate("wallpaper", "Time-For-Lunch-2.jpg")));
44// QPixmap stonemap(locate("appdata", "stones.png")); 44// QPixmap stonemap(locate("appdata", "stones.png"));
45 45
46 QPixmap stonemap = Resource::loadPixmap("zsame/stones" ); 46 QPixmap stonemap = Resource::loadPixmap("zsame/stones" );
47 assert(!stonemap.isNull()); 47 assert(!stonemap.isNull());
48 48
49 slice=0; 49 slice=0;
50 maxslices=30; 50 maxslices=30;
51 maxcolors=4; 51 maxcolors=4;
52 52
53 sizex=x; 53 sizex=x;
54 sizey=y; 54 sizey=y;
55 55
56 stone_width=stonemap.width()/(maxslices+1); 56 stone_width=stonemap.width()/(maxslices+1);
57 stone_height=stonemap.height()/maxcolors; 57 stone_height=stonemap.height()/maxcolors;
58 58
59 map = new StoneSlice*[maxcolors]; 59 map = new StoneSlice*[maxcolors];
60 QBitmap mask; 60 QBitmap mask;
61 for (int c = 0; c < maxcolors; c++) { 61 for (int c = 0; c < maxcolors; c++) {
62 map[c] = new StoneSlice[maxslices]; 62 map[c] = new StoneSlice[maxslices];
63 63
64 for (int s = 0; s < maxslices; s++) { 64 for (int s = 0; s < maxslices; s++) {
65 map[c][s].stone.resize(stone_width, stone_height); 65 map[c][s].stone.resize(stone_width, stone_height);
66 assert(!map[c][s].stone.isNull()); 66 assert(!map[c][s].stone.isNull());
67 bitBlt(&map[c][s].stone, 0, 0, 67 bitBlt(&map[c][s].stone, 0, 0,
68 &stonemap, stone_width * s, 68 &stonemap, stone_width * s,
69 c*stone_height, 69 c*stone_height,
70 stone_width,stone_height,CopyROP,false); 70 stone_width,stone_height,CopyROP,false);
71 QImage im = map[c][s].stone.convertToImage(); 71 QImage im = map[c][s].stone.convertToImage();
72 mask = im.createHeuristicMask(); 72 mask = im.createHeuristicMask();
73 map[c][s].stone.setMask(mask); 73 map[c][s].stone.setMask(mask);
74 } 74 }
75 } 75 }
76 76
77 field_height=stone_height*sizey; 77 field_height=stone_height*sizey;
78 field_width=stone_width*sizex; 78 field_width=stone_width*sizex;
79 79
80 setMouseTracking(true); 80 setMouseTracking(true);
81 81
82 // QColor c(115,115,115); 82 // QColor c(115,115,115);
83 // setBackgroundColor(c); 83 // setBackgroundColor(c);
84 84
85 // emit s_sizechanged(); 85 // emit s_sizechanged();
86 startTimer( 100 ); 86 startTimer( 100 );
87 history.setAutoDelete(true); 87 history.setAutoDelete(true);
88} 88}
89 89
90StoneWidget::~StoneWidget() { 90StoneWidget::~StoneWidget() {
91 for (int c = 0; c < maxcolors; c++) { 91 for (int c = 0; c < maxcolors; c++) {
92 delete [] map[c]; 92 delete [] map[c];
93 } 93 }
94 delete [] map; 94 delete [] map;
95 95
96 setMouseTracking(false); 96 setMouseTracking(false);
97 killTimers(); 97 killTimers();
98} 98}
99 99
100unsigned int 100unsigned int
101StoneWidget::board() { 101StoneWidget::board() {
102 return stonefield.getBoard(); 102 return stonefield.getBoard();
103} 103}
104 104
105int 105int
106StoneWidget::score() { 106StoneWidget::score() {
107 return stonefield.getScore(); 107 return stonefield.getScore();
108} 108}
109 109
110int 110int
111StoneWidget::marked() { 111StoneWidget::marked() {
112 return stonefield.getMarked(); 112 return stonefield.getMarked();
113} 113}
114 114
115QSize 115QSize
116StoneWidget::size() { 116StoneWidget::size() {
117 return QSize(sizex,sizey); 117 return QSize(sizex,sizey);
118} 118}
119 119
120int 120int
121StoneWidget::colors() { 121StoneWidget::colors() {
122 return stonefield.getColors(); 122 return stonefield.getColors();
123} 123}
124 124
125QSize 125QSize
126StoneWidget::sizeHint () const { 126StoneWidget::sizeHint () const {
127 return QSize(field_width,field_height); 127 return QSize(field_width,field_height);
128} 128}
129 129
130void 130void
131StoneWidget::newGame(unsigned int board,int colors) { 131StoneWidget::newGame(unsigned int board,int colors) {
132 stonefield.newGame(board,colors); 132 stonefield.newGame(board,colors);
133 history.clear(); 133 history.clear();
134 modified= false; 134 modified= false;
135 emit s_newgame(); 135 emit s_newgame();
136 emit s_colors(stonefield.getColors()); 136 emit s_colors(stonefield.getColors());
137 emit s_board(stonefield.getBoard()); 137 emit s_board(stonefield.getBoard());
138} 138}
139 139
140void 140void
141StoneWidget::reset() { 141StoneWidget::reset() {
142 stonefield.reset(); 142 stonefield.reset();
143 history.clear(); 143 history.clear();
144 emit s_newgame(); 144 emit s_newgame();
145} 145}
146 146
147void 147void
148StoneWidget::unmark() { 148StoneWidget::unmark() {
149 stonefield.unmark(); 149 stonefield.unmark();
150 emit s_marked(0); 150 emit s_marked(0);
151} 151}
152 152
153bool StoneWidget::undoPossible() const { 153bool StoneWidget::undoPossible() const {
154 if (stonefield.isGameover()) return false; 154 if (stonefield.isGameover()) return false;
155 return stonefield.undoPossible(); 155 return stonefield.undoPossible();
156} 156}
157 157
158int 158int
159StoneWidget::undo(int count) { 159StoneWidget::undo(int count) {
160 if (stonefield.isGameover()) return 0; 160 if (stonefield.isGameover()) return 0;
161 161
162 int ret_val=stonefield.undo(count); 162 int ret_val=stonefield.undo(count);
163 163
164 QPoint p=mapFromGlobal(cursor().pos()); 164 QPoint p=mapFromGlobal(cursor().pos());
165 int x=p.x(); 165 int x=p.x();
166 int y=p.y(); 166 int y=p.y();
167 if (x<0||y<0||x>=field_width||y>=field_height) { 167 if (x<0||y<0||x>=field_width||y>=field_height) {
168 emit s_score(stonefield.getMarked()); 168 emit s_score(stonefield.getMarked());
169 return ret_val; 169 return ret_val;
170 } 170 }
171 171
172 int marked=stonefield.mark(x/stone_width,y/stone_height); 172 int marked=stonefield.mark(x/stone_width,y/stone_height);
173 emit s_marked(marked); 173 emit s_marked(marked);
174 slice=0; 174 slice=0;
175 emit s_score(stonefield.getScore()); 175 emit s_score(stonefield.getScore());
176 modified= (stonefield.getScore()>0); 176 modified= (stonefield.getScore()>0);
177 return ret_val; 177 return ret_val;
178} 178}
179 179
180bool StoneWidget::isGameover() { 180bool StoneWidget::isGameover() {
181 return stonefield.isGameover(); 181 return stonefield.isGameover();
182} 182}
183 183
184bool StoneWidget::hasBonus() { 184bool StoneWidget::hasBonus() {
185 return stonefield.gotBonus(); // don't ask me why the names differ... ;-| [hlm] 185 return stonefield.gotBonus(); // don't ask me why the names differ... ;-| [hlm]
186} 186}
187 187
188void StoneWidget::clearBonus() {
189 stonefield.clearBonus();
190}
191
188bool StoneWidget::isOriginalBoard() { 192bool StoneWidget::isOriginalBoard() {
189 return !modified; 193 return !modified;
190} 194}
191 195
192void StoneWidget::readProperties(Config *) { 196void StoneWidget::readProperties(Config *) {
193/* Q_ASSERT(conf); 197/* Q_ASSERT(conf);
194 198
195 history.clear(); 199 history.clear();
196 200
197 if (!conf->hasKey("Board")|| 201 if (!conf->hasKey("Board")||
198 !conf->hasKey("Colors")|| 202 !conf->hasKey("Colors")||
199 !conf->hasKey("Stones")) { 203 !conf->hasKey("Stones")) {
200 return; 204 return;
201 } 205 }
202 newGame(conf->readNumEntry("Board"),conf->readNumEntry("Colors")); 206 newGame(conf->readNumEntry("Board"),conf->readNumEntry("Colors"));
203 207
204 QStrList list; 208 QStrList list;
205 conf->readListEntry("Stones",list); 209 conf->readListEntry("Stones",list);
206 210
207 for (const char *item=list.first();item;item=list.next()) { 211 for (const char *item=list.first();item;item=list.next()) {
208 int x=-1,y=-1; 212 int x=-1,y=-1;
209 if (sscanf(item,"%02X%02X",&x,&y)!=2) break; 213 if (sscanf(item,"%02X%02X",&x,&y)!=2) break;
210 history.append(new QPoint(x,y)); 214 history.append(new QPoint(x,y));
211 stonefield.remove(x,y); 215 stonefield.remove(x,y);
212 } 216 }
213*/ 217*/
214} 218}
215 219
216 220
217void 221void
218StoneWidget::saveProperties(Config *) { 222StoneWidget::saveProperties(Config *) {
219/* 223/*
220 Q_ASSERT(conf); 224 Q_ASSERT(conf);
221 225
222 QStrList list(true); 226 QStrList list(true);
223 QString tmp; 227 QString tmp;
224 228
225 for (QPoint *item=history.first();item;item=history.next()) { 229 for (QPoint *item=history.first();item;item=history.next()) {
226 tmp.sprintf("%02X%02X",item->x(),item->y()); 230 tmp.sprintf("%02X%02X",item->x(),item->y());
227 list.append(tmp.ascii()); 231 list.append(tmp.ascii());
228 } 232 }
229 233
230 conf->writeEntry("Stones",list); 234 conf->writeEntry("Stones",list);
231 conf->writeEntry("Board",stonefield.getBoard()); 235 conf->writeEntry("Board",stonefield.getBoard());
232 conf->writeEntry("Colors",stonefield.getColors()); 236 conf->writeEntry("Colors",stonefield.getColors());
233*/ 237*/
234} 238}
235 239
236void 240void
237StoneWidget::timerEvent( QTimerEvent * ) { 241StoneWidget::timerEvent( QTimerEvent * ) {
238 QPoint p=mapFromGlobal(cursor().pos()); 242 QPoint p=mapFromGlobal(cursor().pos());
239 int x=p.x(); 243 int x=p.x();
240 int y=p.y(); 244 int y=p.y();
241 if (x<0||y<0||x>=field_width||y>=field_height) 245 if (x<0||y<0||x>=field_width||y>=field_height)
242 stonefield.unmark(); 246 stonefield.unmark();
243 slice=(slice+1)%maxslices; 247 slice=(slice+1)%maxslices;
244 paintEvent(0); 248 paintEvent(0);
245} 249}
246 250
247void 251void
248StoneWidget::paintEvent( QPaintEvent *e ) { 252StoneWidget::paintEvent( QPaintEvent *e ) {
249 253
250 Stone *stone=stonefield.getField(); 254 Stone *stone=stonefield.getField();
251 255
252 for (int y=0;y<sizey;y++) { 256 for (int y=0;y<sizey;y++) {
253 int cy = y * stone_height; 257 int cy = y * stone_height;
254 258
255 for (int x=0;x<sizex;x++) { 259 for (int x=0;x<sizex;x++) {
256 int cx = stone_width * x; 260 int cx = stone_width * x;
257 261
258 bool redraw=stone->marked||stone->changed; 262 bool redraw=stone->marked||stone->changed;
259 263
260 if (!redraw&&e) { 264 if (!redraw&&e) {
261 QRect r(cx,cy,stone_width,stone_height); 265 QRect r(cx,cy,stone_width,stone_height);
262 redraw=r.intersects(e->rect()); 266 redraw=r.intersects(e->rect());
263 } 267 }
264 if (redraw) { 268 if (redraw) {
265 stone->changed=false; 269 stone->changed=false;
266 if (stone->color) { 270 if (stone->color) {
267 271
268 int tslice = stone->marked?slice:0; 272 int tslice = stone->marked?slice:0;
269 bitBlt(this,cx,cy, 273 bitBlt(this,cx,cy,
270 &map[stone->color-1][tslice].stone, 274 &map[stone->color-1][tslice].stone,
271 0, 0, 275 0, 0,
272 stone_width,stone_height,CopyROP,FALSE); 276 stone_width,stone_height,CopyROP,FALSE);
273 277
274 } else { 278 } else {
275 erase(cx, cy, stone_width, stone_height); 279 erase(cx, cy, stone_width, stone_height);
276 } 280 }
277 } 281 }
278 stone++; // naechster Stein. 282 stone++; // naechster Stein.
279 } 283 }
280 } 284 }
281} 285}
282 286
283void 287void
284StoneWidget::mousePressEvent ( QMouseEvent *e) { 288StoneWidget::mousePressEvent ( QMouseEvent *e) {
285 289
286 if (stonefield.isGameover()) return; 290 if (stonefield.isGameover()) return;
287 291
288 int x=e->pos().x(); 292 int x=e->pos().x();
289 int y=e->pos().y(); 293 int y=e->pos().y();
290 if (x<0||y<0||x>=field_width||y>=field_height) return; 294 if (x<0||y<0||x>=field_width||y>=field_height) return;
291 295
292 int sx=x/stone_width; 296 int sx=x/stone_width;
293 int sy=y/stone_height; 297 int sy=y/stone_height;
294 298
295 int mar =stonefield.mark(sx, sy); 299 int mar =stonefield.mark(sx, sy);
296 300
297 if ( mar != -1 ) { 301 if ( mar != -1 ) {
298 myMoveEvent(e); 302 myMoveEvent(e);
299 return; 303 return;
300 } 304 }
301 305
302 306
303 if (stonefield.remove(sx, sy)) { 307 if (stonefield.remove(sx, sy)) {
304 history.append(new QPoint(sx, sy)); 308 history.append(new QPoint(sx, sy));
305 309
306 emit s_remove(sx, sy); 310 emit s_remove(sx, sy);
307 311
308 stonefield.mark(sx,sy); 312 stonefield.mark(sx,sy);
309 emit s_marked(stonefield.getMarked()); 313 emit s_marked(stonefield.getMarked());
310 modified= true; 314 modified= true;
311 315
312 emit s_score(stonefield.getScore()); 316 emit s_score(stonefield.getScore());
313 if (stonefield.isGameover()) emit s_gameover(); 317 if (stonefield.isGameover()) emit s_gameover();
314 } 318 }
315} 319}
316 320
317void 321void
318StoneWidget::myMoveEvent ( QMouseEvent *e) 322StoneWidget::myMoveEvent ( QMouseEvent *e)
319{ 323{
320 return; 324 return;
321 325
322 if (stonefield.isGameover()) { 326 if (stonefield.isGameover()) {
323 stonefield.unmark(); 327 stonefield.unmark();
324 emit s_marked(0); 328 emit s_marked(0);
325 return; 329 return;
326 } 330 }
327 331
328 int x=e->pos().x(); 332 int x=e->pos().x();
329 int y=e->pos().y(); 333 int y=e->pos().y();
330 if (x<0||y<0||x>=field_width||y>=field_height) return; 334 if (x<0||y<0||x>=field_width||y>=field_height) return;
331 335
332 int marked=stonefield.mark(x/stone_width,y/stone_height); 336 int marked=stonefield.mark(x/stone_width,y/stone_height);
333 if (marked>=0) { 337 if (marked>=0) {
334 emit s_marked(marked); 338 emit s_marked(marked);
335 slice=0; 339 slice=0;
336 } 340 }
337} 341}
338 342
339 343
340 344
341 345
342 346
343 347
344 348
345 349
diff --git a/noncore/games/zsame/StoneWidget.h b/noncore/games/zsame/StoneWidget.h
index 9cd7e10..89a8afc 100644
--- a/noncore/games/zsame/StoneWidget.h
+++ b/noncore/games/zsame/StoneWidget.h
@@ -1,115 +1,116 @@
1/* Yo Emacs, this is -*- C++ -*- */ 1/* Yo Emacs, this is -*- C++ -*- */
2/* 2/*
3 * ksame 0.4 - simple Game 3 * ksame 0.4 - simple Game
4 * Copyright (C) 1997,1998 Marcus Kreutzberger 4 * Copyright (C) 1997,1998 Marcus Kreutzberger
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * 19 *
20 */ 20 */
21 21
22#ifndef _STONEWIDGET 22#ifndef _STONEWIDGET
23#define _STONEWIDGET 23#define _STONEWIDGET
24 24
25#include <qpixmap.h> 25#include <qpixmap.h>
26#include <qwidget.h> 26#include <qwidget.h>
27 27
28#include <qpe/config.h> 28#include <qpe/config.h>
29 29
30#include "StoneField.h" 30#include "StoneField.h"
31 31
32struct StoneSlice; 32struct StoneSlice;
33 33
34class StoneWidget : public QWidget { 34class StoneWidget : public QWidget {
35 Q_OBJECT 35 Q_OBJECT
36 36
37 int modified; 37 int modified;
38 // int marked; // # of marked stones 38 // int marked; // # of marked stones
39 39
40 int stones_x, stones_y; 40 int stones_x, stones_y;
41 int sizex, sizey; 41 int sizex, sizey;
42 int field_width, field_height; 42 int field_width, field_height;
43 43
44 QList<QPoint> history; 44 QList<QPoint> history;
45 StoneField stonefield; 45 StoneField stonefield;
46 46
47 // picture number of stonemovie 47 // picture number of stonemovie
48 int slice; 48 int slice;
49 49
50 StoneSlice **map; 50 StoneSlice **map;
51 51
52public: 52public:
53 StoneWidget( QWidget *parent=0, int x=10,int y=10); 53 StoneWidget( QWidget *parent=0, int x=10,int y=10);
54 ~StoneWidget(); 54 ~StoneWidget();
55 55
56 unsigned int board(); 56 unsigned int board();
57 int score(); 57 int score();
58 int marked(); 58 int marked();
59 QSize size(); 59 QSize size();
60 int colors(); 60 int colors();
61 virtual QSize sizeHint() const; 61 virtual QSize sizeHint() const;
62 62
63 bool undoPossible() const; 63 bool undoPossible() const;
64 64
65 void newGame(unsigned int board, int colors); 65 void newGame(unsigned int board, int colors);
66 void reset(); 66 void reset();
67 void unmark(); 67 void unmark();
68 int undo(int count=1); 68 int undo(int count=1);
69 69
70 // test for game end 70 // test for game end
71 bool isGameover(); 71 bool isGameover();
72 // if isGameover(): finished with bonus? 72 // if isGameover(): finished with bonus?
73 bool hasBonus(); 73 bool hasBonus();
74 void clearBonus();
74 // test for unchanged start position 75 // test for unchanged start position
75 bool isOriginalBoard(); 76 bool isOriginalBoard();
76 77
77 virtual void readProperties(Config *conf); 78 virtual void readProperties(Config *conf);
78 virtual void saveProperties(Config *conf); 79 virtual void saveProperties(Config *conf);
79 80
80protected: 81protected:
81 82
82 void timerEvent( QTimerEvent *e ); 83 void timerEvent( QTimerEvent *e );
83 void paintEvent( QPaintEvent *e ); 84 void paintEvent( QPaintEvent *e );
84 void mousePressEvent ( QMouseEvent *e); 85 void mousePressEvent ( QMouseEvent *e);
85 void myMoveEvent ( QMouseEvent *e); 86 void myMoveEvent ( QMouseEvent *e);
86 87
87 // properties of the stone picture 88 // properties of the stone picture
88 int stone_width,stone_height; // size of one stone 89 int stone_width,stone_height; // size of one stone
89 int maxcolors; // number of different stones (Y direction) 90 int maxcolors; // number of different stones (Y direction)
90 int maxslices; // number of pictures per movie (X direction) 91 int maxslices; // number of pictures per movie (X direction)
91 92
92signals: 93signals:
93 // A new game begins 94 // A new game begins
94 void s_newgame(); 95 void s_newgame();
95 96
96 void s_colors(int colors); 97 void s_colors(int colors);
97 void s_board(int board); 98 void s_board(int board);
98 void s_score(int score); 99 void s_score(int score);
99 void s_marked(int m); 100 void s_marked(int m);
100 101
101 void s_gameover(); 102 void s_gameover();
102 103
103 // The stone (x,y) was clicked(removed), 104 // The stone (x,y) was clicked(removed),
104 // all neighbor stones disappear without further signals 105 // all neighbor stones disappear without further signals
105 void s_remove(int x,int y); 106 void s_remove(int x,int y);
106 107
107 void s_sizechanged(); 108 void s_sizechanged();
108}; 109};
109 110
110#endif 111#endif
111 112
112 113
113 114
114 115
115 116
diff --git a/noncore/games/zsame/ZSameWidget.cpp b/noncore/games/zsame/ZSameWidget.cpp
index 04ad825..dee4a1c 100644
--- a/noncore/games/zsame/ZSameWidget.cpp
+++ b/noncore/games/zsame/ZSameWidget.cpp
@@ -1,244 +1,245 @@
1/* Yo Emacs, this is -*- C++ -*- */ 1/* Yo Emacs, this is -*- C++ -*- */
2/* 2/*
3 * ksame 0.4 - simple Game 3 * ksame 0.4 - simple Game
4 * Copyright (C) 1997,1998 Marcus Kreutzberger 4 * Copyright (C) 1997,1998 Marcus Kreutzberger
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * 19 *
20 */ 20 */
21 21
22#include <stdio.h> 22#include <stdio.h>
23 23
24#include <opie2/oapplicationfactory.h> 24#include <opie2/oapplicationfactory.h>
25 25
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27 27
28#include <qtoolbar.h> 28#include <qtoolbar.h>
29#include <qmenubar.h> 29#include <qmenubar.h>
30#include <qapplication.h> 30#include <qapplication.h>
31#include <qaction.h> 31#include <qaction.h>
32#include <qmessagebox.h> 32#include <qmessagebox.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35 35
36#include "ZSameWidget.h" 36#include "ZSameWidget.h"
37 37
38static int default_colors=3; 38static int default_colors=3;
39 39
40#define i18n tr 40#define i18n tr
41 41
42 42
43using namespace Opie::Core; 43using namespace Opie::Core;
44OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> ) 44OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> )
45 45
46 46
47 47
48ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl ) 48ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl )
49 : QMainWindow( parent, name, fl ) 49 : QMainWindow( parent, name, fl )
50{ 50{
51 setCaption(tr("ZSame")); 51 setCaption(tr("ZSame"));
52 52
53 setToolBarsMovable( false ); 53 setToolBarsMovable( false );
54 QToolBar* con = new QToolBar( this ); 54 QToolBar* con = new QToolBar( this );
55 con->setHorizontalStretchable( true ); 55 con->setHorizontalStretchable( true );
56 QMenuBar* mb = new QMenuBar( con ); 56 QMenuBar* mb = new QMenuBar( con );
57 QToolBar* tb = new QToolBar( this ); 57 QToolBar* tb = new QToolBar( this );
58 58
59 QPopupMenu* fileMenu = new QPopupMenu( this ); 59 QPopupMenu* fileMenu = new QPopupMenu( this );
60 60
61 QAction* a = new QAction(tr("New Game"), Resource::loadIconSet("new") , 61 QAction* a = new QAction(tr("New Game"), Resource::loadIconSet("new") ,
62 QString::null, 0, this, "new_icon"); 62 QString::null, 0, this, "new_icon");
63 a->addTo( fileMenu ); 63 a->addTo( fileMenu );
64 a->addTo( tb ); 64 a->addTo( tb );
65 connect(a, SIGNAL(activated()), this, SLOT(m_new())); 65 connect(a, SIGNAL(activated()), this, SLOT(m_new()));
66 66
67 a = new QAction(tr("Restart This Board"), Resource::loadIconSet("redo"), 67 a = new QAction(tr("Restart This Board"), Resource::loadIconSet("redo"),
68 QString::null, 0, this, "restart_board" ); 68 QString::null, 0, this, "restart_board" );
69 a->addTo( fileMenu ); 69 a->addTo( fileMenu );
70 connect( a, SIGNAL(activated()), this, SLOT(m_restart())); 70 connect( a, SIGNAL(activated()), this, SLOT(m_restart()));
71 restart = a; 71 restart = a;
72 72
73 a = new QAction( tr("Undo"), Resource::loadIconSet("undo"), 73 a = new QAction( tr("Undo"), Resource::loadIconSet("undo"),
74 QString::null, 0, this, "undo_action" ); 74 QString::null, 0, this, "undo_action" );
75 a->addTo( fileMenu ); 75 a->addTo( fileMenu );
76 a->addTo( tb ); 76 a->addTo( tb );
77 connect( a, SIGNAL(activated()), this, SLOT(m_undo())); 77 connect( a, SIGNAL(activated()), this, SLOT(m_undo()));
78 78
79 a = new QAction(tr("Quit"), Resource::loadIconSet("quit_icon"), 79 a = new QAction(tr("Quit"), Resource::loadIconSet("quit_icon"),
80 QString::null, 0, this, "quit_action"); 80 QString::null, 0, this, "quit_action");
81 a->addTo( fileMenu ); 81 a->addTo( fileMenu );
82 a->addTo( tb ); 82 a->addTo( tb );
83 connect(a, SIGNAL(activated()), this, SLOT(m_quit())); 83 connect(a, SIGNAL(activated()), this, SLOT(m_quit()));
84 84
85 mb->insertItem(tr("Game" ), fileMenu ); 85 mb->insertItem(tr("Game" ), fileMenu );
86 86
87 int foo[2]; 87 int foo[2];
88 desktop_widget(foo); 88 desktop_widget(foo);
89 stone = new StoneWidget(this,foo[0],foo[1]); 89 stone = new StoneWidget(this,foo[0],foo[1]);
90 90
91 connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover())); 91 connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover()));
92 92
93 connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int))); 93 connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int)));
94 connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int))); 94 connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int)));
95 connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int))); 95 connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int)));
96 connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int))); 96 connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int)));
97 connect( stone, SIGNAL(s_remove(int,int)), this, SLOT(stonesRemoved(int,int))); 97 connect( stone, SIGNAL(s_remove(int,int)), this, SLOT(stonesRemoved(int,int)));
98 98
99 connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged())); 99 connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged()));
100 100
101 sizeChanged(); 101 sizeChanged();
102 setCentralWidget(stone); 102 setCentralWidget(stone);
103 103
104 104
105 setScore(0); 105 setScore(0);
106} 106}
107 107
108ZSameWidget::~ZSameWidget() { 108ZSameWidget::~ZSameWidget() {
109 109
110} 110}
111 111
112void ZSameWidget::readProperties(Config *) { 112void ZSameWidget::readProperties(Config *) {
113/* 113/*
114 Q_ASSERT(conf); 114 Q_ASSERT(conf);
115 stone->readProperties(conf); 115 stone->readProperties(conf);
116*/ 116*/
117} 117}
118 118
119void ZSameWidget::saveProperties(Config *) { 119void ZSameWidget::saveProperties(Config *) {
120/* 120/*
121 Q_ASSERT(conf); 121 Q_ASSERT(conf);
122 stone->saveProperties(conf); 122 stone->saveProperties(conf);
123 conf->sync(); 123 conf->sync();
124*/ 124*/
125} 125}
126 126
127void ZSameWidget::sizeChanged() { 127void ZSameWidget::sizeChanged() {
128 //stone->setFixedSize(stone->sizeHint()); 128 //stone->setFixedSize(stone->sizeHint());
129} 129}
130 130
131void ZSameWidget::newGame(unsigned int board,int colors) { 131void ZSameWidget::newGame(unsigned int board,int colors) {
132 while (board>=1000000) board-=1000000; 132 while (board>=1000000) board-=1000000;
133 // kdDebug() << "newgame board " << board << " colors " << colors << endl; 133 // kdDebug() << "newgame board " << board << " colors " << colors << endl;
134 stone->newGame(board,colors); 134 stone->newGame(board,colors);
135 setScore(0); 135 setScore(0);
136} 136}
137 137
138bool ZSameWidget::confirmAbort() { 138bool ZSameWidget::confirmAbort() {
139 return stone->isGameover() || 139 return stone->isGameover() ||
140 stone->isOriginalBoard() || 140 stone->isOriginalBoard() ||
141 (QMessageBox::warning(this, i18n("Resign"), i18n("<qt>Do you want to resign?</qt>"), 141 (QMessageBox::warning(this, i18n("Resign"), i18n("<qt>Do you want to resign?</qt>"),
142 QMessageBox::Yes, 142 QMessageBox::Yes,
143 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes ); 143 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes );
144} 144}
145 145
146void ZSameWidget::m_new() { 146void ZSameWidget::m_new() {
147 if (confirmAbort()) 147 if (confirmAbort())
148 newGame(_random(),default_colors); 148 newGame(_random(),default_colors);
149 149
150} 150}
151 151
152void ZSameWidget::m_restart() { 152void ZSameWidget::m_restart() {
153 if (confirmAbort()) 153 if (confirmAbort())
154 newGame(stone->board(),default_colors); 154 newGame(stone->board(),default_colors);
155} 155}
156 156
157void ZSameWidget::m_load() { 157void ZSameWidget::m_load() {
158// kdDebug() << "menu load not supported" << endl; 158// kdDebug() << "menu load not supported" << endl;
159} 159}
160 160
161void ZSameWidget::m_save() { 161void ZSameWidget::m_save() {
162// kdDebug() << "menu save not supported" << endl; 162// kdDebug() << "menu save not supported" << endl;
163} 163}
164 164
165void ZSameWidget::m_undo() { 165void ZSameWidget::m_undo() {
166 //Q_ASSERT(stone); 166 //Q_ASSERT(stone);
167 stone->undo(); 167 stone->undo();
168} 168}
169 169
170 170
171void ZSameWidget::m_showhs() { 171void ZSameWidget::m_showhs() {
172/* Q_ASSERT(stone); 172/* Q_ASSERT(stone);
173 stone->unmark(); 173 stone->unmark();
174 KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this); 174 KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this);
175 d.addField(Board, i18n("Board"), "Board"); 175 d.addField(Board, i18n("Board"), "Board");
176 d.exec(); 176 d.exec();
177*/ 177*/
178} 178}
179 179
180void ZSameWidget::m_quit() { 180void ZSameWidget::m_quit() {
181// Q_ASSERT(stone); 181// Q_ASSERT(stone);
182 stone->unmark(); 182 stone->unmark();
183 qApp->quit(); 183 qApp->quit();
184// delete this; 184// delete this;
185} 185}
186 186
187void ZSameWidget::m_tglboard() { 187void ZSameWidget::m_tglboard() {
188 //kdDebug() << "toggled" << endl; 188 //kdDebug() << "toggled" << endl;
189} 189}
190 190
191 191
192void ZSameWidget::setColors(int ) { 192void ZSameWidget::setColors(int ) {
193 //status->changeItem(i18n("%1 Colors").arg(colors),1); 193 //status->changeItem(i18n("%1 Colors").arg(colors),1);
194} 194}
195 195
196void ZSameWidget::setBoard(int ) { 196void ZSameWidget::setBoard(int ) {
197 //status->changeItem(i18n("Board: %1").arg(board, 6), 2); 197 //status->changeItem(i18n("Board: %1").arg(board, 6), 2);
198} 198}
199 199
200void ZSameWidget::setMarked(int ) { 200void ZSameWidget::setMarked(int ) {
201// status->changeItem(i18n("Marked: %1").arg(m, 6),3); 201// status->changeItem(i18n("Marked: %1").arg(m, 6),3);
202} 202}
203 203
204void ZSameWidget::stonesRemoved(int,int) { 204void ZSameWidget::stonesRemoved(int,int) {
205 //KNotifyClient::event("stones removed", 205 //KNotifyClient::event("stones removed",
206 // i18n("%1 stones removed.").arg(stone->marked())); 206 // i18n("%1 stones removed.").arg(stone->marked()));
207} 207}
208 208
209void ZSameWidget::setScore(int ) { 209void ZSameWidget::setScore(int ) {
210// status->changeItem(i18n("Score: %1").arg(score, 6),4); 210// status->changeItem(i18n("Score: %1").arg(score, 6),4);
211// undo->setEnabled(stone->undoPossible()); 211// undo->setEnabled(stone->undoPossible());
212// restart->setEnabled(!stone->isOriginalBoard()); 212// restart->setEnabled(!stone->isOriginalBoard());
213} 213}
214 214
215void ZSameWidget::gameover() { 215void ZSameWidget::gameover() {
216// kdDebug() << "GameOver" << endl; 216// kdDebug() << "GameOver" << endl;
217 if (stone->hasBonus()) { 217 if (stone->hasBonus()) {
218 QMessageBox::information(this,i18n("Game won"), 218 QMessageBox::information(this,i18n("Game won"),
219 i18n("<qt>You even removed the last stone, great job! " 219 i18n("<qt>You even removed the last stone, great job! "
220 "This gave you a score of %1 in total.</qt>").arg(stone->score())); 220 "This gave you a score of %1 in total.</qt>").arg(stone->score()));
221 stone->clearBonus();
221 } else { 222 } else {
222 QMessageBox::information(this,i18n("Game over"), 223 QMessageBox::information(this,i18n("Game over"),
223 i18n("<qt>There are no more removeable stones. " 224 i18n("<qt>There are no more removeable stones. "
224 "You got a score of %1 in total.</qt>").arg(stone->score())); 225 "You got a score of %1 in total.</qt>").arg(stone->score()));
225 } 226 }
226 stone->unmark(); 227 stone->unmark();
227} 228}
228 229
229void ZSameWidget::desktop_widget(int *f)const{ 230void ZSameWidget::desktop_widget(int *f)const{
230 231
231 QWidget* wid = QApplication::desktop(); 232 QWidget* wid = QApplication::desktop();
232 /* width > height landscape mode */ 233 /* width > height landscape mode */
233 if ( wid->width() > wid->height() ) { 234 if ( wid->width() > wid->height() ) {
234 f[0]=15; 235 f[0]=15;
235 f[1]=9; 236 f[1]=9;
236 } 237 }
237 /* normal */ 238 /* normal */
238 else{ 239 else{
239 f[0]=12; 240 f[0]=12;
240 f[1]=13; 241 f[1]=13;
241 } 242 }
242} 243}
243 244
244 245