summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/bounce/main.cpp1
-rw-r--r--noncore/games/buzzword/main.cpp1
-rw-r--r--noncore/games/fifteen/main.cpp1
-rw-r--r--noncore/games/go/gowidget.cpp2
-rw-r--r--noncore/games/go/main.cpp1
-rw-r--r--noncore/games/kcheckers/main.cpp1
-rw-r--r--noncore/games/minesweep/main.cpp1
-rw-r--r--noncore/games/parashoot/main.cpp1
-rw-r--r--noncore/games/qasteroids/main.cpp1
-rw-r--r--noncore/games/snake/interface.cpp2
-rw-r--r--noncore/games/snake/main.cpp1
-rw-r--r--noncore/games/solitaire/main.cpp1
-rw-r--r--noncore/games/tetrix/main.cpp1
-rw-r--r--noncore/games/tictac/main.cpp1
-rw-r--r--noncore/games/wordgame/main.cpp1
-rw-r--r--noncore/games/wordgame/wordgame.cpp2
-rw-r--r--noncore/games/zlines/main.cpp1
-rw-r--r--noncore/games/zsame/ZSameWidget.cpp1
18 files changed, 18 insertions, 3 deletions
diff --git a/noncore/games/bounce/main.cpp b/noncore/games/bounce/main.cpp
index eb8d561..bec4a86 100644
--- a/noncore/games/bounce/main.cpp
+++ b/noncore/games/bounce/main.cpp
@@ -1,24 +1,25 @@
1/* 1/*
2 * Copyright (C) 2000 Stefan Schimanski <schimmi@kde.org> 2 * Copyright (C) 2000 Stefan Schimanski <schimmi@kde.org>
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public 14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free 15 * License along with this program; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */ 17 */
18 18
19#include "kbounce.h" 19#include "kbounce.h"
20 20
21#include <opie2/oapplicationfactory.h> 21#include <opie2/oapplicationfactory.h>
22 22
23using namespace Opie::Core;
23OPIE_EXPORT_APP( OApplicationFactory<KJezzball> ) 24OPIE_EXPORT_APP( OApplicationFactory<KJezzball> )
24 25
diff --git a/noncore/games/buzzword/main.cpp b/noncore/games/buzzword/main.cpp
index 596cf16..a95e91a 100644
--- a/noncore/games/buzzword/main.cpp
+++ b/noncore/games/buzzword/main.cpp
@@ -1,23 +1,24 @@
1/* 1/*
2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch> 2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch>
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public 5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License,Life or (at your option) any later version. 7 * version 2 of the License,Life or (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public 14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free 15 * License along with this program; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */ 17 */
18 18
19#include <opie2/oapplicationfactory.h> 19#include <opie2/oapplicationfactory.h>
20 20
21#include "buzzword.h" 21#include "buzzword.h"
22 22
23using namespace Opie::Core;
23OPIE_EXPORT_APP( OApplicationFactory<BuzzWord> ) 24OPIE_EXPORT_APP( OApplicationFactory<BuzzWord> )
diff --git a/noncore/games/fifteen/main.cpp b/noncore/games/fifteen/main.cpp
index ed74a47..800a270 100644
--- a/noncore/games/fifteen/main.cpp
+++ b/noncore/games/fifteen/main.cpp
@@ -1,23 +1,24 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2004 Holger Freyther. All rights reserved. 2** Copyright (C) 2004 Holger Freyther. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16**********************************************************************/ 16**********************************************************************/
17 17
18#include "fifteen.h" 18#include "fifteen.h"
19 19
20#include <opie2/oapplicationfactory.h> 20#include <opie2/oapplicationfactory.h>
21 21
22using namespace Opie::Core;
22OPIE_EXPORT_APP( OApplicationFactory<FifteenMainWindow> ) 23OPIE_EXPORT_APP( OApplicationFactory<FifteenMainWindow> )
23 24
diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp
index 79820b1..d134540 100644
--- a/noncore/games/go/gowidget.cpp
+++ b/noncore/games/go/gowidget.cpp
@@ -1,460 +1,460 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "gowidget.h" 21#include "gowidget.h"
22 22
23#include <qpe/config.h> 23#include <qpe/config.h>
24#include <qpe/resource.h> 24#include <qpe/resource.h>
25 25
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qpe/qpetoolbar.h> 27#include <qtoolbar.h>
28#include <qmenubar.h> 28#include <qmenubar.h>
29#include <qaction.h> 29#include <qaction.h>
30#include <qapplication.h> //processEvents() 30#include <qapplication.h> //processEvents()
31#include <qlabel.h> 31#include <qlabel.h>
32 32
33//#include <stdio.h> 33//#include <stdio.h>
34 34
35 35
36static const enum bVal computer_color = BLACK; 36static const enum bVal computer_color = BLACK;
37 37
38static int current_handicap = 1; 38static int current_handicap = 1;
39 39
40static QBrush *goBrush; 40static QBrush *goBrush;
41//static QImage *newBlackStone; 41//static QImage *newBlackStone;
42//static QImage *blackStone; 42//static QImage *blackStone;
43//static QImage *whiteStone; 43//static QImage *whiteStone;
44static QPixmap *newBlackStone; 44static QPixmap *newBlackStone;
45static QPixmap *blackStone; 45static QPixmap *blackStone;
46static QPixmap *whiteStone; 46static QPixmap *whiteStone;
47 47
48static bool smallStones = FALSE; 48static bool smallStones = FALSE;
49 49
50GoMainWidget::GoMainWidget( QWidget *parent, const char* name, WFlags fl) : 50GoMainWidget::GoMainWidget( QWidget *parent, const char* name, WFlags fl) :
51 QMainWindow( parent, name, fl ) 51 QMainWindow( parent, name, fl )
52{ 52{
53 setToolBarsMovable( FALSE ); 53 setToolBarsMovable( FALSE );
54 GoWidget *go = new GoWidget(this); 54 GoWidget *go = new GoWidget(this);
55 55
56 setCentralWidget(go); 56 setCentralWidget(go);
57 toolbar = new QToolBar(this); 57 toolbar = new QToolBar(this);
58 toolbar->setHorizontalStretchable( TRUE ); 58 toolbar->setHorizontalStretchable( TRUE );
59 addToolBar(toolbar); 59 addToolBar(toolbar);
60 60
61 QMenuBar *mb = new QMenuBar( toolbar ); 61 QMenuBar *mb = new QMenuBar( toolbar );
62 mb->setMargin(0); 62 mb->setMargin(0);
63 QPopupMenu *file = new QPopupMenu( this ); 63 QPopupMenu *file = new QPopupMenu( this );
64 64
65 QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); 65 QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 );
66 connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); 66 connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) );
67 a->addTo( file ); 67 a->addTo( file );
68 68
69 a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); 69 a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 );
70 connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); 70 connect( a, SIGNAL( activated() ), go, SLOT( pass() ) );
71 a->addTo( file ); 71 a->addTo( file );
72 a->addTo( toolbar ); 72 a->addTo( toolbar );
73 73
74 74
75 a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); 75 a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 );
76 connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); 76 connect( a, SIGNAL( activated() ), go, SLOT( resign() ) );
77 a->addTo( file ); 77 a->addTo( file );
78 78
79 a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); 79 a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 );
80 a->setToggleAction( TRUE ); 80 a->setToggleAction( TRUE );
81 connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); 81 connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) );
82 a->addTo( file ); 82 a->addTo( file );
83 83
84 mb->insertItem( tr( "Game" ), file ); 84 mb->insertItem( tr( "Game" ), file );
85 85
86 QLabel *turnLabel = new QLabel( toolbar ); 86 QLabel *turnLabel = new QLabel( toolbar );
87 turnLabel->setBackgroundMode( PaletteButton ); 87 turnLabel->setBackgroundMode( PaletteButton );
88 connect( go, SIGNAL(showTurn(const QPixmap&)), 88 connect( go, SIGNAL(showTurn(const QPixmap&)),
89 turnLabel, SLOT(setPixmap(const QPixmap&)) ); 89 turnLabel, SLOT(setPixmap(const QPixmap&)) );
90 90
91 91
92 QLabel * scoreLabel = new QLabel( toolbar ); 92 QLabel * scoreLabel = new QLabel( toolbar );
93 scoreLabel->setBackgroundMode( PaletteButton ); 93 scoreLabel->setBackgroundMode( PaletteButton );
94 connect( go, SIGNAL(showScore(const QString&)), 94 connect( go, SIGNAL(showScore(const QString&)),
95 scoreLabel, SLOT(setText(const QString&)) ); 95 scoreLabel, SLOT(setText(const QString&)) );
96 96
97 toolbar->setStretchableWidget( scoreLabel ); 97 toolbar->setStretchableWidget( scoreLabel );
98 98
99 go->readConfig(); 99 go->readConfig();
100} 100}
101 101
102void GoMainWidget::resizeEvent( QResizeEvent * ) 102void GoMainWidget::resizeEvent( QResizeEvent * )
103{ 103{
104 //### this won't work because of the text label... 104 //### this won't work because of the text label...
105 /* 105 /*
106 if ( width() > height() ) 106 if ( width() > height() )
107 moveToolBar( toolbar, Left ); 107 moveToolBar( toolbar, Left );
108 else 108 else
109 moveToolBar( toolbar, Top ); 109 moveToolBar( toolbar, Top );
110 */ 110 */
111} 111}
112 112
113GoWidget *GoWidget::self = 0; 113GoWidget *GoWidget::self = 0;
114 114
115GoWidget::GoWidget( QWidget *parent, const char* name) : 115GoWidget::GoWidget( QWidget *parent, const char* name) :
116 QWidget( parent, name ) 116 QWidget( parent, name )
117{ 117{
118 if ( self ) 118 if ( self )
119 fatal( "Only one Go widget allowed" ); 119 fatal( "Only one Go widget allowed" );
120 self = this; 120 self = this;
121 twoplayer = FALSE; 121 twoplayer = FALSE;
122 122
123 123
124 d = bx = by = 1; 124 d = bx = by = 1;
125 125
126 QPixmap pix = Resource::loadPixmap( "go/pine" ); 126 QPixmap pix = Resource::loadPixmap( "go/pine" );
127 goBrush = new QBrush( black, pix ); 127 goBrush = new QBrush( black, pix );
128 /* 128 /*
129 QString fn = Resource::findPixmap("Go-black"); 129 QString fn = Resource::findPixmap("Go-black");
130 blackStone = new QImage( fn ); 130 blackStone = new QImage( fn );
131 fn = Resource::findPixmap("Go-black-highlight"); 131 fn = Resource::findPixmap("Go-black-highlight");
132 newBlackStone = new QImage( fn ); 132 newBlackStone = new QImage( fn );
133 fn = Resource::findPixmap("Go-white"); 133 fn = Resource::findPixmap("Go-white");
134 whiteStone = new QImage( fn ); 134 whiteStone = new QImage( fn );
135 */ 135 */
136 blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); 136 blackStone = new QPixmap(Resource::loadPixmap( "Go-black" ));
137 whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); 137 whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" ));
138 newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); 138 newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" ));
139 139
140 init(); 140 init();
141} 141}
142 142
143GoWidget::~GoWidget() 143GoWidget::~GoWidget()
144{ 144{
145 writeConfig(); 145 writeConfig();
146} 146}
147 147
148void GoWidget::writeConfig() 148void GoWidget::writeConfig()
149{ 149{
150 Config cfg("Go"); 150 Config cfg("Go");
151 cfg.setGroup("Game"); 151 cfg.setGroup("Game");
152 cfg.writeEntry("TwoPlayer", twoplayer); 152 cfg.writeEntry("TwoPlayer", twoplayer);
153 cfg.writeEntry("CurrentPlayer", currentPlayer); 153 cfg.writeEntry("CurrentPlayer", currentPlayer);
154 cfg.writeEntry("NPassed", nPassed); 154 cfg.writeEntry("NPassed", nPassed);
155 QString b; 155 QString b;
156 for (int i=0; i<19; i++) 156 for (int i=0; i<19; i++)
157 for (int j=0; j<19; j++) 157 for (int j=0; j<19; j++)
158 b += board[i][j] == BLACK ? 'B' : board[i][j] == WHITE ? 'W' : '.'; 158 b += board[i][j] == BLACK ? 'B' : board[i][j] == WHITE ? 'W' : '.';
159 cfg.writeEntry("Board", b); 159 cfg.writeEntry("Board", b);
160 cfg.writeEntry("LastX", lastX); 160 cfg.writeEntry("LastX", lastX);
161 cfg.writeEntry("LastY", lastY); 161 cfg.writeEntry("LastY", lastY);
162 extern int blackPrisoners, whitePrisoners; 162 extern int blackPrisoners, whitePrisoners;
163 cfg.writeEntry("BlackPrisoners", blackPrisoners); 163 cfg.writeEntry("BlackPrisoners", blackPrisoners);
164 cfg.writeEntry("WhitePrisoners", whitePrisoners); 164 cfg.writeEntry("WhitePrisoners", whitePrisoners);
165} 165}
166 166
167void GoWidget::readConfig() 167void GoWidget::readConfig()
168{ 168{
169 init(); 169 init();
170 Config cfg("Go"); 170 Config cfg("Go");
171 cfg.setGroup("Game"); 171 cfg.setGroup("Game");
172 twoplayer = cfg.readBoolEntry("TwoPlayer"); 172 twoplayer = cfg.readBoolEntry("TwoPlayer");
173 currentPlayer = (bVal)cfg.readNumEntry("CurrentPlayer",1); 173 currentPlayer = (bVal)cfg.readNumEntry("CurrentPlayer",1);
174 nPassed = cfg.readNumEntry("NPassed",0); 174 nPassed = cfg.readNumEntry("NPassed",0);
175 QString b = cfg.readEntry("Board"); 175 QString b = cfg.readEntry("Board");
176 if ( b.length() == 19*19 ) 176 if ( b.length() == 19*19 )
177 for (int i=0; i<19; i++) 177 for (int i=0; i<19; i++)
178 for (int j=0; j<19; j++) { 178 for (int j=0; j<19; j++) {
179 QChar ch = b[j+19*i]; 179 QChar ch = b[j+19*i];
180 if ( ch != '.' ) 180 if ( ch != '.' )
181 GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j ); 181 GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j );
182 } 182 }
183 lastX = cfg.readNumEntry("LastX"); 183 lastX = cfg.readNumEntry("LastX");
184 lastY = cfg.readNumEntry("LastY"); 184 lastY = cfg.readNumEntry("LastY");
185 extern int blackPrisoners, whitePrisoners; 185 extern int blackPrisoners, whitePrisoners;
186 blackPrisoners = cfg.readNumEntry("BlackPrisoners",0); 186 blackPrisoners = cfg.readNumEntry("BlackPrisoners",0);
187 whitePrisoners = cfg.readNumEntry("WhitePrisoners",0); 187 whitePrisoners = cfg.readNumEntry("WhitePrisoners",0);
188 reportPrisoners(blackPrisoners,whitePrisoners); 188 reportPrisoners(blackPrisoners,whitePrisoners);
189 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); 189 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone );
190} 190}
191 191
192void GoWidget::resizeEvent( QResizeEvent * ) 192void GoWidget::resizeEvent( QResizeEvent * )
193{ 193{
194 d = QMIN(width(),height())/19; 194 d = QMIN(width(),height())/19;
195 // int r = (d/2-1); 195 // int r = (d/2-1);
196 bx = (width() - 18*d)/2 ; 196 bx = (width() - 18*d)/2 ;
197 by = (height() - 18*d)/2 ; 197 by = (height() - 18*d)/2 ;
198 198
199 if ( d < 10 && !smallStones ) { 199 if ( d < 10 && !smallStones ) {
200 blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) ); 200 blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) );
201 whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) ); 201 whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) );
202 newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) ); 202 newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) );
203 203
204 smallStones = TRUE; 204 smallStones = TRUE;
205 } else if ( d >= 10 && smallStones ) { 205 } else if ( d >= 10 && smallStones ) {
206 blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); 206 blackStone = new QPixmap(Resource::loadPixmap( "Go-black" ));
207 whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); 207 whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" ));
208 newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); 208 newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" ));
209 smallStones = FALSE; 209 smallStones = FALSE;
210 } 210 }
211} 211}
212 212
213void GoWidget::init() 213void GoWidget::init()
214{ 214{
215 lastX = lastY = newX = newY = -1; 215 lastX = lastY = newX = newY = -1;
216 nPassed = 0; 216 nPassed = 0;
217 for ( int i = 0; i < 19; i++ ) 217 for ( int i = 0; i < 19; i++ )
218 for ( int j = 0; j < 19; j++ ) 218 for ( int j = 0; j < 19; j++ )
219 board[i][j]=-1; 219 board[i][j]=-1;
220 gameActive = TRUE; 220 gameActive = TRUE;
221 goRestart(current_handicap); 221 goRestart(current_handicap);
222 222
223 if ( twoplayer ) { 223 if ( twoplayer ) {
224 currentPlayer = BLACK; 224 currentPlayer = BLACK;
225 } else { 225 } else {
226 doComputerMove(); 226 doComputerMove();
227 currentPlayer = WHITE; 227 currentPlayer = WHITE;
228 } 228 }
229 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); 229 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone );
230} 230}
231 231
232void GoWidget::paintEvent( QPaintEvent *e ) 232void GoWidget::paintEvent( QPaintEvent *e )
233{ 233{
234 int i,j; 234 int i,j;
235 235
236 int r = whiteStone->width()/2; 236 int r = whiteStone->width()/2;
237 237
238 QPainter p(this); 238 QPainter p(this);
239 p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush ); 239 p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush );
240 240
241 int xMin = QMAX( x2board(e->rect().left()), 0 ); 241 int xMin = QMAX( x2board(e->rect().left()), 0 );
242 int xMax = QMIN( x2board(e->rect().right()), 18 ); 242 int xMax = QMIN( x2board(e->rect().right()), 18 );
243 int yMin = QMAX( y2board(e->rect().top()), 0 ); 243 int yMin = QMAX( y2board(e->rect().top()), 0 );
244 int yMax = QMIN( y2board(e->rect().bottom()), 18 ); 244 int yMax = QMIN( y2board(e->rect().bottom()), 18 );
245 245
246 QColor pine( 255, 186, 89 ); 246 QColor pine( 255, 186, 89 );
247 p.setPen( pine.dark() ); 247 p.setPen( pine.dark() );
248 248
249 for ( i = xMin; i < xMax+1 ; i ++ ) { 249 for ( i = xMin; i < xMax+1 ; i ++ ) {
250 p.drawLine( bx+i*d, by, bx+i*d, by+18*d ); 250 p.drawLine( bx+i*d, by, bx+i*d, by+18*d );
251 } 251 }
252 for ( j = yMin; j < yMax+1 ; j ++ ) { 252 for ( j = yMin; j < yMax+1 ; j ++ ) {
253 p.drawLine( bx, by+j*d, bx+18*d, by+j*d); 253 p.drawLine( bx, by+j*d, bx+18*d, by+j*d);
254 } 254 }
255 255
256 // dots are at (3,3), (3,9), (3,15) and so on 256 // dots are at (3,3), (3,9), (3,15) and so on
257 p.setBrush( black ); 257 p.setBrush( black );
258 for ( i = 3; i < xMax+1; i+=6 ) 258 for ( i = 3; i < xMax+1; i+=6 )
259 for ( j = 3; j < yMax+1; j+=6 ) 259 for ( j = 3; j < yMax+1; j+=6 )
260 p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 ); 260 p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 );
261 261
262 262
263 for ( i = xMin; i < xMax+1; i++ ) 263 for ( i = xMin; i < xMax+1; i++ )
264 for ( j = yMin; j < yMax+1; j++ ) { 264 for ( j = yMin; j < yMax+1; j++ ) {
265 if ( board[i][j] == WHITE || 265 if ( board[i][j] == WHITE ||
266 currentPlayer==WHITE && newX == i && newY == j ) 266 currentPlayer==WHITE && newX == i && newY == j )
267 p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone ); 267 p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone );
268 else if ( i == lastX && j == lastY ) 268 else if ( i == lastX && j == lastY )
269 p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone ); 269 p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone );
270 else if ( board[i][j] == BLACK || 270 else if ( board[i][j] == BLACK ||
271 currentPlayer==BLACK && newX == i && newY == j) 271 currentPlayer==BLACK && newX == i && newY == j)
272 p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone ); 272 p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone );
273 } 273 }
274} 274}
275 275
276void GoWidget::doMove( int x, int y ) 276void GoWidget::doMove( int x, int y )
277{ 277{
278 278
279 if ( !GoPlaceStone( currentPlayer, x, y ) ) { 279 if ( !GoPlaceStone( currentPlayer, x, y ) ) {
280 //printf( "Illegal move (%d,%d)\n", x, y ); 280 //printf( "Illegal move (%d,%d)\n", x, y );
281 return; 281 return;
282 } 282 }
283 //printf( "you do (%d,%d)\n", x, y ); 283 //printf( "you do (%d,%d)\n", x, y );
284 nPassed = 0; 284 nPassed = 0;
285 if ( twoplayer ) 285 if ( twoplayer )
286 currentPlayer = (currentPlayer==WHITE) ? BLACK : WHITE; 286 currentPlayer = (currentPlayer==WHITE) ? BLACK : WHITE;
287 else 287 else
288 doComputerMove(); 288 doComputerMove();
289 289
290 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); 290 emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone );
291 291
292} 292}
293 293
294void GoWidget::pass() 294void GoWidget::pass()
295{ 295{
296 if ( !gameActive ) 296 if ( !gameActive )
297 return; 297 return;
298 nPassed++; 298 nPassed++;
299 if ( nPassed >= 2 ) 299 if ( nPassed >= 2 )
300 endGame(); 300 endGame();
301 else if ( !twoplayer ) 301 else if ( !twoplayer )
302 doComputerMove(); 302 doComputerMove();
303} 303}
304 304
305void GoWidget::resign() 305void GoWidget::resign()
306{ 306{
307 if ( gameActive ) 307 if ( gameActive )
308 endGame(); 308 endGame();
309} 309}
310 310
311 311
312void GoWidget::newGame() 312void GoWidget::newGame()
313{ 313{
314 init(); 314 init();
315 update(); 315 update();
316} 316}
317 317
318 318
319void GoWidget::endGame() 319void GoWidget::endGame()
320{ 320{
321 gameActive = FALSE; 321 gameActive = FALSE;
322 322
323 int w,b; 323 int w,b;
324 CountUp( &w, &b); 324 CountUp( &w, &b);
325 QString s = tr("White %1, Black %2. ").arg(w).arg(b); 325 QString s = tr("White %1, Black %2. ").arg(w).arg(b);
326 if ( w > b ) 326 if ( w > b )
327 s += tr("White wins."); 327 s += tr("White wins.");
328 else if ( w < b ) 328 else if ( w < b )
329 s += tr("Black wins."); 329 s += tr("Black wins.");
330 else 330 else
331 s += tr("A draw."); 331 s += tr("A draw.");
332 emit showScore( s ); 332 emit showScore( s );
333} 333}
334 334
335void GoWidget::doComputerMove() 335void GoWidget::doComputerMove()
336{ 336{
337 int ox = lastX; 337 int ox = lastX;
338 int oy = lastY; 338 int oy = lastY;
339 lastX = lastY = -1; 339 lastX = lastY = -1;
340 emit showTurn( *blackStone ); 340 emit showTurn( *blackStone );
341 refresh( ox, oy); 341 refresh( ox, oy);
342 qApp->processEvents(); 342 qApp->processEvents();
343 short int x,y; 343 short int x,y;
344 if ( genMove( computer_color, &x, &y ) ) { 344 if ( genMove( computer_color, &x, &y ) ) {
345 lastX = x; 345 lastX = x;
346 lastY = y; 346 lastY = y;
347 //printf( "I do (%d,%d)\n", x, y ); 347 //printf( "I do (%d,%d)\n", x, y );
348 GoPlaceStone(computer_color,x,y); 348 GoPlaceStone(computer_color,x,y);
349 nPassed = 0; 349 nPassed = 0;
350 } else { 350 } else {
351 emit showScore( tr("I pass") ); 351 emit showScore( tr("I pass") );
352 nPassed++; 352 nPassed++;
353 if ( nPassed >= 2 ) 353 if ( nPassed >= 2 )
354 endGame(); 354 endGame();
355 } 355 }
356} 356}
357 357
358void GoWidget::mousePressEvent( QMouseEvent *me ) 358void GoWidget::mousePressEvent( QMouseEvent *me )
359{ 359{
360 if ( !gameActive ) 360 if ( !gameActive )
361 return; 361 return;
362 int x = x2board(me->x()); 362 int x = x2board(me->x());
363 int y = y2board(me->y()); 363 int y = y2board(me->y());
364 showStone(x,y,currentPlayer); 364 showStone(x,y,currentPlayer);
365} 365}
366 366
367void GoWidget::mouseMoveEvent( QMouseEvent *me ) 367void GoWidget::mouseMoveEvent( QMouseEvent *me )
368{ 368{
369 if ( !gameActive ) 369 if ( !gameActive )
370 return; 370 return;
371 int x = x2board(me->x()); 371 int x = x2board(me->x());
372 int y = y2board(me->y()); 372 int y = y2board(me->y());
373 if ( x != newX || y != newY ) 373 if ( x != newX || y != newY )
374 showStone(x,y,currentPlayer); 374 showStone(x,y,currentPlayer);
375} 375}
376 376
377void GoWidget::showStone( int x, int y, enum bVal c ) 377void GoWidget::showStone( int x, int y, enum bVal c )
378{ 378{
379 379
380 if ( newX > -1 ) { 380 if ( newX > -1 ) {
381 refresh( newX, newY ); 381 refresh( newX, newY );
382 newY = newX = -1; 382 newY = newX = -1;
383 } 383 }
384 if ( x < 0 || x > 18 || y < 0 || y > 18 ) { 384 if ( x < 0 || x > 18 || y < 0 || y > 18 ) {
385 newX = newY = -1; 385 newX = newY = -1;
386 return; 386 return;
387 } 387 }
388 if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { 388 if ( board[x][y] == -1 && !Suicide( c, x, y ) ) {
389 newX = x; 389 newX = x;
390 newY = y; 390 newY = y;
391 refresh(x,y); 391 refresh(x,y);
392 } 392 }
393 393
394} 394}
395 395
396void GoWidget::mouseReleaseEvent( QMouseEvent * ) 396void GoWidget::mouseReleaseEvent( QMouseEvent * )
397{ 397{
398 if ( gameActive && newX > -1 ) 398 if ( gameActive && newX > -1 )
399 doMove( newX, newY ); 399 doMove( newX, newY );
400 newX = newY = -1; 400 newX = newY = -1;
401} 401}
402 402
403void GoWidget::refresh( int x, int y ) 403void GoWidget::refresh( int x, int y )
404{ 404{
405 update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); 405 update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 );
406} 406}
407 407
408void GoWidget::removeStone(short x, short y) 408void GoWidget::removeStone(short x, short y)
409{ 409{
410 board[x][y]=-1; 410 board[x][y]=-1;
411 refresh( x, y ); 411 refresh( x, y );
412} 412}
413 413
414void GoWidget::placeStone (enum bVal c, short x, short y ) 414void GoWidget::placeStone (enum bVal c, short x, short y )
415{ 415{
416 board[x][y]=c; 416 board[x][y]=c;
417 refresh( x, y ); 417 refresh( x, y );
418} 418}
419 419
420void GoWidget::reportPrisoners( int blackcnt, int whitecnt ) 420void GoWidget::reportPrisoners( int blackcnt, int whitecnt )
421{ 421{
422 QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt); 422 QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt);
423 emit showScore( s ); 423 emit showScore( s );
424} 424}
425 425
426void GoWidget::setTwoplayer( bool b ) 426void GoWidget::setTwoplayer( bool b )
427{ 427{
428 twoplayer = b; 428 twoplayer = b;
429} 429}
430 430
431void GoWidget::setHandicap( int h ) 431void GoWidget::setHandicap( int h )
432{ 432{
433 current_handicap = h; 433 current_handicap = h;
434} 434}
435 435
436 436
437extern "C" { 437extern "C" {
438 438
439 voidremovestone(short x, short y) 439 voidremovestone(short x, short y)
440{ 440{
441 GoWidget::self->removeStone(x,y); 441 GoWidget::self->removeStone(x,y);
442} 442}
443 443
444 voidplacestone (enum bVal c, short x, short y ) 444 voidplacestone (enum bVal c, short x, short y )
445{ 445{
446 GoWidget::self->placeStone(c,x,y); 446 GoWidget::self->placeStone(c,x,y);
447} 447}
448 448
449 voidintrMoveReport(enum bVal c ,char *coord ,char *reason ) 449 voidintrMoveReport(enum bVal c ,char *coord ,char *reason )
450{ 450{
451 qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason ); 451 qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason );
452} 452}
453 453
454 voidintrPrisonerReport( short blackcnt, short whitecnt ) 454 voidintrPrisonerReport( short blackcnt, short whitecnt )
455{ 455{
456 GoWidget::self->reportPrisoners(blackcnt,whitecnt); 456 GoWidget::self->reportPrisoners(blackcnt,whitecnt);
457} 457}
458 458
459} 459}
460 460
diff --git a/noncore/games/go/main.cpp b/noncore/games/go/main.cpp
index 46817d1..f6bb813 100644
--- a/noncore/games/go/main.cpp
+++ b/noncore/games/go/main.cpp
@@ -1,27 +1,28 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "gowidget.h" 21#include "gowidget.h"
22 22
23 23
24#include <opie2/oapplicationfactory.h> 24#include <opie2/oapplicationfactory.h>
25 25
26using namespace Opie::Core;
26OPIE_EXPORT_APP( OApplicationFactory<GoMainWidget> ) 27OPIE_EXPORT_APP( OApplicationFactory<GoMainWidget> )
27 28
diff --git a/noncore/games/kcheckers/main.cpp b/noncore/games/kcheckers/main.cpp
index 79b5ac7..8c708e2 100644
--- a/noncore/games/kcheckers/main.cpp
+++ b/noncore/games/kcheckers/main.cpp
@@ -1,9 +1,10 @@
1 1
2 2
3#include "kcheckers.h" 3#include "kcheckers.h"
4 4
5#include <opie2/oapplicationfactory.h> 5#include <opie2/oapplicationfactory.h>
6 6
7using namespace Opie::Core;
7OPIE_EXPORT_APP( OApplicationFactory<KCheckers> ) 8OPIE_EXPORT_APP( OApplicationFactory<KCheckers> )
8 9
9 10
diff --git a/noncore/games/minesweep/main.cpp b/noncore/games/minesweep/main.cpp
index f3070f5..629afbf 100644
--- a/noncore/games/minesweep/main.cpp
+++ b/noncore/games/minesweep/main.cpp
@@ -1,26 +1,27 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "minesweep.h" 21#include "minesweep.h"
22 22
23#include <opie2/oapplicationfactory.h> 23#include <opie2/oapplicationfactory.h>
24 24
25using namespace Opie::Core;
25OPIE_EXPORT_APP( OApplicationFactory<MineSweep> ) 26OPIE_EXPORT_APP( OApplicationFactory<MineSweep> )
26 27
diff --git a/noncore/games/parashoot/main.cpp b/noncore/games/parashoot/main.cpp
index 81d513d..da21c25 100644
--- a/noncore/games/parashoot/main.cpp
+++ b/noncore/games/parashoot/main.cpp
@@ -1,26 +1,27 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "interface.h" 21#include "interface.h"
22 22
23#include <opie2/oapplicationfactory.h> 23#include <opie2/oapplicationfactory.h>
24 24
25using namespace Opie::Core;
25OPIE_EXPORT_APP( OApplicationFactory<ParaShoot> ) 26OPIE_EXPORT_APP( OApplicationFactory<ParaShoot> )
26 27
diff --git a/noncore/games/qasteroids/main.cpp b/noncore/games/qasteroids/main.cpp
index 33e4729..6ddb238 100644
--- a/noncore/games/qasteroids/main.cpp
+++ b/noncore/games/qasteroids/main.cpp
@@ -1,26 +1,27 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "toplevel.h" 21#include "toplevel.h"
22 22
23#include <opie2/oapplicationfactory.h> 23#include <opie2/oapplicationfactory.h>
24 24
25 25
26using namespace Opie::Core;
26OPIE_EXPORT_APP( OApplicationFactory<KAstTopLevel> ) 27OPIE_EXPORT_APP( OApplicationFactory<KAstTopLevel> )
diff --git a/noncore/games/snake/interface.cpp b/noncore/games/snake/interface.cpp
index b5fb5bf..9d9550a 100644
--- a/noncore/games/snake/interface.cpp
+++ b/noncore/games/snake/interface.cpp
@@ -1,219 +1,219 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "interface.h" 21#include "interface.h"
22 22
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24 24
25#include <qpe/qpetoolbar.h> 25#include <qtoolbar.h>
26#include <qtoolbutton.h> 26#include <qtoolbutton.h>
27 27
28SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) : 28SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) :
29 QMainWindow(parent,name,f), 29 QMainWindow(parent,name,f),
30 canvas(232, 258) 30 canvas(232, 258)
31{ 31{
32 setCaption( tr("Snake") ); 32 setCaption( tr("Snake") );
33 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); 33 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff );
34 QPixmap bg = Resource::loadPixmap("snake/grass"); 34 QPixmap bg = Resource::loadPixmap("snake/grass");
35 canvas.setBackgroundPixmap(bg); 35 canvas.setBackgroundPixmap(bg);
36 canvas.setUpdatePeriod(100); 36 canvas.setUpdatePeriod(100);
37 snake = 0; 37 snake = 0;
38 38
39 cv = new QCanvasView(&canvas, this); 39 cv = new QCanvasView(&canvas, this);
40 40
41 pauseTimer = new QTimer(this); 41 pauseTimer = new QTimer(this);
42 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); 42 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) );
43 43
44 setToolBarsMovable( FALSE ); 44 setToolBarsMovable( FALSE );
45 45
46 QToolBar* toolbar = new QToolBar( this); 46 QToolBar* toolbar = new QToolBar( this);
47 toolbar->setHorizontalStretchable( TRUE ); 47 toolbar->setHorizontalStretchable( TRUE );
48 48
49 QPixmap newicon = Resource::loadPixmap("ksnake"); 49 QPixmap newicon = Resource::loadPixmap("ksnake");
50 setIcon(newicon); 50 setIcon(newicon);
51 (void)new QToolButton(newicon, tr("New Game"), 0, 51 (void)new QToolButton(newicon, tr("New Game"), 0,
52 this, SLOT(newGame()), toolbar, "New Game"); 52 this, SLOT(newGame()), toolbar, "New Game");
53 53
54 scorelabel = new QLabel(toolbar); 54 scorelabel = new QLabel(toolbar);
55 showScore(0); 55 showScore(0);
56 scorelabel->setBackgroundMode( PaletteButton ); 56 scorelabel->setBackgroundMode( PaletteButton );
57 scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); 57 scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs );
58 toolbar->setStretchableWidget( scorelabel ); 58 toolbar->setStretchableWidget( scorelabel );
59 59
60 setFocusPolicy(StrongFocus); 60 setFocusPolicy(StrongFocus);
61 61
62 setCentralWidget(cv); 62 setCentralWidget(cv);
63 63
64 QTimer::singleShot( 16, this, SLOT(welcomescreen()) ); 64 QTimer::singleShot( 16, this, SLOT(welcomescreen()) );
65 gamestopped = true; 65 gamestopped = true;
66 waitover = true; 66 waitover = true;
67} 67}
68 68
69SnakeGame::~SnakeGame() 69SnakeGame::~SnakeGame()
70{ 70{
71 delete snake; 71 delete snake;
72} 72}
73 73
74void SnakeGame::resizeEvent(QResizeEvent *) 74void SnakeGame::resizeEvent(QResizeEvent *)
75{ 75{
76 QSize s = centralWidget()->size(); 76 QSize s = centralWidget()->size();
77 int fw = style().defaultFrameWidth(); 77 int fw = style().defaultFrameWidth();
78 canvas.resize( s.width() - fw - 2, s.height() - fw - 2); 78 canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
79} 79}
80 80
81void SnakeGame::welcomescreen() 81void SnakeGame::welcomescreen()
82{ 82{
83 QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); 83 QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas);
84 title->setColor(yellow); 84 title->setColor(yellow);
85 title->setFont( QFont("times", 18, QFont::Bold) ); 85 title->setFont( QFont("times", 18, QFont::Bold) );
86 int w = title->boundingRect().width(); 86 int w = title->boundingRect().width();
87 title->move(canvas.width()/2 -w/2, canvas.height()/2-110); 87 title->move(canvas.width()/2 -w/2, canvas.height()/2-110);
88 title->show(); 88 title->show();
89 QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); 89 QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title"));
90 QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); 90 QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas);
91 titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); 91 titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85);
92 titlepic->show(); 92 titlepic->show();
93 QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" 93 QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n"
94 "snake to eat the mouse. You must not\n" 94 "snake to eat the mouse. You must not\n"
95 "crash into the walls, edges or its tail."), 95 "crash into the walls, edges or its tail."),
96 &canvas); 96 &canvas);
97 w = instr->boundingRect().width(); 97 w = instr->boundingRect().width();
98 instr->move(canvas.width()/2-w/2, canvas.height()/2-20); 98 instr->move(canvas.width()/2-w/2, canvas.height()/2-20);
99 instr->setColor(white); 99 instr->setColor(white);
100 instr->show(); 100 instr->show();
101 QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas); 101 QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas);
102 w = cont->boundingRect().width(); 102 w = cont->boundingRect().width();
103 cont->move(canvas.width()/2-w/2, canvas.height()-20); 103 cont->move(canvas.width()/2-w/2, canvas.height()-20);
104 cont->setColor(yellow); 104 cont->setColor(yellow);
105 cont->show(); 105 cont->show();
106 106
107} 107}
108 108
109void SnakeGame::newGame() 109void SnakeGame::newGame()
110{ 110{
111 clear(); 111 clear();
112 snake = new Snake(&canvas); 112 snake = new Snake(&canvas);
113 connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) ); 113 connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) );
114 connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) ); 114 connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) );
115 connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) ); 115 connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) );
116 connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) ); 116 connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) );
117 last = 0; 117 last = 0;
118 targetamount = 1; 118 targetamount = 1;
119 notargets = 1; 119 notargets = 1;
120 level = 1; 120 level = 1;
121 stage = 1; 121 stage = 1;
122 showScore(0); 122 showScore(0);
123 gamestopped = false; 123 gamestopped = false;
124 waitover = true; 124 waitover = true;
125 int y = canvas.height()-50; 125 int y = canvas.height()-50;
126 (void)new Obstacle(&canvas, 32); 126 (void)new Obstacle(&canvas, 32);
127 (void)new Obstacle(&canvas, y); 127 (void)new Obstacle(&canvas, y);
128 createTargets(); 128 createTargets();
129} 129}
130 130
131 131
132void SnakeGame::showScore(int score) 132void SnakeGame::showScore(int score)
133{ 133{
134 scorelabel->setText(tr(" Score : %1 ").arg(score) ); 134 scorelabel->setText(tr(" Score : %1 ").arg(score) );
135} 135}
136 136
137 137
138void SnakeGame::scoreInc() 138void SnakeGame::scoreInc()
139{ 139{
140 showScore( snake->getScore() ); 140 showScore( snake->getScore() );
141} 141}
142 142
143void SnakeGame::levelUp() 143void SnakeGame::levelUp()
144{ 144{
145 notargets--; 145 notargets--;
146 if (notargets == 0) { 146 if (notargets == 0) {
147 stage++; 147 stage++;
148 if (stage == 3) { 148 if (stage == 3) {
149 level++; 149 level++;
150 emit moveFaster(); 150 emit moveFaster();
151 targetamount++; 151 targetamount++;
152 stage = 0; 152 stage = 0;
153 } 153 }
154 createTargets(); 154 createTargets();
155 } 155 }
156} 156}
157 157
158void SnakeGame::createTargets() 158void SnakeGame::createTargets()
159{ 159{
160 for (int i = 0; i < targetamount; i++) 160 for (int i = 0; i < targetamount; i++)
161 (void)new Target(&canvas); 161 (void)new Target(&canvas);
162 notargets = targetamount; 162 notargets = targetamount;
163} 163}
164 164
165void SnakeGame::clear() 165void SnakeGame::clear()
166{ 166{
167 delete snake; 167 delete snake;
168 snake = 0; 168 snake = 0;
169 QCanvasItemList l = canvas.allItems(); 169 QCanvasItemList l = canvas.allItems();
170 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { 170 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
171 delete *it; 171 delete *it;
172 } 172 }
173} 173}
174 174
175void SnakeGame::gameOver() 175void SnakeGame::gameOver()
176{ 176{
177 int score = snake->getScore(); 177 int score = snake->getScore();
178 QString scoreoutput=""; 178 QString scoreoutput="";
179 scoreoutput.setNum(score); 179 scoreoutput.setNum(score);
180 QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); 180 QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas);
181 181
182 gameover->setZ(100); 182 gameover->setZ(100);
183 gameover->setColor(yellow); 183 gameover->setColor(yellow);
184 gameover->setFont( QFont("times", 18, QFont::Bold) ); 184 gameover->setFont( QFont("times", 18, QFont::Bold) );
185 int w = gameover->boundingRect().width(); 185 int w = gameover->boundingRect().width();
186 gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50); 186 gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50);
187 gameover->show(); 187 gameover->show();
188 gamestopped = true; 188 gamestopped = true;
189 waitover = false; 189 waitover = false;
190 pauseTimer->start(1500); 190 pauseTimer->start(1500);
191} 191}
192 192
193void SnakeGame::wait() 193void SnakeGame::wait()
194{ 194{
195 waitover = true; 195 waitover = true;
196 pauseTimer->stop(); 196 pauseTimer->stop();
197 QCanvasText* cont = new QCanvasText(tr("Press any key to begin a new game."), 197 QCanvasText* cont = new QCanvasText(tr("Press any key to begin a new game."),
198 &canvas); 198 &canvas);
199 cont->setZ(100); 199 cont->setZ(100);
200 cont->setColor(white); 200 cont->setColor(white);
201 int w = cont->boundingRect().width(); 201 int w = cont->boundingRect().width();
202 cont->move(canvas.width()/2 -w/2, canvas.height()/2); 202 cont->move(canvas.width()/2 -w/2, canvas.height()/2);
203 cont->show(); 203 cont->show();
204} 204}
205 205
206void SnakeGame::keyPressEvent(QKeyEvent* event) 206void SnakeGame::keyPressEvent(QKeyEvent* event)
207{ 207{
208 if (gamestopped) { 208 if (gamestopped) {
209 if (waitover) 209 if (waitover)
210 newGame(); 210 newGame();
211 else 211 else
212 return; 212 return;
213 } 213 }
214 else { 214 else {
215 int newkey = event->key(); 215 int newkey = event->key();
216 snake->go(newkey); 216 snake->go(newkey);
217 } 217 }
218} 218}
219 219
diff --git a/noncore/games/snake/main.cpp b/noncore/games/snake/main.cpp
index 44f742f..81eb9ee 100644
--- a/noncore/games/snake/main.cpp
+++ b/noncore/games/snake/main.cpp
@@ -1,28 +1,29 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "interface.h" 21#include "interface.h"
22 22
23#include <opie2/oapplicationfactory.h> 23#include <opie2/oapplicationfactory.h>
24 24
25 25
26using namespace Opie::Core;
26OPIE_EXPORT_APP( OApplicationFactory<SnakeGame> ) 27OPIE_EXPORT_APP( OApplicationFactory<SnakeGame> )
27 28
28 29
diff --git a/noncore/games/solitaire/main.cpp b/noncore/games/solitaire/main.cpp
index d4f6673..c8d4040 100644
--- a/noncore/games/solitaire/main.cpp
+++ b/noncore/games/solitaire/main.cpp
@@ -1,25 +1,26 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "canvascardwindow.h" 21#include "canvascardwindow.h"
22 22
23#include <opie2/oapplicationfactory.h> 23#include <opie2/oapplicationfactory.h>
24 24
25using namespace Opie::Core;
25OPIE_EXPORT_APP( OApplicationFactory<CanvasCardWindow> ) \ No newline at end of file 26OPIE_EXPORT_APP( OApplicationFactory<CanvasCardWindow> ) \ No newline at end of file
diff --git a/noncore/games/tetrix/main.cpp b/noncore/games/tetrix/main.cpp
index 147d13d..6194bbf 100644
--- a/noncore/games/tetrix/main.cpp
+++ b/noncore/games/tetrix/main.cpp
@@ -1,27 +1,28 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qtetrix.h" 21#include "qtetrix.h"
22 22
23 23
24#include <opie2/oapplicationfactory.h> 24#include <opie2/oapplicationfactory.h>
25 25
26using namespace Opie::Core;
26OPIE_EXPORT_APP( OApplicationFactory<QTetrix> ) 27OPIE_EXPORT_APP( OApplicationFactory<QTetrix> )
27 28
diff --git a/noncore/games/tictac/main.cpp b/noncore/games/tictac/main.cpp
index b8193f7..f3df375 100644
--- a/noncore/games/tictac/main.cpp
+++ b/noncore/games/tictac/main.cpp
@@ -1,13 +1,14 @@
1/**************************************************************************** 1/****************************************************************************
2** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 2** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of an example program for Qt. This example 4** This file is part of an example program for Qt. This example
5** program may be used, distributed and modified without limitation. 5** program may be used, distributed and modified without limitation.
6** 6**
7*****************************************************************************/ 7*****************************************************************************/
8 8
9#include "tictac.h" 9#include "tictac.h"
10 10
11#include <opie2/oapplicationfactory.h> 11#include <opie2/oapplicationfactory.h>
12 12
13using namespace Opie::Core;
13OPIE_EXPORT_APP( OApplicationFactory<TicTacToe> ) 14OPIE_EXPORT_APP( OApplicationFactory<TicTacToe> )
diff --git a/noncore/games/wordgame/main.cpp b/noncore/games/wordgame/main.cpp
index 7fd5f50..c388775 100644
--- a/noncore/games/wordgame/main.cpp
+++ b/noncore/games/wordgame/main.cpp
@@ -1,27 +1,28 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "wordgame.h" 21#include "wordgame.h"
22 22
23#include <opie2/oapplicationfactory.h> 23#include <opie2/oapplicationfactory.h>
24 24
25 25
26using namespace Opie::Core;
26OPIE_EXPORT_APP( OApplicationFactory<WordGame> ) 27OPIE_EXPORT_APP( OApplicationFactory<WordGame> )
27 28
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp
index 43a54f8..a80bd35 100644
--- a/noncore/games/wordgame/wordgame.cpp
+++ b/noncore/games/wordgame/wordgame.cpp
@@ -1,1510 +1,1510 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21 21
22#include "wordgame.h" 22#include "wordgame.h"
23 23
24#include <qpe/global.h> 24#include <qpe/global.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27 27
28#include <qapplication.h> 28#include <qapplication.h>
29#include <qmessagebox.h> 29#include <qmessagebox.h>
30#include <qcombobox.h> 30#include <qcombobox.h>
31#include <qdir.h> 31#include <qdir.h>
32#include <qlineedit.h> 32#include <qlineedit.h>
33#include <qpushbutton.h> 33#include <qpushbutton.h>
34#include <qtextstream.h> 34#include <qtextstream.h>
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qpe/qpetoolbar.h> 36#include <qtoolbar.h>
37#include <qtoolbutton.h> 37#include <qtoolbutton.h>
38#include <qvbox.h> 38#include <qvbox.h>
39#include <qwidgetstack.h> 39#include <qwidgetstack.h>
40#include <qlayout.h> 40#include <qlayout.h>
41 41
42#include <stdlib.h> 42#include <stdlib.h>
43#include <unistd.h> 43#include <unistd.h>
44#include <pwd.h> 44#include <pwd.h>
45#include <sys/types.h> 45#include <sys/types.h>
46 46
47enum RuleEffects { 47enum RuleEffects {
48 Multiplier=15, 48 Multiplier=15,
49 MultiplyAll=64, 49 MultiplyAll=64,
50 Start=128 50 Start=128
51}; 51};
52 52
53static int tile_smallw = 16; 53static int tile_smallw = 16;
54static int tile_smallh = 16; 54static int tile_smallh = 16;
55static int tile_bigw = 22; 55static int tile_bigw = 22;
56static int tile_bigh = 22; 56static int tile_bigh = 22;
57static int tile_stweak = -2; 57static int tile_stweak = -2;
58static int tile_btweak = -1; 58static int tile_btweak = -1;
59 59
60static const int rack_tiles=7; 60static const int rack_tiles=7;
61 61
62const char* sampleWGR= 62const char* sampleWGR=
63 "wordgame_shapes\n" 63 "wordgame_shapes\n"
64 "15 15\n" 64 "15 15\n"
65 "400001040100004\n" 65 "400001040100004\n"
66 "030000000000030\n" 66 "030000000000030\n"
67 "002002000200200\n" 67 "002002000200200\n"
68 "000300020003000\n" 68 "000300020003000\n"
69 "000020000020000\n" 69 "000020000020000\n"
70 "102001000100201\n" 70 "102001000100201\n"
71 "000000202000000\n" 71 "000000202000000\n"
72 "400200050002004\n" 72 "400200050002004\n"
73 "000000202000000\n" 73 "000000202000000\n"
74 "102001000100201\n" 74 "102001000100201\n"
75 "000020000020000\n" 75 "000020000020000\n"
76 "000300020003000\n" 76 "000300020003000\n"
77 "002002000200200\n" 77 "002002000200200\n"
78 "030000000000030\n" 78 "030000000000030\n"
79 "400001040100004\n" 79 "400001040100004\n"
80 "1 2 3 66 67 194 100 0\n" 80 "1 2 3 66 67 194 100 0\n"
81 "1 j 8\n" 81 "1 j 8\n"
82 "1 q 7\n" 82 "1 q 7\n"
83 "1 x 6\n" 83 "1 x 6\n"
84 "1 z 6\n" 84 "1 z 6\n"
85 "1 w 4\n" 85 "1 w 4\n"
86 "1 k 4\n" 86 "1 k 4\n"
87 "1 v 3\n" 87 "1 v 3\n"
88 "1 f 3\n" 88 "1 f 3\n"
89 "2 y 3\n" 89 "2 y 3\n"
90 "2 h 2\n" 90 "2 h 2\n"
91 "2 b 2\n" 91 "2 b 2\n"
92 "2 m 2\n" 92 "2 m 2\n"
93 "3 p 2\n" 93 "3 p 2\n"
94 "3 g 2\n" 94 "3 g 2\n"
95 "3 u 2\n" 95 "3 u 2\n"
96 "4 d 2\n" 96 "4 d 2\n"
97 "4 c 2\n" 97 "4 c 2\n"
98 "5 l 1\n" 98 "5 l 1\n"
99 "5 o 1\n" 99 "5 o 1\n"
100 "7 t 1\n" 100 "7 t 1\n"
101 "7 n 1\n" 101 "7 n 1\n"
102 "7 a 1\n" 102 "7 a 1\n"
103 "7 r 1\n" 103 "7 r 1\n"
104 "8 s 1\n" 104 "8 s 1\n"
105 "8 i 1\n" 105 "8 i 1\n"
106 "11 e 1\n" 106 "11 e 1\n"
107 "0\n"; 107 "0\n";
108 108
109WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : 109WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) :
110 QMainWindow(parent, name, fl) 110 QMainWindow(parent, name, fl)
111{ 111{
112 if ( qApp->desktop()->width() < 240 ) { 112 if ( qApp->desktop()->width() < 240 ) {
113 tile_smallw = 10; 113 tile_smallw = 10;
114 tile_smallh = 10; 114 tile_smallh = 10;
115 tile_bigw = 16; 115 tile_bigw = 16;
116 tile_bigh = 16; 116 tile_bigh = 16;
117 tile_stweak = 0; 117 tile_stweak = 0;
118 tile_btweak = 0; 118 tile_btweak = 0;
119 } 119 }
120 120
121 setIcon( Resource::loadPixmap( "wordgame/WordGame.png" ) ); 121 setIcon( Resource::loadPixmap( "wordgame/WordGame.png" ) );
122 setCaption( tr("Word Game") ); 122 setCaption( tr("Word Game") );
123 123
124 setToolBarsMovable( FALSE ); 124 setToolBarsMovable( FALSE );
125 vbox = new QVBox(this); 125 vbox = new QVBox(this);
126 126
127 setCentralWidget(vbox); 127 setCentralWidget(vbox);
128 toolbar = new QToolBar(this); 128 toolbar = new QToolBar(this);
129 addToolBar(toolbar, Bottom); 129 addToolBar(toolbar, Bottom);
130 reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); 130 reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar);
131 done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); 131 done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar);
132 scoreinfo = new ScoreInfo(toolbar); 132 scoreinfo = new ScoreInfo(toolbar);
133 scoreinfo->setFont(QFont("Helvetica",10)); 133 scoreinfo->setFont(QFont("Helvetica",10));
134 new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); 134 new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar);
135 toolbar->setStretchableWidget(scoreinfo); 135 toolbar->setStretchableWidget(scoreinfo);
136 136
137 cpu = 0; 137 cpu = 0;
138 board = 0; 138 board = 0;
139 bag = 0; 139 bag = 0;
140 racks = 0; 140 racks = 0;
141 141
142 aiheart = new QTimer(this); 142 aiheart = new QTimer(this);
143 connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); 143 connect(aiheart, SIGNAL(timeout()), this, SLOT(think()));
144 144
145 readConfig(); 145 readConfig();
146} 146}
147 147
148WordGame::~WordGame() 148WordGame::~WordGame()
149{ 149{
150 writeConfig(); 150 writeConfig();
151} 151}
152 152
153void WordGame::writeConfig() 153void WordGame::writeConfig()
154{ 154{
155 Config cfg("WordGame"); 155 Config cfg("WordGame");
156 cfg.setGroup("Game"); 156 cfg.setGroup("Game");
157 cfg.writeEntry("NameList",namelist,';'); 157 cfg.writeEntry("NameList",namelist,';');
158 cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); 158 cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1);
159 if ( !gameover ) { 159 if ( !gameover ) {
160 cfg.writeEntry("Rules",rules); 160 cfg.writeEntry("Rules",rules);
161 bag->writeConfig(cfg); 161 bag->writeConfig(cfg);
162 board->writeConfig(cfg); 162 board->writeConfig(cfg);
163 scoreinfo->writeConfig(cfg); 163 scoreinfo->writeConfig(cfg);
164 } 164 }
165 for (int p=0; p<nplayers; p++) { 165 for (int p=0; p<nplayers; p++) {
166 cfg.setGroup("Player"+QString::number(p+1)); 166 cfg.setGroup("Player"+QString::number(p+1));
167 if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); 167 if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg);
168 } 168 }
169} 169}
170 170
171void WordGame::readConfig() 171void WordGame::readConfig()
172{ 172{
173 Config cfg("WordGame"); 173 Config cfg("WordGame");
174 cfg.setGroup("Game"); 174 cfg.setGroup("Game");
175 int currentplayer = cfg.readNumEntry("CurrentPlayer",0); 175 int currentplayer = cfg.readNumEntry("CurrentPlayer",0);
176 QStringList pnames = cfg.readListEntry("NameList",';'); 176 QStringList pnames = cfg.readListEntry("NameList",';');
177 if ( currentplayer ) { 177 if ( currentplayer ) {
178 gameover = FALSE; 178 gameover = FALSE;
179 rules = cfg.readEntry("Rules"); 179 rules = cfg.readEntry("Rules");
180 if ( rules.find("x-wordgamerules") >= 0 ) { 180 if ( rules.find("x-wordgamerules") >= 0 ) {
181 // rules files moved 181 // rules files moved
182 rules = "Sample.rules"; 182 rules = "Sample.rules";
183 } 183 }
184 if ( loadRules(rules) ) { 184 if ( loadRules(rules) ) {
185 startGame(pnames); 185 startGame(pnames);
186 bag->readConfig(cfg); 186 bag->readConfig(cfg);
187 board->readConfig(cfg); 187 board->readConfig(cfg);
188 scoreinfo->readConfig(cfg); 188 scoreinfo->readConfig(cfg);
189 for (int p=0; p<nplayers; p++) { 189 for (int p=0; p<nplayers; p++) {
190 cfg.setGroup("Player"+QString::number(p+1)); 190 cfg.setGroup("Player"+QString::number(p+1));
191 rack(p)->readConfig(cfg); 191 rack(p)->readConfig(cfg);
192 } 192 }
193 player=currentplayer-1; 193 player=currentplayer-1;
194 readyRack(player); 194 readyRack(player);
195 return; 195 return;
196 } 196 }
197 } 197 }
198 // fall-back 198 // fall-back
199 openGameSelector(pnames); 199 openGameSelector(pnames);
200} 200}
201 201
202void WordGame::openGameSelector(const QStringList& initnames) 202void WordGame::openGameSelector(const QStringList& initnames)
203{ 203{
204 toolbar->hide(); 204 toolbar->hide();
205 gameover = FALSE; 205 gameover = FALSE;
206 206
207 delete board; 207 delete board;
208 board = 0; 208 board = 0;
209 delete racks; 209 delete racks;
210 racks = 0; 210 racks = 0;
211 211
212 delete cpu; 212 delete cpu;
213 cpu = 0; 213 cpu = 0;
214 214
215 newgame = new NewGame(vbox); 215 newgame = new NewGame(vbox);
216 216
217 //Rules rules(this); 217 //Rules rules(this);
218 //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules())); 218 //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules()));
219 //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets())); 219 //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets()));
220 struct passwd* n = getpwuid(getuid()); 220 struct passwd* n = getpwuid(getuid());
221 QString playername = n ? n->pw_name : ""; 221 QString playername = n ? n->pw_name : "";
222 if ( playername.isEmpty() ) { 222 if ( playername.isEmpty() ) {
223 playername = "Player"; 223 playername = "Player";
224 } 224 }
225 newgame->player0->changeItem(playername,0); 225 newgame->player0->changeItem(playername,0);
226 newgame->player1->setCurrentItem(1); 226 newgame->player1->setCurrentItem(1);
227 newgame->updateRuleSets(); 227 newgame->updateRuleSets();
228 newgame->show(); 228 newgame->show();
229 229
230 connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame())); 230 connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame()));
231} 231}
232 232
233void WordGame::startGame() 233void WordGame::startGame()
234{ 234{
235 rules = newgame->ruleslist[newgame->rules->currentItem()]; 235 rules = newgame->ruleslist[newgame->rules->currentItem()];
236 if ( loadRules(rules) ) { 236 if ( loadRules(rules) ) {
237 QStringList names; 237 QStringList names;
238 names.append(newgame->player0->currentText()); 238 names.append(newgame->player0->currentText());
239 names.append(newgame->player1->currentText()); 239 names.append(newgame->player1->currentText());
240 names.append(newgame->player2->currentText()); 240 names.append(newgame->player2->currentText());
241 names.append(newgame->player3->currentText()); 241 names.append(newgame->player3->currentText());
242 names.append(newgame->player4->currentText()); 242 names.append(newgame->player4->currentText());
243 names.append(newgame->player5->currentText()); 243 names.append(newgame->player5->currentText());
244 delete newgame; 244 delete newgame;
245 startGame(names); 245 startGame(names);
246 } else { 246 } else {
247 // error... 247 // error...
248 delete newgame; 248 delete newgame;
249 close(); 249 close();
250 } 250 }
251} 251}
252 252
253void WordGame::startGame(const QStringList& playerlist) 253void WordGame::startGame(const QStringList& playerlist)
254{ 254{
255 toolbar->show(); 255 toolbar->show();
256 racks = new QWidgetStack(vbox); 256 racks = new QWidgetStack(vbox);
257 racks->setFixedHeight(TileItem::bigHeight()+2); 257 racks->setFixedHeight(TileItem::bigHeight()+2);
258 namelist.clear(); 258 namelist.clear();
259 nplayers=0; 259 nplayers=0;
260 for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) 260 for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it)
261 addPlayer(*it); 261 addPlayer(*it);
262 scoreinfo->init(namelist); 262 scoreinfo->init(namelist);
263 263
264 if ( nplayers ) { 264 if ( nplayers ) {
265 player=0; 265 player=0;
266 readyRack(player); 266 readyRack(player);
267 } 267 }
268 268
269 board->show(); 269 board->show();
270 racks->show(); 270 racks->show();
271} 271}
272 272
273bool WordGame::loadRules(const QString &name) 273bool WordGame::loadRules(const QString &name)
274{ 274{
275 QString filename = Global::applicationFileName( "wordgame", name ); 275 QString filename = Global::applicationFileName( "wordgame", name );
276 QFile file( filename ); 276 QFile file( filename );
277 if ( !file.open( IO_ReadOnly ) ) 277 if ( !file.open( IO_ReadOnly ) )
278 return FALSE; 278 return FALSE;
279 279
280 QTextStream ts( &file ); 280 QTextStream ts( &file );
281 281
282 QString title = name; 282 QString title = name;
283 title.truncate( title.length() - 6 ); 283 title.truncate( title.length() - 6 );
284 //setCaption( title ); 284 //setCaption( title );
285 285
286 QString shapepixmap; 286 QString shapepixmap;
287 ts >> shapepixmap; 287 ts >> shapepixmap;
288 int htiles,vtiles; 288 int htiles,vtiles;
289 ts >> htiles >> vtiles; 289 ts >> htiles >> vtiles;
290 290
291 if ( htiles < 3 || vtiles < 3 ) 291 if ( htiles < 3 || vtiles < 3 )
292 return FALSE; 292 return FALSE;
293 293
294 QString rule_shapes; 294 QString rule_shapes;
295 for (int i=0; i<vtiles; i++) { 295 for (int i=0; i<vtiles; i++) {
296 QString line; 296 QString line;
297 ts >> line; 297 ts >> line;
298 rule_shapes += line; 298 rule_shapes += line;
299 } 299 }
300 static int rule_effects[12]; 300 static int rule_effects[12];
301 int re=0,e; 301 int re=0,e;
302 ts >> e; 302 ts >> e;
303 while ( e && re < 10 ) { 303 while ( e && re < 10 ) {
304 rule_effects[re] = e; 304 rule_effects[re] = e;
305 if ( re++ < 10 ) ts >> e; 305 if ( re++ < 10 ) ts >> e;
306 } 306 }
307 307
308 QImage shim = Resource::loadImage("wordgame/wordgame_shapes"); 308 QImage shim = Resource::loadImage("wordgame/wordgame_shapes");
309 shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); 309 shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight());
310 QPixmap bgshapes; 310 QPixmap bgshapes;
311 bgshapes.convertFromImage(shim); 311 bgshapes.convertFromImage(shim);
312 312
313 rule_effects[re++] = 100; // default bonus 313 rule_effects[re++] = 100; // default bonus
314 board = new Board(bgshapes, htiles, vtiles, vbox); 314 board = new Board(bgshapes, htiles, vtiles, vbox);
315 board->setRules(rule_shapes, rule_effects); 315 board->setRules(rule_shapes, rule_effects);
316 connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); 316 connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int)));
317 317
318 bag = new Bag; 318 bag = new Bag;
319 319
320 int count; 320 int count;
321 ts >> count; 321 ts >> count;
322 while ( count ) { 322 while ( count ) {
323 QString text; 323 QString text;
324 int value; 324 int value;
325 ts >> text >> value; 325 ts >> text >> value;
326 if ( text == "_" ) 326 if ( text == "_" )
327 text = ""; 327 text = "";
328 328
329 Tile t(text, value); 329 Tile t(text, value);
330 for (int n=count; n--; ) 330 for (int n=count; n--; )
331 bag->add(t); 331 bag->add(t);
332 332
333 ts >> count; 333 ts >> count;
334 } 334 }
335 335
336 return TRUE; 336 return TRUE;
337} 337}
338 338
339 339
340NewGame::NewGame(QWidget* parent) : 340NewGame::NewGame(QWidget* parent) :
341 NewGameBase(parent) 341 NewGameBase(parent)
342{ 342{
343} 343}
344 344
345void NewGame::updateRuleSets() 345void NewGame::updateRuleSets()
346{ 346{
347 rules->clear(); 347 rules->clear();
348 348
349 QString rulesDir = Global::applicationFileName( "wordgame", "" ); 349 QString rulesDir = Global::applicationFileName( "wordgame", "" );
350 QDir dir( rulesDir, "*.rules" ); 350 QDir dir( rulesDir, "*.rules" );
351 ruleslist = dir.entryList(); 351 ruleslist = dir.entryList();
352 if ( ruleslist.isEmpty() ) { 352 if ( ruleslist.isEmpty() ) {
353 // Provide a sample 353 // Provide a sample
354 QFile file( rulesDir + "Sample.rules" ); 354 QFile file( rulesDir + "Sample.rules" );
355 if ( file.open( IO_WriteOnly ) ) { 355 if ( file.open( IO_WriteOnly ) ) {
356 file.writeBlock( sampleWGR, strlen(sampleWGR) ); 356 file.writeBlock( sampleWGR, strlen(sampleWGR) );
357 file.close(); 357 file.close();
358 updateRuleSets(); 358 updateRuleSets();
359 } 359 }
360 return; 360 return;
361 } 361 }
362 int newest=0; 362 int newest=0;
363 int newest_age=INT_MAX; 363 int newest_age=INT_MAX;
364 QDateTime now = QDateTime::currentDateTime(); 364 QDateTime now = QDateTime::currentDateTime();
365 QStringList::Iterator it; 365 QStringList::Iterator it;
366 for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) { 366 for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) {
367 QFileInfo fi((*it)); 367 QFileInfo fi((*it));
368 int age = fi.lastModified().secsTo(now); 368 int age = fi.lastModified().secsTo(now);
369 QString name = *it; 369 QString name = *it;
370 name.truncate( name.length()-6 ); // remove extension 370 name.truncate( name.length()-6 ); // remove extension
371 rules->insertItem( name ); 371 rules->insertItem( name );
372 if ( age < newest_age ) { 372 if ( age < newest_age ) {
373 newest_age = age; 373 newest_age = age;
374 newest = rules->count()-1; 374 newest = rules->count()-1;
375 } 375 }
376 } 376 }
377 rules->setCurrentItem(newest); 377 rules->setCurrentItem(newest);
378} 378}
379 379
380Rules::Rules(QWidget* parent) : 380Rules::Rules(QWidget* parent) :
381 RulesBase(parent,0,TRUE) 381 RulesBase(parent,0,TRUE)
382{ 382{
383} 383}
384 384
385void Rules::editRules() 385void Rules::editRules()
386{ 386{
387 if ( exec() ) { 387 if ( exec() ) {
388 // ### create a new set of rules 388 // ### create a new set of rules
389 emit rulesChanged(); 389 emit rulesChanged();
390 } 390 }
391} 391}
392 392
393void Rules::deleteRuleSet() 393void Rules::deleteRuleSet()
394{ 394{
395 // ### delete existing rule set 395 // ### delete existing rule set
396 emit rulesChanged(); 396 emit rulesChanged();
397} 397}
398 398
399void WordGame::addPlayer(const QString& name) 399void WordGame::addPlayer(const QString& name)
400{ 400{
401 if ( !name.isEmpty() ) { 401 if ( !name.isEmpty() ) {
402 int colon = name.find(':'); 402 int colon = name.find(':');
403 int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0; 403 int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0;
404 addPlayer(name,cpu); 404 addPlayer(name,cpu);
405 } 405 }
406} 406}
407 407
408void WordGame::addPlayer(const QString& name, int cpu) 408void WordGame::addPlayer(const QString& name, int cpu)
409{ 409{
410 Rack* r = new Rack(rack_tiles,racks); 410 Rack* r = new Rack(rack_tiles,racks);
411 r->setPlayerName(name); 411 r->setPlayerName(name);
412 r->setComputerization(cpu); 412 r->setComputerization(cpu);
413 racks->addWidget(r, nplayers); 413 racks->addWidget(r, nplayers);
414 refillRack(nplayers); 414 refillRack(nplayers);
415 namelist.append(name); 415 namelist.append(name);
416 416
417 ++nplayers; 417 ++nplayers;
418} 418}
419 419
420void WordGame::nextPlayer() 420void WordGame::nextPlayer()
421{ 421{
422 if ( !refillRack(player) ) { 422 if ( !refillRack(player) ) {
423 endGame(); 423 endGame();
424 } else { 424 } else {
425 player = (player+1)%nplayers; 425 player = (player+1)%nplayers;
426 scoreinfo->setBoldOne(player); 426 scoreinfo->setBoldOne(player);
427 readyRack(player); 427 readyRack(player);
428 } 428 }
429} 429}
430 430
431bool WordGame::mayEndGame() 431bool WordGame::mayEndGame()
432{ 432{
433 int out=-1; 433 int out=-1;
434 int i; 434 int i;
435 for (i=0; i<nplayers; i++) 435 for (i=0; i<nplayers; i++)
436 if ( !rack(i)->count() ) 436 if ( !rack(i)->count() )
437 out = i; 437 out = i;
438 if ( out<0 ) { 438 if ( out<0 ) {
439 if ( QMessageBox::warning(this,tr("End game"), 439 if ( QMessageBox::warning(this,tr("End game"),
440 tr("Do you want to end the game early?"), 440 tr("Do you want to end the game early?"),
441 tr("Yes"), tr("No") )!=0 ) 441 tr("Yes"), tr("No") )!=0 )
442 { 442 {
443 return FALSE; 443 return FALSE;
444 } 444 }
445 } 445 }
446 return TRUE; 446 return TRUE;
447} 447}
448 448
449void WordGame::endGame() 449void WordGame::endGame()
450{ 450{
451 if ( gameover ) { 451 if ( gameover ) {
452 close(); 452 close();
453 return; 453 return;
454 } 454 }
455 455
456 if ( !mayEndGame() ) 456 if ( !mayEndGame() )
457 return; 457 return;
458 int out=-1; 458 int out=-1;
459 int totalleft=0; 459 int totalleft=0;
460 int i; 460 int i;
461 for (i=0; i<nplayers; i++) { 461 for (i=0; i<nplayers; i++) {
462 Rack* r = rack(i); 462 Rack* r = rack(i);
463 int c = r->count(); 463 int c = r->count();
464 if ( c ) { 464 if ( c ) {
465 int lose=0; 465 int lose=0;
466 for ( int j=0; j<c; j++ ) 466 for ( int j=0; j<c; j++ )
467 lose += r->tileRef(j)->value(); 467 lose += r->tileRef(j)->value();
468 totalleft += lose; 468 totalleft += lose;
469 scoreinfo->addScore(i,-lose); 469 scoreinfo->addScore(i,-lose);
470 } else { 470 } else {
471 out = i; 471 out = i;
472 } 472 }
473 } 473 }
474 int highest=0; 474 int highest=0;
475 int winner=0; 475 int winner=0;
476 for (i=0; i<nplayers; i++) { 476 for (i=0; i<nplayers; i++) {
477 int s = scoreinfo->playerScore(i); 477 int s = scoreinfo->playerScore(i);
478 if ( s > highest ) { 478 if ( s > highest ) {
479 highest = s; 479 highest = s;
480 winner = i; 480 winner = i;
481 } 481 }
482 } 482 }
483 if ( out >= 0 ) 483 if ( out >= 0 )
484 scoreinfo->addScore(out,totalleft); 484 scoreinfo->addScore(out,totalleft);
485 scoreinfo->setBoldOne(winner); 485 scoreinfo->setBoldOne(winner);
486 gameover = TRUE; 486 gameover = TRUE;
487 done->setEnabled(TRUE); 487 done->setEnabled(TRUE);
488 reset->setEnabled(FALSE); 488 reset->setEnabled(FALSE);
489} 489}
490 490
491void WordGame::endTurn() 491void WordGame::endTurn()
492{ 492{
493 if ( gameover ) { 493 if ( gameover ) {
494 openGameSelector(namelist); 494 openGameSelector(namelist);
495 } else { 495 } else {
496 if ( board->checkTurn() ) { 496 if ( board->checkTurn() ) {
497 if ( board->turnScore() >= 0 ) { 497 if ( board->turnScore() >= 0 ) {
498 scoreinfo->addScore(player,board->turnScore()); 498 scoreinfo->addScore(player,board->turnScore());
499 board->finalizeTurn(); 499 board->finalizeTurn();
500 } else { 500 } else {
501 QApplication::beep(); 501 QApplication::beep();
502 } 502 }
503 nextPlayer(); 503 nextPlayer();
504 } 504 }
505 } 505 }
506} 506}
507 507
508void WordGame::resetTurn() 508void WordGame::resetTurn()
509{ 509{
510 board->resetRack(); 510 board->resetRack();
511} 511}
512 512
513void WordGame::passTurn() 513void WordGame::passTurn()
514{ 514{
515 // ######## trade? 515 // ######## trade?
516 nextPlayer(); 516 nextPlayer();
517} 517}
518 518
519bool WordGame::refillRack(int i) 519bool WordGame::refillRack(int i)
520{ 520{
521 Rack* r = rack(i); 521 Rack* r = rack(i);
522 while ( !bag->isEmpty() && !r->isFull() ) { 522 while ( !bag->isEmpty() && !r->isFull() ) {
523 r->addTile(bag->takeRandom()); 523 r->addTile(bag->takeRandom());
524 } 524 }
525 return r->count() != 0; 525 return r->count() != 0;
526} 526}
527 527
528void WordGame::readyRack(int i) 528void WordGame::readyRack(int i)
529{ 529{
530 Rack* r = rack(i); 530 Rack* r = rack(i);
531 racks->raiseWidget(i); 531 racks->raiseWidget(i);
532 board->setCurrentRack(r); 532 board->setCurrentRack(r);
533 533
534 done->setEnabled( !r->computerized() ); 534 done->setEnabled( !r->computerized() );
535 reset->setEnabled( !r->computerized() ); 535 reset->setEnabled( !r->computerized() );
536 536
537 if ( r->computerized() ) { 537 if ( r->computerized() ) {
538 cpu = new ComputerPlayer(board, r); 538 cpu = new ComputerPlayer(board, r);
539 aiheart->start(0); 539 aiheart->start(0);
540 } 540 }
541} 541}
542 542
543Rack* WordGame::rack(int i) const 543Rack* WordGame::rack(int i) const
544{ 544{
545 return (Rack*)racks->widget(i); 545 return (Rack*)racks->widget(i);
546} 546}
547 547
548void WordGame::think() 548void WordGame::think()
549{ 549{
550 if ( !cpu->step() ) { 550 if ( !cpu->step() ) {
551 delete cpu; 551 delete cpu;
552 cpu = 0; 552 cpu = 0;
553 aiheart->stop(); 553 aiheart->stop();
554 if ( board->turnScore() < 0 ) 554 if ( board->turnScore() < 0 )
555 passTurn(); 555 passTurn();
556 else 556 else
557 endTurn(); 557 endTurn();
558 } 558 }
559} 559}
560 560
561ComputerPlayer::ComputerPlayer(Board* b, Rack* r) : 561ComputerPlayer::ComputerPlayer(Board* b, Rack* r) :
562 board(b), rack(r), best(new const Tile*[rack_tiles]), 562 board(b), rack(r), best(new const Tile*[rack_tiles]),
563 best_blankvalues(new Tile[rack_tiles]) 563 best_blankvalues(new Tile[rack_tiles])
564{ 564{
565 best_score = -1; 565 best_score = -1;
566 across=FALSE; 566 across=FALSE;
567 dict=0; 567 dict=0;
568} 568}
569 569
570ComputerPlayer::~ComputerPlayer() 570ComputerPlayer::~ComputerPlayer()
571{ 571{
572 delete [] best; 572 delete [] best;
573 delete [] best_blankvalues; 573 delete [] best_blankvalues;
574} 574}
575 575
576bool ComputerPlayer::step() 576bool ComputerPlayer::step()
577{ 577{
578 const QDawg::Node* root = dict ? Global::dawg("WordGame").root() 578 const QDawg::Node* root = dict ? Global::dawg("WordGame").root()
579 : Global::fixedDawg().root(); 579 : Global::fixedDawg().root();
580 QPoint d = across ? QPoint(1,0) : QPoint(0,1); 580 QPoint d = across ? QPoint(1,0) : QPoint(0,1);
581 const Tile* tiles[99]; // ### max board size 581 const Tile* tiles[99]; // ### max board size
582 uchar nletter[4095]; // QDawg only handles 0..4095 582 uchar nletter[4095]; // QDawg only handles 0..4095
583 memset(nletter,0,4096); 583 memset(nletter,0,4096);
584 for (int i=0; i<rack->count(); i++) { 584 for (int i=0; i<rack->count(); i++) {
585 const Tile* r = rack->tileRef(i); 585 const Tile* r = rack->tileRef(i);
586 if ( r->isBlank() ) 586 if ( r->isBlank() )
587 nletter[0]++; 587 nletter[0]++;
588 else 588 else
589 nletter[r->text()[0].unicode()]++; 589 nletter[r->text()[0].unicode()]++;
590 } 590 }
591 Tile blankvalues[99]; // ### max blanks 591 Tile blankvalues[99]; // ### max blanks
592 findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0); 592 findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0);
593 if ( ++current.rx() == board->xTiles() ) { 593 if ( ++current.rx() == board->xTiles() ) {
594 current.rx() = 0; 594 current.rx() = 0;
595 if ( ++current.ry() == board->yTiles() ) { 595 if ( ++current.ry() == board->yTiles() ) {
596 if ( across ) { 596 if ( across ) {
597 if ( dict == 1 ) { 597 if ( dict == 1 ) {
598 if ( best_score >= 0 ) { 598 if ( best_score >= 0 ) {
599 rack->arrangeTiles(best,best_n); 599 rack->arrangeTiles(best,best_n);
600 rack->setBlanks(best_blankvalues); 600 rack->setBlanks(best_blankvalues);
601 board->scoreTurn(best_start, best_n, best_dir); 601 board->scoreTurn(best_start, best_n, best_dir);
602 board->showTurn(); 602 board->showTurn();
603 } 603 }
604 return FALSE; 604 return FALSE;
605 } 605 }
606 dict++; 606 dict++;
607 across = FALSE; 607 across = FALSE;
608 current = QPoint(0,0); 608 current = QPoint(0,0);
609 } else { 609 } else {
610 across = TRUE; 610 across = TRUE;
611 current = QPoint(0,0); 611 current = QPoint(0,0);
612 } 612 }
613 } 613 }
614 } 614 }
615 return TRUE; 615 return TRUE;
616} 616}
617 617
618void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused) 618void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused)
619{ 619{
620 if ( !node ) 620 if ( !node )
621 return; 621 return;
622 QChar l = node->letter(); 622 QChar l = node->letter();
623 const Tile* cur = board->tile(at); 623 const Tile* cur = board->tile(at);
624 if ( cur ) { 624 if ( cur ) {
625 if ( cur->text()[0] == l ) { 625 if ( cur->text()[0] == l ) {
626 bool nextok = board->contains(at+d); 626 bool nextok = board->contains(at+d);
627 if ( node->isWord() && n && (!nextok || !board->tile(at+d)) ) 627 if ( node->isWord() && n && (!nextok || !board->tile(at+d)) )
628 noteChoice(tiles,n,d,blankvalues,blused); 628 noteChoice(tiles,n,d,blankvalues,blused);
629 if ( nextok ) 629 if ( nextok )
630 findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); 630 findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused);
631 // #### text()[1]... 631 // #### text()[1]...
632 } 632 }
633 } else { 633 } else {
634 if ( nletter[l.unicode()] || nletter[0] ) { 634 if ( nletter[l.unicode()] || nletter[0] ) {
635 int rc = rack->count(); 635 int rc = rack->count();
636 ulong msk = 1; 636 ulong msk = 1;
637 for ( int x=0; x<rc; x++ ) { 637 for ( int x=0; x<rc; x++ ) {
638 if ( !(used&msk) ) { 638 if ( !(used&msk) ) {
639 const Tile* t = rack->tileRef(x); 639 const Tile* t = rack->tileRef(x);
640 if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s 640 if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s
641 bool nextok = board->contains(at+d); 641 bool nextok = board->contains(at+d);
642 tiles[n++] = t; 642 tiles[n++] = t;
643 if ( t->isBlank() ) 643 if ( t->isBlank() )
644 blankvalues[blused++] = Tile(l,0); 644 blankvalues[blused++] = Tile(l,0);
645 if ( node->isWord() && (!nextok || !board->tile(at+d)) ) 645 if ( node->isWord() && (!nextok || !board->tile(at+d)) )
646 noteChoice(tiles,n,d,blankvalues,blused); 646 noteChoice(tiles,n,d,blankvalues,blused);
647 used |= msk; // mark 647 used |= msk; // mark
648 nletter[t->text()[0].unicode()]--; 648 nletter[t->text()[0].unicode()]--;
649 if ( nextok ) 649 if ( nextok )
650 findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); 650 findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused);
651 n--; 651 n--;
652 nletter[t->text()[0].unicode()]++; 652 nletter[t->text()[0].unicode()]++;
653 if ( t->isBlank() ) { 653 if ( t->isBlank() ) {
654 // keep looking 654 // keep looking
655 blused--; 655 blused--;
656 used &= ~msk; // unmark 656 used &= ~msk; // unmark
657 } else { 657 } else {
658 break; 658 break;
659 } 659 }
660 } 660 }
661 } 661 }
662 msk <<= 1; 662 msk <<= 1;
663 } 663 }
664 } 664 }
665 // #### text()[1]... 665 // #### text()[1]...
666 } 666 }
667 findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused); 667 findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused);
668} 668}
669 669
670void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused) 670void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused)
671{ 671{
672 int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0); 672 int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0);
673/* 673/*
674if (s>0 || current==QPoint(5,1)){ 674if (s>0 || current==QPoint(5,1)){
675QString st; 675QString st;
676for ( int i=0; i<n; i++ ) 676for ( int i=0; i<n; i++ )
677 st += tiles[i]->text(); 677 st += tiles[i]->text();
678qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s); 678qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s);
679} 679}
680*/ 680*/
681 if ( s > best_score ) { 681 if ( s > best_score ) {
682 int i; 682 int i;
683 for ( i=0; i<n; i++ ) 683 for ( i=0; i<n; i++ )
684 best[i] = tiles[i]; 684 best[i] = tiles[i];
685 for ( i=0; i<blused; i++ ) 685 for ( i=0; i<blused; i++ )
686 best_blankvalues[i] = blankvalues[i]; 686 best_blankvalues[i] = blankvalues[i];
687 best_n = n; 687 best_n = n;
688 best_blused = blused; 688 best_blused = blused;
689 best_score = s; 689 best_score = s;
690 best_dir = d; 690 best_dir = d;
691 best_start = current; 691 best_start = current;
692 } 692 }
693} 693}
694 694
695int TileItem::smallWidth() 695int TileItem::smallWidth()
696{ 696{
697 return tile_smallw; 697 return tile_smallw;
698} 698}
699 699
700int TileItem::smallHeight() 700int TileItem::smallHeight()
701{ 701{
702 return tile_smallh; 702 return tile_smallh;
703} 703}
704 704
705int TileItem::bigWidth() 705int TileItem::bigWidth()
706{ 706{
707 return tile_bigw; 707 return tile_bigw;
708} 708}
709 709
710int TileItem::bigHeight() 710int TileItem::bigHeight()
711{ 711{
712 return tile_bigh; 712 return tile_bigh;
713} 713}
714 714
715void TileItem::setState( State state ) 715void TileItem::setState( State state )
716{ 716{
717 hide(); 717 hide();
718 s = state; 718 s = state;
719 show(); // ### use update() in Qt 3.0 719 show(); // ### use update() in Qt 3.0
720} 720}
721 721
722void TileItem::setTile(const Tile& tile) 722void TileItem::setTile(const Tile& tile)
723{ 723{
724 hide(); 724 hide();
725 t = tile; 725 t = tile;
726 show(); // ### use update() in Qt 3.0 726 show(); // ### use update() in Qt 3.0
727} 727}
728 728
729void TileItem::setBig(bool b) 729void TileItem::setBig(bool b)
730{ 730{
731 big = b; 731 big = b;
732} 732}
733 733
734void TileItem::drawShape(QPainter& p) 734void TileItem::drawShape(QPainter& p)
735{ 735{
736 static QFont *value_font=0; 736 static QFont *value_font=0;
737 static QFont *big_font=0; 737 static QFont *big_font=0;
738 static QFont *small_font=0; 738 static QFont *small_font=0;
739 if ( !value_font ) { 739 if ( !value_font ) {
740 value_font = new QFont("helvetica",8); 740 value_font = new QFont("helvetica",8);
741 if ( TileItem::bigWidth() < 20 ) { 741 if ( TileItem::bigWidth() < 20 ) {
742 big_font = new QFont("helvetica",12); 742 big_font = new QFont("helvetica",12);
743 small_font = new QFont("helvetica",8); 743 small_font = new QFont("helvetica",8);
744 } else { 744 } else {
745 big_font = new QFont("smoothtimes",17); 745 big_font = new QFont("smoothtimes",17);
746 small_font = new QFont("smoothtimes",10); 746 small_font = new QFont("smoothtimes",10);
747 } 747 }
748 } 748 }
749 749
750 QRect area(x(),y(),width(),height()); 750 QRect area(x(),y(),width(),height());
751 p.setBrush(s == Floating ? yellow/*lightGray*/ : white); 751 p.setBrush(s == Floating ? yellow/*lightGray*/ : white);
752 p.drawRect(area); 752 p.drawRect(area);
753 if ( big ) { 753 if ( big ) {
754 p.setFont(*value_font); 754 p.setFont(*value_font);
755 QString n = QString::number(t.value()); 755 QString n = QString::number(t.value());
756 int w = p.fontMetrics().width('1'); 756 int w = p.fontMetrics().width('1');
757 int h = p.fontMetrics().height(); 757 int h = p.fontMetrics().height();
758 w *= n.length(); 758 w *= n.length();
759 QRect valuearea(x()+width()-w-1,y()+height()-h,w,h); 759 QRect valuearea(x()+width()-w-1,y()+height()-h,w,h);
760 p.drawText(valuearea,AlignCenter,n); 760 p.drawText(valuearea,AlignCenter,n);
761 p.setFont(*big_font); 761 p.setFont(*big_font);
762 area = QRect(x(),y()+tile_btweak,width()-4,height()-1); 762 area = QRect(x(),y()+tile_btweak,width()-4,height()-1);
763 } else { 763 } else {
764 p.setFont(*small_font); 764 p.setFont(*small_font);
765 area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3); 765 area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3);
766 } 766 }
767 if ( t.value() == 0 ) 767 if ( t.value() == 0 )
768 p.setPen(darkGray); 768 p.setPen(darkGray);
769 p.drawText(area,AlignCenter,t.text().upper()); 769 p.drawText(area,AlignCenter,t.text().upper());
770} 770}
771 771
772Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : 772Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) :
773 QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), 773 QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()),
774 parent) 774 parent)
775{ 775{
776 setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight()); 776 setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight());
777 grid = new TileItem*[w*h]; 777 grid = new TileItem*[w*h];
778 memset(grid,0,w*h*sizeof(TileItem*)); 778 memset(grid,0,w*h*sizeof(TileItem*));
779 setFrameStyle(0); 779 setFrameStyle(0);
780 setHScrollBarMode(AlwaysOff); 780 setHScrollBarMode(AlwaysOff);
781 setVScrollBarMode(AlwaysOff); 781 setVScrollBarMode(AlwaysOff);
782 current_rack = 0; 782 current_rack = 0;
783 shown_n = 0; 783 shown_n = 0;
784} 784}
785 785
786Board::~Board() 786Board::~Board()
787{ 787{
788 delete canvas(); 788 delete canvas();
789} 789}
790 790
791QSize Board::sizeHint() const 791QSize Board::sizeHint() const
792{ 792{
793 return QSize(canvas()->width(),canvas()->height()); 793 return QSize(canvas()->width(),canvas()->height());
794} 794}
795 795
796void Board::writeConfig(Config& cfg) 796void Board::writeConfig(Config& cfg)
797{ 797{
798 QStringList t; 798 QStringList t;
799 int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); 799 int n=canvas()->tilesHorizontally()*canvas()->tilesVertically();
800 for (int i=0; i<n; i++) 800 for (int i=0; i<n; i++)
801 t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); 801 t.append( grid[i] ? grid[i]->tile().key() : QString(".") );
802 cfg.writeEntry("Board",t,';'); 802 cfg.writeEntry("Board",t,';');
803} 803}
804 804
805void Board::readConfig(Config& cfg) 805void Board::readConfig(Config& cfg)
806{ 806{
807 clear(); 807 clear();
808 QStringList t = cfg.readListEntry("Board",';'); 808 QStringList t = cfg.readListEntry("Board",';');
809 int i=0; 809 int i=0;
810 int h=canvas()->tilesHorizontally(); 810 int h=canvas()->tilesHorizontally();
811 for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) { 811 for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) {
812 if ( *it != "." ) { 812 if ( *it != "." ) {
813 QPoint p(i%h,i/h); 813 QPoint p(i%h,i/h);
814 setTile(p,Tile(*it)); 814 setTile(p,Tile(*it));
815 } 815 }
816 i++; 816 i++;
817 } 817 }
818 canvas()->update(); 818 canvas()->update();
819} 819}
820 820
821void Board::clear() 821void Board::clear()
822{ 822{
823 int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); 823 int n=canvas()->tilesHorizontally()*canvas()->tilesVertically();
824 for (int i=0; i<n; i++) { 824 for (int i=0; i<n; i++) {
825 delete grid[i]; 825 delete grid[i];
826 grid[i]=0; 826 grid[i]=0;
827 } 827 }
828} 828}
829 829
830 830
831void Board::setCurrentRack(Rack* r) 831void Board::setCurrentRack(Rack* r)
832{ 832{
833 turn_score = -1; 833 turn_score = -1;
834 current_rack = r; 834 current_rack = r;
835} 835}
836 836
837void Board::resetRack() 837void Board::resetRack()
838{ 838{
839 unshowTurn(); 839 unshowTurn();
840 canvas()->update(); 840 canvas()->update();
841} 841}
842 842
843void Board::contentsMousePressEvent(QMouseEvent* e) 843void Board::contentsMousePressEvent(QMouseEvent* e)
844{ 844{
845 dragstart = e->pos(); 845 dragstart = e->pos();
846} 846}
847 847
848void Board::contentsMouseMoveEvent(QMouseEvent* e) 848void Board::contentsMouseMoveEvent(QMouseEvent* e)
849{ 849{
850 if ( current_rack && !current_rack->computerized() ) { 850 if ( current_rack && !current_rack->computerized() ) {
851 QPoint d = e->pos() - dragstart; 851 QPoint d = e->pos() - dragstart;
852 if ( d.x() <= 0 && d.y() <= 0 ) { 852 if ( d.x() <= 0 && d.y() <= 0 ) {
853 // None 853 // None
854 resetRack(); 854 resetRack();
855 } else { 855 } else {
856 int n; 856 int n;
857 QPoint start=boardPos(dragstart); 857 QPoint start=boardPos(dragstart);
858 QPoint end=boardPos(e->pos()); 858 QPoint end=boardPos(e->pos());
859 QPoint diff=end-start; 859 QPoint diff=end-start;
860 QPoint dir; 860 QPoint dir;
861 if ( d.x() > d.y() ) { 861 if ( d.x() > d.y() ) {
862 n = diff.x()+1; 862 n = diff.x()+1;
863 dir = QPoint(1,0); 863 dir = QPoint(1,0);
864 } else { 864 } else {
865 n = diff.y()+1; 865 n = diff.y()+1;
866 dir = QPoint(0,1); 866 dir = QPoint(0,1);
867 } 867 }
868 868
869 unshowTurn(); 869 unshowTurn();
870 870
871 // Subtract existing tiles from n 871 // Subtract existing tiles from n
872 QPoint t = start; 872 QPoint t = start;
873 for ( int i=n; i--; ) { 873 for ( int i=n; i--; ) {
874 if ( contains(t) && tile(t) ) 874 if ( contains(t) && tile(t) )
875 n--; 875 n--;
876 t += dir; 876 t += dir;
877 } 877 }
878 878
879 // Move start back to real start 879 // Move start back to real start
880 while (contains(start-dir) && tile(start-dir)) 880 while (contains(start-dir) && tile(start-dir))
881 start -= dir; 881 start -= dir;
882 882
883 scoreTurn(start, n, dir); 883 scoreTurn(start, n, dir);
884 showTurn(); 884 showTurn();
885 } 885 }
886 } 886 }
887} 887}
888 888
889void Board::finalizeTurn() 889void Board::finalizeTurn()
890{ 890{
891 int i=0; 891 int i=0;
892 QPoint at = shown_at; 892 QPoint at = shown_at;
893 while ( i<shown_n && contains(at) ) { 893 while ( i<shown_n && contains(at) ) {
894 if ( item(at) && item(at)->state() == TileItem::Floating ) { 894 if ( item(at) && item(at)->state() == TileItem::Floating ) {
895 current_rack->remove(item(at)->tile()); 895 current_rack->remove(item(at)->tile());
896 setTileState(at,TileItem::Firm); 896 setTileState(at,TileItem::Firm);
897 i++; 897 i++;
898 } 898 }
899 at += shown_step; 899 at += shown_step;
900 } 900 }
901 canvas()->update(); 901 canvas()->update();
902} 902}
903 903
904void Board::unshowTurn() 904void Board::unshowTurn()
905{ 905{
906 int i=0; 906 int i=0;
907 QPoint at = shown_at; 907 QPoint at = shown_at;
908 while ( i<shown_n && i<current_rack->count() && contains(at) ) { 908 while ( i<shown_n && i<current_rack->count() && contains(at) ) {
909 if ( item(at) && item(at)->state() == TileItem::Floating ) { 909 if ( item(at) && item(at)->state() == TileItem::Floating ) {
910 unsetTile(at); 910 unsetTile(at);
911 i++; 911 i++;
912 } 912 }
913 at += shown_step; 913 at += shown_step;
914 } 914 }
915} 915}
916 916
917void Board::showTurn() 917void Board::showTurn()
918{ 918{
919 unshowTurn(); 919 unshowTurn();
920 QPoint at = shown_at; 920 QPoint at = shown_at;
921 int i=0; 921 int i=0;
922 while ( i<shown_n && i<current_rack->count() && contains(at) ) { 922 while ( i<shown_n && i<current_rack->count() && contains(at) ) {
923 if ( !tile(at) ) { 923 if ( !tile(at) ) {
924 Tile t = current_rack->tile(i); 924 Tile t = current_rack->tile(i);
925 setTile(at,t); 925 setTile(at,t);
926 setTileState(at,TileItem::Floating); 926 setTileState(at,TileItem::Floating);
927 i++; 927 i++;
928 } 928 }
929 at += shown_step; 929 at += shown_step;
930 } 930 }
931 canvas()->update(); 931 canvas()->update();
932} 932}
933 933
934int Board::bonussedValue(const QPoint& at, int base, int& all_mult) const 934int Board::bonussedValue(const QPoint& at, int base, int& all_mult) const
935{ 935{
936 int rule = rule_shape[idx(at)]-'0'; 936 int rule = rule_shape[idx(at)]-'0';
937 int effect = rule_effect[rule]; 937 int effect = rule_effect[rule];
938 int mult = effect&Multiplier; 938 int mult = effect&Multiplier;
939 if ( effect & MultiplyAll ) { 939 if ( effect & MultiplyAll ) {
940 all_mult *= mult; 940 all_mult *= mult;
941 return base; 941 return base;
942 } else { 942 } else {
943 return base * mult; 943 return base * mult;
944 } 944 }
945} 945}
946 946
947bool Board::isStart(const QPoint& at) const 947bool Board::isStart(const QPoint& at) const
948{ 948{
949 int rule = rule_shape[idx(at)]-'0'; 949 int rule = rule_shape[idx(at)]-'0';
950 int effect = rule_effect[rule]; 950 int effect = rule_effect[rule];
951 return effect&Start; 951 return effect&Start;
952} 952}
953 953
954bool Board::checkTurn() 954bool Board::checkTurn()
955{ 955{
956 if ( current_rack->computerized() ) 956 if ( current_rack->computerized() )
957 return TRUE; // computer doesn't cheat, and has already set blanks. 957 return TRUE; // computer doesn't cheat, and has already set blanks.
958 958
959 QPoint at = shown_at; 959 QPoint at = shown_at;
960 int n = shown_n; 960 int n = shown_n;
961 QPoint d = shown_step; 961 QPoint d = shown_step;
962 const Tile* tiles[99]; 962 const Tile* tiles[99];
963 Tile blankvalues[99]; 963 Tile blankvalues[99];
964 if ( n > current_rack->count() ) 964 if ( n > current_rack->count() )
965 n = current_rack->count(); 965 n = current_rack->count();
966 966
967 QDialog check(this,0,TRUE); 967 QDialog check(this,0,TRUE);
968 (new QVBoxLayout(&check))->setAutoAdd(TRUE); 968 (new QVBoxLayout(&check))->setAutoAdd(TRUE);
969 969
970 QHBox mw(&check); 970 QHBox mw(&check);
971 new QLabel(tr("Blanks: "),&mw); 971 new QLabel(tr("Blanks: "),&mw);
972 972
973 int bl=0; 973 int bl=0;
974 QLineEdit* le[99]; 974 QLineEdit* le[99];
975 for (int i=0; i<n; i++) { 975 for (int i=0; i<n; i++) {
976 tiles[i] = current_rack->tileRef(i); 976 tiles[i] = current_rack->tileRef(i);
977 if ( tiles[i]->isBlank() ) { 977 if ( tiles[i]->isBlank() ) {
978 QLineEdit *l = new QLineEdit(&mw); 978 QLineEdit *l = new QLineEdit(&mw);
979 le[bl++] = l; 979 le[bl++] = l;
980 l->setMaxLength(1); 980 l->setMaxLength(1);
981 l->setFixedSize(l->minimumSizeHint()); 981 l->setFixedSize(l->minimumSizeHint());
982 } 982 }
983 } 983 }
984 984
985 QHBox btns(&check); 985 QHBox btns(&check);
986 connect(new QPushButton(tr("OK"),&btns), SIGNAL(clicked()), &check, SLOT(accept())); 986 connect(new QPushButton(tr("OK"),&btns), SIGNAL(clicked()), &check, SLOT(accept()));
987 connect(new QPushButton(tr("Cancel"),&btns), SIGNAL(clicked()), &check, SLOT(reject())); 987 connect(new QPushButton(tr("Cancel"),&btns), SIGNAL(clicked()), &check, SLOT(reject()));
988 988
989 if ( bl ) { 989 if ( bl ) {
990retry: 990retry:
991 if ( !check.exec() ) { 991 if ( !check.exec() ) {
992 unshowTurn(); 992 unshowTurn();
993 canvas()->update(); 993 canvas()->update();
994 return FALSE; 994 return FALSE;
995 } 995 }
996 996
997 for (int b=0; b<bl; b++) { 997 for (int b=0; b<bl; b++) {
998 QString v = le[b]->text(); 998 QString v = le[b]->text();
999 blankvalues[b]=Tile(v,0); 999 blankvalues[b]=Tile(v,0);
1000 if ( v.length() != 1 ) 1000 if ( v.length() != 1 )
1001 goto retry; 1001 goto retry;
1002 } 1002 }
1003 } 1003 }
1004 1004
1005 QStringList words; 1005 QStringList words;
1006 unshowTurn(); 1006 unshowTurn();
1007 turn_score = score(at,tiles,n,blankvalues,d,FALSE,&words); 1007 turn_score = score(at,tiles,n,blankvalues,d,FALSE,&words);
1008 showTurn(); 1008 showTurn();
1009 QStringList to_add; 1009 QStringList to_add;
1010 for (QStringList::Iterator it=words.begin(); it!=words.end(); ++it) { 1010 for (QStringList::Iterator it=words.begin(); it!=words.end(); ++it) {
1011 if ( !Global::fixedDawg().contains(*it) 1011 if ( !Global::fixedDawg().contains(*it)
1012 && !Global::dawg("WordGame").contains(*it) ) { 1012 && !Global::dawg("WordGame").contains(*it) ) {
1013 switch (QMessageBox::warning(this, tr("Unknown word"), 1013 switch (QMessageBox::warning(this, tr("Unknown word"),
1014 tr("<p>The word \"%1\" is not in the dictionary.").arg(*it), 1014 tr("<p>The word \"%1\" is not in the dictionary.").arg(*it),
1015 tr("Add"), tr("Ignore"), tr("Cancel"))) 1015 tr("Add"), tr("Ignore"), tr("Cancel")))
1016 { 1016 {
1017 case 0: 1017 case 0:
1018 // ####### add to wordgame dictionary 1018 // ####### add to wordgame dictionary
1019 to_add.append(*it); 1019 to_add.append(*it);
1020 break; 1020 break;
1021 case 1: 1021 case 1:
1022 break; 1022 break;
1023 case 2: 1023 case 2:
1024 unshowTurn(); 1024 unshowTurn();
1025 canvas()->update(); 1025 canvas()->update();
1026 return FALSE; 1026 return FALSE;
1027 } 1027 }
1028 } 1028 }
1029 } 1029 }
1030 if ( to_add.count() ) 1030 if ( to_add.count() )
1031 Global::addWords("WordGame",to_add); 1031 Global::addWords("WordGame",to_add);
1032 return TRUE; 1032 return TRUE;
1033} 1033}
1034 1034
1035void Board::scoreTurn(const QPoint& at, int n, const QPoint& d) 1035void Board::scoreTurn(const QPoint& at, int n, const QPoint& d)
1036{ 1036{
1037 unshowTurn(); 1037 unshowTurn();
1038 shown_at = at; 1038 shown_at = at;
1039 shown_n = n; 1039 shown_n = n;
1040 shown_step = d; 1040 shown_step = d;
1041 const Tile* tiles[99]; 1041 const Tile* tiles[99];
1042 if ( n > current_rack->count() ) 1042 if ( n > current_rack->count() )
1043 n = current_rack->count(); 1043 n = current_rack->count();
1044 for (int i=0; i<n; i++) 1044 for (int i=0; i<n; i++)
1045 tiles[i] = current_rack->tileRef(i); 1045 tiles[i] = current_rack->tileRef(i);
1046 turn_score = score(at,tiles,n,0,d,FALSE,0); 1046 turn_score = score(at,tiles,n,0,d,FALSE,0);
1047 emit temporaryScore(turn_score); 1047 emit temporaryScore(turn_score);
1048} 1048}
1049 1049
1050int Board::score(QPoint at, const Tile** tiles, int n, const Tile* blankvalue, const QPoint& d, bool checkdict, QStringList* words) const 1050int Board::score(QPoint at, const Tile** tiles, int n, const Tile* blankvalue, const QPoint& d, bool checkdict, QStringList* words) const
1051{ 1051{
1052 int total=0; 1052 int total=0;
1053 int totalsidetotal=0; 1053 int totalsidetotal=0;
1054 1054
1055 // words gets filled with words made 1055 // words gets filled with words made
1056 1056
1057 // mainword==0 -> 1057 // mainword==0 ->
1058 // Checks side words, but not main word 1058 // Checks side words, but not main word
1059 1059
1060 // -1 means words not in dict, or illegally positioned (eg. not connected) 1060 // -1 means words not in dict, or illegally positioned (eg. not connected)
1061 1061
1062 // text is assumed to fit on board. 1062 // text is assumed to fit on board.
1063 1063
1064 if ( words ) *words=QStringList(); 1064 if ( words ) *words=QStringList();
1065 1065
1066 QPoint otherd(d.y(), d.x()); 1066 QPoint otherd(d.y(), d.x());
1067 1067
1068 int all_mult = 1; 1068 int all_mult = 1;
1069 int bl=0; 1069 int bl=0;
1070 1070
1071 bool connected = FALSE; 1071 bool connected = FALSE;
1072 1072
1073 QString mainword=""; 1073 QString mainword="";
1074 1074
1075 if ( contains(at-d) && tile(at-d) ) { 1075 if ( contains(at-d) && tile(at-d) ) {
1076 return -1; // preceeding tiles 1076 return -1; // preceeding tiles
1077 } 1077 }
1078 1078
1079 const Tile* t; 1079 const Tile* t;
1080 for (int i=0; contains(at) && ((t=tile(at)) || i<n); ) { 1080 for (int i=0; contains(at) && ((t=tile(at)) || i<n); ) {
1081 if ( t ) { 1081 if ( t ) {
1082 if ( checkdict || words ) mainword += t->text(); 1082 if ( checkdict || words ) mainword += t->text();
1083 total += t->value(); 1083 total += t->value();
1084 connected = TRUE; 1084 connected = TRUE;
1085 } else { 1085 } else {
1086 QString sideword; 1086 QString sideword;
1087 QString tt; 1087 QString tt;
1088 if ( tiles[i]->isBlank() ) { 1088 if ( tiles[i]->isBlank() ) {
1089 if ( blankvalue ) 1089 if ( blankvalue )
1090 tt = blankvalue[bl++].text(); 1090 tt = blankvalue[bl++].text();
1091 } else { 1091 } else {
1092 tt = tiles[i]->text(); 1092 tt = tiles[i]->text();
1093 } 1093 }
1094 sideword=tt; 1094 sideword=tt;
1095 if ( checkdict || words ) mainword += tt; 1095 if ( checkdict || words ) mainword += tt;
1096 int side_mult = 1; 1096 int side_mult = 1;
1097 int tilevalue = bonussedValue(at,tiles[i]->value(),side_mult); 1097 int tilevalue = bonussedValue(at,tiles[i]->value(),side_mult);
1098 all_mult *= side_mult; 1098 all_mult *= side_mult;
1099 if ( !connected && isStart(at) ) 1099 if ( !connected && isStart(at) )
1100 connected = TRUE; 1100 connected = TRUE;
1101 total += tilevalue; 1101 total += tilevalue;
1102 int sidetotal = tilevalue; 1102 int sidetotal = tilevalue;
1103 { 1103 {
1104 QPoint side = at-otherd; 1104 QPoint side = at-otherd;
1105 1105
1106 while ( contains(side) && (t=tile(side)) ) { 1106 while ( contains(side) && (t=tile(side)) ) {
1107 sidetotal += t->value(); 1107 sidetotal += t->value();
1108 sideword.prepend(t->text()); 1108 sideword.prepend(t->text());
1109 side -= otherd; 1109 side -= otherd;
1110 } 1110 }
1111 } 1111 }
1112 { 1112 {
1113 QPoint side = at+otherd; 1113 QPoint side = at+otherd;
1114 while ( contains(side) && (t=tile(side)) ) { 1114 while ( contains(side) && (t=tile(side)) ) {
1115 sidetotal += t->value(); 1115 sidetotal += t->value();
1116 sideword.append(t->text()); 1116 sideword.append(t->text());
1117 side += otherd; 1117 side += otherd;
1118 } 1118 }
1119 } 1119 }
1120 if ( sideword.length() > 1 ) { 1120 if ( sideword.length() > 1 ) {
1121 if ( words ) 1121 if ( words )
1122 words->append(sideword); 1122 words->append(sideword);
1123 if ( checkdict && !Global::fixedDawg().contains(sideword) 1123 if ( checkdict && !Global::fixedDawg().contains(sideword)
1124 && !Global::dawg("WordGame").contains(sideword) ) 1124 && !Global::dawg("WordGame").contains(sideword) )
1125 return -1; 1125 return -1;
1126 totalsidetotal += sidetotal * side_mult; 1126 totalsidetotal += sidetotal * side_mult;
1127 connected = TRUE; 1127 connected = TRUE;
1128 } 1128 }
1129 i++; 1129 i++;
1130 } 1130 }
1131 at += d; 1131 at += d;
1132 } 1132 }
1133 1133
1134 if ( words ) 1134 if ( words )
1135 words->append(mainword); 1135 words->append(mainword);
1136 if ( checkdict && !Global::fixedDawg().contains(mainword) 1136 if ( checkdict && !Global::fixedDawg().contains(mainword)
1137 && !Global::dawg("WordGame").contains(mainword) ) 1137 && !Global::dawg("WordGame").contains(mainword) )
1138 return -1; 1138 return -1;
1139 1139
1140 if ( n == rack_tiles ) 1140 if ( n == rack_tiles )
1141 totalsidetotal += rack_tiles_bonus; 1141 totalsidetotal += rack_tiles_bonus;
1142 1142
1143 return connected ? totalsidetotal + total * all_mult : -1; 1143 return connected ? totalsidetotal + total * all_mult : -1;
1144} 1144}
1145 1145
1146QPoint Board::boardPos(const QPoint& p) const 1146QPoint Board::boardPos(const QPoint& p) const
1147{ 1147{
1148 return QPoint(p.x()/canvas()->tileWidth(), p.y()/canvas()->tileHeight()); 1148 return QPoint(p.x()/canvas()->tileWidth(), p.y()/canvas()->tileHeight());
1149} 1149}
1150 1150
1151void Board::contentsMouseReleaseEvent(QMouseEvent*) 1151void Board::contentsMouseReleaseEvent(QMouseEvent*)
1152{ 1152{
1153 if ( current_rack ) { 1153 if ( current_rack ) {
1154 } 1154 }
1155} 1155}
1156 1156
1157 1157
1158void Board::setRules(const QString& shapes, const int* effects) 1158void Board::setRules(const QString& shapes, const int* effects)
1159{ 1159{
1160 rule_shape=shapes; rule_effect=effects; 1160 rule_shape=shapes; rule_effect=effects;
1161 int i=0; 1161 int i=0;
1162 int maxre=0; 1162 int maxre=0;
1163 for (int y=0; y<yTiles(); y++) { 1163 for (int y=0; y<yTiles(); y++) {
1164 for (int x=0; x<xTiles(); x++) { 1164 for (int x=0; x<xTiles(); x++) {
1165 int re = shapes[i++]-'0'; 1165 int re = shapes[i++]-'0';
1166 if ( re > maxre ) maxre = re; 1166 if ( re > maxre ) maxre = re;
1167 canvas()->setTile(x,y,re); 1167 canvas()->setTile(x,y,re);
1168 } 1168 }
1169 } 1169 }
1170 rack_tiles_bonus=effects[maxre+1]; 1170 rack_tiles_bonus=effects[maxre+1];
1171} 1171}
1172 1172
1173void Board::unsetTile(const QPoint& p) 1173void Board::unsetTile(const QPoint& p)
1174{ 1174{
1175 delete item(p); 1175 delete item(p);
1176 grid[idx(p)] = 0; 1176 grid[idx(p)] = 0;
1177} 1177}
1178 1178
1179void Board::setTile(const QPoint& p, const Tile& t) 1179void Board::setTile(const QPoint& p, const Tile& t)
1180{ 1180{
1181 TileItem* it=item(p); 1181 TileItem* it=item(p);
1182 if ( !it ) { 1182 if ( !it ) {
1183 it = grid[idx(p)] = new TileItem(t,FALSE,canvas()); 1183 it = grid[idx(p)] = new TileItem(t,FALSE,canvas());
1184 it->move(p.x()*canvas()->tileWidth(), p.y()*canvas()->tileHeight()); 1184 it->move(p.x()*canvas()->tileWidth(), p.y()*canvas()->tileHeight());
1185 it->show(); 1185 it->show();
1186 } else { 1186 } else {
1187 it->setTile(t); 1187 it->setTile(t);
1188 } 1188 }
1189} 1189}
1190 1190
1191Rack::Rack(int ntiles, QWidget* parent) : QCanvasView( 1191Rack::Rack(int ntiles, QWidget* parent) : QCanvasView(
1192 new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()), 1192 new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()),
1193 parent), 1193 parent),
1194 item(ntiles) 1194 item(ntiles)
1195{ 1195{
1196 setLineWidth(1); 1196 setLineWidth(1);
1197 setFixedHeight(sizeHint().height()); 1197 setFixedHeight(sizeHint().height());
1198 n = 0; 1198 n = 0;
1199 for (int i=0; i<ntiles; i++) 1199 for (int i=0; i<ntiles; i++)
1200 item[i]=0; 1200 item[i]=0;
1201 setHScrollBarMode(AlwaysOff); 1201 setHScrollBarMode(AlwaysOff);
1202 setVScrollBarMode(AlwaysOff); 1202 setVScrollBarMode(AlwaysOff);
1203 canvas()->setBackgroundColor(gray); 1203 canvas()->setBackgroundColor(gray);
1204 dragging = 0; 1204 dragging = 0;
1205} 1205}
1206 1206
1207Rack::~Rack() 1207Rack::~Rack()
1208{ 1208{
1209 clear(); 1209 clear();
1210 delete canvas(); 1210 delete canvas();
1211} 1211}
1212 1212
1213QSize Rack::sizeHint() const 1213QSize Rack::sizeHint() const
1214{ 1214{
1215 return QSize(-1,TileItem::bigHeight()+2); 1215 return QSize(-1,TileItem::bigHeight()+2);
1216} 1216}
1217 1217
1218void Rack::clear() 1218void Rack::clear()
1219{ 1219{
1220 for (int i=0; i<n; i++) 1220 for (int i=0; i<n; i++)
1221 delete item[i]; 1221 delete item[i];
1222 n=0; 1222 n=0;
1223} 1223}
1224 1224
1225void Rack::writeConfig(Config& cfg) 1225void Rack::writeConfig(Config& cfg)
1226{ 1226{
1227 QStringList l; 1227 QStringList l;
1228 for (int i=0; i<n; i++) 1228 for (int i=0; i<n; i++)
1229 l.append(tile(i).key()); 1229 l.append(tile(i).key());
1230 cfg.writeEntry("Tiles",l,';'); 1230 cfg.writeEntry("Tiles",l,';');
1231} 1231}
1232 1232
1233void Rack::readConfig(Config& cfg) 1233void Rack::readConfig(Config& cfg)
1234{ 1234{
1235 clear(); 1235 clear();
1236 int x=0; 1236 int x=0;
1237 QStringList l = cfg.readListEntry("Tiles",';'); 1237 QStringList l = cfg.readListEntry("Tiles",';');
1238 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 1238 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
1239 TileItem *i = new TileItem(Tile(*it),TRUE,canvas()); 1239 TileItem *i = new TileItem(Tile(*it),TRUE,canvas());
1240 i->move(x++,0); 1240 i->move(x++,0);
1241 i->show(); 1241 i->show();
1242 item[n++] = i; 1242 item[n++] = i;
1243 } 1243 }
1244 layoutTiles(); 1244 layoutTiles();
1245} 1245}
1246 1246
1247static int cmp_tileitem(const void *a, const void *b) 1247static int cmp_tileitem(const void *a, const void *b)
1248{ 1248{
1249 const TileItem* ia = *(TileItem**)a; 1249 const TileItem* ia = *(TileItem**)a;
1250 const TileItem* ib = *(TileItem**)b; 1250 const TileItem* ib = *(TileItem**)b;
1251 return int(ia->x() - ib->x()); 1251 return int(ia->x() - ib->x());
1252} 1252}
1253 1253
1254void Rack::layoutTiles() 1254void Rack::layoutTiles()
1255{ 1255{
1256 int w = TileItem::bigWidth()+2; 1256 int w = TileItem::bigWidth()+2;
1257 1257
1258 if ( dragging ) dragging->moveBy(dragging_adj,0); 1258 if ( dragging ) dragging->moveBy(dragging_adj,0);
1259 qsort(item.data(), n, sizeof(TileItem*), cmp_tileitem); 1259 qsort(item.data(), n, sizeof(TileItem*), cmp_tileitem);
1260 if ( dragging ) dragging->moveBy(-dragging_adj,0); 1260 if ( dragging ) dragging->moveBy(-dragging_adj,0);
1261 1261
1262 for (int i=0; i<n ;i++) 1262 for (int i=0; i<n ;i++)
1263 if ( item[i] == dragging ) { 1263 if ( item[i] == dragging ) {
1264 item[i]->setZ(1); 1264 item[i]->setZ(1);
1265 } else { 1265 } else {
1266 item[i]->move(i*w, 0); 1266 item[i]->move(i*w, 0);
1267 item[i]->setZ(0); 1267 item[i]->setZ(0);
1268 } 1268 }
1269 canvas()->update(); 1269 canvas()->update();
1270} 1270}
1271 1271
1272void Rack::setBlanks(const Tile* bv) 1272void Rack::setBlanks(const Tile* bv)
1273{ 1273{
1274 for (int j=0; j<n; j++) { 1274 for (int j=0; j<n; j++) {
1275 Tile tt = item[j]->tile(); 1275 Tile tt = item[j]->tile();
1276 if ( tt.isBlank() ) { 1276 if ( tt.isBlank() ) {
1277 tt.setText(bv->text()); 1277 tt.setText(bv->text());
1278 item[j]->setTile(tt); 1278 item[j]->setTile(tt);
1279 bv++; 1279 bv++;
1280 } 1280 }
1281 } 1281 }
1282} 1282}
1283 1283
1284bool Rack::arrangeTiles(const Tile** s, int sn) 1284bool Rack::arrangeTiles(const Tile** s, int sn)
1285{ 1285{
1286 bool could = TRUE; 1286 bool could = TRUE;
1287 for (int j=0; j<n; j++) { 1287 for (int j=0; j<n; j++) {
1288 Tile tt = item[j]->tile(); 1288 Tile tt = item[j]->tile();
1289 int f=-1; 1289 int f=-1;
1290 for (int i=0; i<sn && f<0; i++) { 1290 for (int i=0; i<sn && f<0; i++) {
1291 if (s[i] && *s[i] == tt ) { 1291 if (s[i] && *s[i] == tt ) {
1292 s[i]=0; 1292 s[i]=0;
1293 f=i; 1293 f=i;
1294 } 1294 }
1295 } 1295 }
1296 if ( f >= 0 ) { 1296 if ( f >= 0 ) {
1297 item[j]->move(f-999,0); 1297 item[j]->move(f-999,0);
1298 } else { 1298 } else {
1299 could = FALSE; 1299 could = FALSE;
1300 } 1300 }
1301 } 1301 }
1302 layoutTiles(); 1302 layoutTiles();
1303 return could; 1303 return could;
1304} 1304}
1305 1305
1306void Rack::addTile(const Tile& t) 1306void Rack::addTile(const Tile& t)
1307{ 1307{
1308 TileItem *i = new TileItem(t,TRUE,canvas()); 1308 TileItem *i = new TileItem(t,TRUE,canvas());
1309 i->show(); 1309 i->show();
1310 item[n++] = i; 1310 item[n++] = i;
1311 layoutTiles(); 1311 layoutTiles();
1312} 1312}
1313 1313
1314void Rack::remove(Tile t) 1314void Rack::remove(Tile t)
1315{ 1315{
1316 for (int i=0; i<n ;i++) 1316 for (int i=0; i<n ;i++)
1317 if ( item[i]->tile() == t ) { 1317 if ( item[i]->tile() == t ) {
1318 remove(i); 1318 remove(i);
1319 return; 1319 return;
1320 } 1320 }
1321} 1321}
1322 1322
1323void Rack::remove(int i) 1323void Rack::remove(int i)
1324{ 1324{
1325 delete item[i]; 1325 delete item[i];
1326 n--; 1326 n--;
1327 for (;i<n;i++) 1327 for (;i<n;i++)
1328 item[i]=item[i+1]; 1328 item[i]=item[i+1];
1329 layoutTiles(); 1329 layoutTiles();
1330} 1330}
1331 1331
1332void Rack::resizeEvent(QResizeEvent* e) 1332void Rack::resizeEvent(QResizeEvent* e)
1333{ 1333{
1334 canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2); 1334 canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2);
1335 QCanvasView::resizeEvent(e); 1335 QCanvasView::resizeEvent(e);
1336} 1336}
1337 1337
1338void Rack::contentsMousePressEvent(QMouseEvent* e) 1338void Rack::contentsMousePressEvent(QMouseEvent* e)
1339{ 1339{
1340 if ( computerized() ) 1340 if ( computerized() )
1341 return; 1341 return;
1342 QCanvasItemList list = canvas()->collisions(e->pos()); 1342 QCanvasItemList list = canvas()->collisions(e->pos());
1343 if (list.count()) { 1343 if (list.count()) {
1344 dragging = list.first(); 1344 dragging = list.first();
1345 dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y())); 1345 dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y()));
1346 } else { 1346 } else {
1347 dragging = 0; 1347 dragging = 0;
1348 } 1348 }
1349} 1349}
1350 1350
1351void Rack::contentsMouseMoveEvent(QMouseEvent* e) 1351void Rack::contentsMouseMoveEvent(QMouseEvent* e)
1352{ 1352{
1353 if ( computerized() ) 1353 if ( computerized() )
1354 return; 1354 return;
1355 //int w = TileItem::bigWidth()+2; 1355 //int w = TileItem::bigWidth()+2;
1356 if ( dragging ) { 1356 if ( dragging ) {
1357 dragging_adj = TileItem::bigWidth()/2; 1357 dragging_adj = TileItem::bigWidth()/2;
1358 if ( dragging->x() > e->x()-dragstart.x() ) 1358 if ( dragging->x() > e->x()-dragstart.x() )
1359 dragging_adj = -dragging_adj; 1359 dragging_adj = -dragging_adj;
1360 dragging->move(e->x()-dragstart.x(),0); 1360 dragging->move(e->x()-dragstart.x(),0);
1361 layoutTiles(); 1361 layoutTiles();
1362 } 1362 }
1363} 1363}
1364 1364
1365void Rack::contentsMouseReleaseEvent(QMouseEvent* e) 1365void Rack::contentsMouseReleaseEvent(QMouseEvent* e)
1366{ 1366{
1367 if ( computerized() ) 1367 if ( computerized() )
1368 return; 1368 return;
1369 if ( dragging ) { 1369 if ( dragging ) {
1370 dragging=0; 1370 dragging=0;
1371 layoutTiles(); 1371 layoutTiles();
1372 } 1372 }
1373} 1373}
1374 1374
1375Tile::Tile(const QString& key) 1375Tile::Tile(const QString& key)
1376{ 1376{
1377 int a=key.find('@'); 1377 int a=key.find('@');
1378 txt = key.left(a); 1378 txt = key.left(a);
1379 val = key.mid(a+1).toInt(); 1379 val = key.mid(a+1).toInt();
1380 blank = txt.isEmpty(); 1380 blank = txt.isEmpty();
1381} 1381}
1382 1382
1383QString Tile::key() const 1383QString Tile::key() const
1384{ 1384{
1385 return txt+"@"+QString::number(val); 1385 return txt+"@"+QString::number(val);
1386} 1386}
1387 1387
1388Bag::Bag() 1388Bag::Bag()
1389{ 1389{
1390 tiles.setAutoDelete(TRUE); 1390 tiles.setAutoDelete(TRUE);
1391} 1391}
1392 1392
1393void Bag::writeConfig(Config& cfg) 1393void Bag::writeConfig(Config& cfg)
1394{ 1394{
1395 QStringList t; 1395 QStringList t;
1396 for (QListIterator<Tile> it(tiles); it; ++it) 1396 for (QListIterator<Tile> it(tiles); it; ++it)
1397 t.append((*it)->key()); 1397 t.append((*it)->key());
1398 cfg.writeEntry("Tiles",t,';'); 1398 cfg.writeEntry("Tiles",t,';');
1399} 1399}
1400 1400
1401void Bag::readConfig(Config& cfg) 1401void Bag::readConfig(Config& cfg)
1402{ 1402{
1403 tiles.clear(); 1403 tiles.clear();
1404 QStringList t = cfg.readListEntry("Tiles",';'); 1404 QStringList t = cfg.readListEntry("Tiles",';');
1405 for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it ) 1405 for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it )
1406 add(Tile(*it)); 1406 add(Tile(*it));
1407} 1407}
1408 1408
1409void Bag::add(const Tile& t) 1409void Bag::add(const Tile& t)
1410{ 1410{
1411 tiles.append(new Tile(t)); 1411 tiles.append(new Tile(t));
1412} 1412}
1413 1413
1414Tile Bag::takeRandom() 1414Tile Bag::takeRandom()
1415{ 1415{
1416 Tile* rp = tiles.take(random()%tiles.count()); 1416 Tile* rp = tiles.take(random()%tiles.count());
1417 Tile r=*rp; 1417 Tile r=*rp;
1418 return r; 1418 return r;
1419} 1419}
1420 1420
1421ScoreInfo::ScoreInfo( QWidget* parent, const char* name, WFlags fl ) : 1421ScoreInfo::ScoreInfo( QWidget* parent, const char* name, WFlags fl ) :
1422 QLabel("<P>",parent,name,fl) 1422 QLabel("<P>",parent,name,fl)
1423{ 1423{
1424 score=0; 1424 score=0;
1425 msgtimer = new QTimer(this); 1425 msgtimer = new QTimer(this);
1426 connect(msgtimer, SIGNAL(timeout()), this, SLOT(showScores())); 1426 connect(msgtimer, SIGNAL(timeout()), this, SLOT(showScores()));
1427 setBackgroundMode( PaletteButton ); 1427 setBackgroundMode( PaletteButton );
1428} 1428}
1429 1429
1430ScoreInfo::~ScoreInfo() 1430ScoreInfo::~ScoreInfo()
1431{ 1431{
1432 if ( score ) delete [] score; 1432 if ( score ) delete [] score;
1433} 1433}
1434 1434
1435void ScoreInfo::writeConfig(Config& cfg) 1435void ScoreInfo::writeConfig(Config& cfg)
1436{ 1436{
1437 QStringList l; 1437 QStringList l;
1438 for (int i=0; i<(int)names.count(); i++) 1438 for (int i=0; i<(int)names.count(); i++)
1439 l.append(QString::number(score[i])); 1439 l.append(QString::number(score[i]));
1440 cfg.writeEntry("Scores",l,';'); 1440 cfg.writeEntry("Scores",l,';');
1441} 1441}
1442 1442
1443void ScoreInfo::readConfig(Config& cfg) 1443void ScoreInfo::readConfig(Config& cfg)
1444{ 1444{
1445 QStringList l = cfg.readListEntry("Scores",';'); 1445 QStringList l = cfg.readListEntry("Scores",';');
1446 int i=0; 1446 int i=0;
1447 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it ) 1447 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it )
1448 score[i++]=(*it).toInt(); 1448 score[i++]=(*it).toInt();
1449 showScores(); 1449 showScores();
1450} 1450}
1451 1451
1452 1452
1453QSize ScoreInfo::sizeHint() const 1453QSize ScoreInfo::sizeHint() const
1454{ 1454{
1455 return QSize(QLabel::sizeHint().width(),fontMetrics().height()); 1455 return QSize(QLabel::sizeHint().width(),fontMetrics().height());
1456} 1456}
1457 1457
1458void ScoreInfo::init(const QStringList& namelist) 1458void ScoreInfo::init(const QStringList& namelist)
1459{ 1459{
1460 names = namelist; 1460 names = namelist;
1461 if ( score ) delete [] score; 1461 if ( score ) delete [] score;
1462 score = new int[names.count()]; 1462 score = new int[names.count()];
1463 memset(score,0,sizeof(int)*names.count()); 1463 memset(score,0,sizeof(int)*names.count());
1464 boldone = -1; 1464 boldone = -1;
1465 showScores(); 1465 showScores();
1466} 1466}
1467 1467
1468void ScoreInfo::addScore(int player, int change) 1468void ScoreInfo::addScore(int player, int change)
1469{ 1469{
1470 score[player] += change; 1470 score[player] += change;
1471 showScores(); 1471 showScores();
1472} 1472}
1473 1473
1474void ScoreInfo::setBoldOne(int b) 1474void ScoreInfo::setBoldOne(int b)
1475{ 1475{
1476 boldone=b; 1476 boldone=b;
1477 showScores(); 1477 showScores();
1478} 1478}
1479 1479
1480void ScoreInfo::showScores() 1480void ScoreInfo::showScores()
1481{ 1481{
1482 QString r="<p>"; 1482 QString r="<p>";
1483 int i=0; 1483 int i=0;
1484 //int spl=(names.count()+1)/2; // 2 lines 1484 //int spl=(names.count()+1)/2; // 2 lines
1485 for (QStringList::ConstIterator it=names.begin(); it!=names.end(); ) { 1485 for (QStringList::ConstIterator it=names.begin(); it!=names.end(); ) {
1486 if ( i==boldone ) r += "<b>"; 1486 if ( i==boldone ) r += "<b>";
1487 QString n = *it; 1487 QString n = *it;
1488 n.replace(QRegExp(":.*"),""); 1488 n.replace(QRegExp(":.*"),"");
1489 r += n; 1489 r += n;
1490 r += ":"; 1490 r += ":";
1491 r += QString::number(score[i]); 1491 r += QString::number(score[i]);
1492 if ( i==boldone ) r += "</b>"; 1492 if ( i==boldone ) r += "</b>";
1493 1493
1494 ++i; 1494 ++i;
1495 ++it; 1495 ++it;
1496 if ( it != names.end() ) 1496 if ( it != names.end() )
1497 r += " "; 1497 r += " ";
1498 } 1498 }
1499 setText(r); 1499 setText(r);
1500} 1500}
1501 1501
1502void ScoreInfo::showTemporaryScore(int amount) 1502void ScoreInfo::showTemporaryScore(int amount)
1503{ 1503{
1504 if ( amount < 0 ) 1504 if ( amount < 0 )
1505 setText(tr("<P>Invalid move")); 1505 setText(tr("<P>Invalid move"));
1506 else 1506 else
1507 setText(tr("<P>Score: ")+QString::number(amount)); 1507 setText(tr("<P>Score: ")+QString::number(amount));
1508 msgtimer->start(3000,TRUE); 1508 msgtimer->start(3000,TRUE);
1509} 1509}
1510 1510
diff --git a/noncore/games/zlines/main.cpp b/noncore/games/zlines/main.cpp
index d1709e4..8d80bae 100644
--- a/noncore/games/zlines/main.cpp
+++ b/noncore/games/zlines/main.cpp
@@ -1,28 +1,29 @@
1/*************************************************************************** 1/***************************************************************************
2 main.cpp - description 2 main.cpp - description
3 ------------------- 3 -------------------
4 begin : Fri May 19 2000 4 begin : Fri May 19 2000
5 copyright : (C) 2000 by Roman Merzlyakov 5 copyright : (C) 2000 by Roman Merzlyakov
6 email : roman@sbrf.barrt.ru 6 email : roman@sbrf.barrt.ru
7 copyright : (C) 2000 by Roman Razilov 7 copyright : (C) 2000 by Roman Razilov
8 email : Roman.Razilov@gmx.de 8 email : Roman.Razilov@gmx.de
9 ***************************************************************************/ 9 ***************************************************************************/
10 10
11/*************************************************************************** 11/***************************************************************************
12 * * 12 * *
13 * This program is free software; you can redistribute it and/or modify * 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 * 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 * 15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. * 16 * (at your option) any later version. *
17 * * 17 * *
18 ***************************************************************************/ 18 ***************************************************************************/
19 /* 19 /*
20 * Roman Razilov 2000-05-19 debug dummmy 20 * Roman Razilov 2000-05-19 debug dummmy
21 * Roman Razilov 2000-05-21 qimgio 21 * Roman Razilov 2000-05-21 qimgio
22*/ 22*/
23 23
24#include "klines.h" 24#include "klines.h"
25 25
26#include <opie2/oapplicationfactory.h> 26#include <opie2/oapplicationfactory.h>
27 27
28using namespace Opie::Core;
28OPIE_EXPORT_APP( OApplicationFactory<KLines> ) 29OPIE_EXPORT_APP( OApplicationFactory<KLines> )
diff --git a/noncore/games/zsame/ZSameWidget.cpp b/noncore/games/zsame/ZSameWidget.cpp
index 3c58c93..4fab0f6 100644
--- a/noncore/games/zsame/ZSameWidget.cpp
+++ b/noncore/games/zsame/ZSameWidget.cpp
@@ -1,243 +1,244 @@
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;
43OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> ) 44OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> )
44 45
45 46
46 47
47ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl ) 48ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl )
48 : QMainWindow( parent, name, fl ) 49 : QMainWindow( parent, name, fl )
49{ 50{
50 setCaption(tr("ZSame")); 51 setCaption(tr("ZSame"));
51 52
52 setToolBarsMovable( false ); 53 setToolBarsMovable( false );
53 QToolBar* con = new QToolBar( this ); 54 QToolBar* con = new QToolBar( this );
54 con->setHorizontalStretchable( true ); 55 con->setHorizontalStretchable( true );
55 QMenuBar* mb = new QMenuBar( con ); 56 QMenuBar* mb = new QMenuBar( con );
56 QToolBar* tb = new QToolBar( this ); 57 QToolBar* tb = new QToolBar( this );
57 58
58 QPopupMenu* fileMenu = new QPopupMenu( this ); 59 QPopupMenu* fileMenu = new QPopupMenu( this );
59 60
60 QAction* a = new QAction(tr("New Game"), Resource::loadIconSet("new") , 61 QAction* a = new QAction(tr("New Game"), Resource::loadIconSet("new") ,
61 QString::null, 0, this, "new_icon"); 62 QString::null, 0, this, "new_icon");
62 a->addTo( fileMenu ); 63 a->addTo( fileMenu );
63 a->addTo( tb ); 64 a->addTo( tb );
64 connect(a, SIGNAL(activated()), this, SLOT(m_new())); 65 connect(a, SIGNAL(activated()), this, SLOT(m_new()));
65 66
66 a = new QAction(tr("Restart This Board"), Resource::loadIconSet("redo"), 67 a = new QAction(tr("Restart This Board"), Resource::loadIconSet("redo"),
67 QString::null, 0, this, "restart_board" ); 68 QString::null, 0, this, "restart_board" );
68 a->addTo( fileMenu ); 69 a->addTo( fileMenu );
69 connect( a, SIGNAL(activated()), this, SLOT(m_restart())); 70 connect( a, SIGNAL(activated()), this, SLOT(m_restart()));
70 restart = a; 71 restart = a;
71 72
72 a = new QAction( tr("Undo"), Resource::loadIconSet("undo"), 73 a = new QAction( tr("Undo"), Resource::loadIconSet("undo"),
73 QString::null, 0, this, "undo_action" ); 74 QString::null, 0, this, "undo_action" );
74 a->addTo( fileMenu ); 75 a->addTo( fileMenu );
75 a->addTo( tb ); 76 a->addTo( tb );
76 connect( a, SIGNAL(activated()), this, SLOT(m_undo())); 77 connect( a, SIGNAL(activated()), this, SLOT(m_undo()));
77 78
78 a = new QAction(tr("Quit"), Resource::loadIconSet("quit_icon"), 79 a = new QAction(tr("Quit"), Resource::loadIconSet("quit_icon"),
79 QString::null, 0, this, "quit_action"); 80 QString::null, 0, this, "quit_action");
80 a->addTo( fileMenu ); 81 a->addTo( fileMenu );
81 a->addTo( tb ); 82 a->addTo( tb );
82 connect(a, SIGNAL(activated()), this, SLOT(m_quit())); 83 connect(a, SIGNAL(activated()), this, SLOT(m_quit()));
83 84
84 mb->insertItem(tr("Game" ), fileMenu ); 85 mb->insertItem(tr("Game" ), fileMenu );
85 86
86 int foo[2]; 87 int foo[2];
87 desktop_widget(foo); 88 desktop_widget(foo);
88 stone = new StoneWidget(this,foo[0],foo[1]); 89 stone = new StoneWidget(this,foo[0],foo[1]);
89 90
90 connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover())); 91 connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover()));
91 92
92 connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int))); 93 connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int)));
93 connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int))); 94 connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int)));
94 connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int))); 95 connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int)));
95 connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int))); 96 connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int)));
96 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)));
97 98
98 connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged())); 99 connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged()));
99 100
100 sizeChanged(); 101 sizeChanged();
101 setCentralWidget(stone); 102 setCentralWidget(stone);
102 103
103 104
104 setScore(0); 105 setScore(0);
105} 106}
106 107
107ZSameWidget::~ZSameWidget() { 108ZSameWidget::~ZSameWidget() {
108 109
109} 110}
110 111
111void ZSameWidget::readProperties(Config *conf) { 112void ZSameWidget::readProperties(Config *conf) {
112/* 113/*
113 Q_ASSERT(conf); 114 Q_ASSERT(conf);
114 stone->readProperties(conf); 115 stone->readProperties(conf);
115*/ 116*/
116} 117}
117 118
118void ZSameWidget::saveProperties(Config *conf) { 119void ZSameWidget::saveProperties(Config *conf) {
119/* 120/*
120 Q_ASSERT(conf); 121 Q_ASSERT(conf);
121 stone->saveProperties(conf); 122 stone->saveProperties(conf);
122 conf->sync(); 123 conf->sync();
123*/ 124*/
124} 125}
125 126
126void ZSameWidget::sizeChanged() { 127void ZSameWidget::sizeChanged() {
127 //stone->setFixedSize(stone->sizeHint()); 128 //stone->setFixedSize(stone->sizeHint());
128} 129}
129 130
130void ZSameWidget::newGame(unsigned int board,int colors) { 131void ZSameWidget::newGame(unsigned int board,int colors) {
131 while (board>=1000000) board-=1000000; 132 while (board>=1000000) board-=1000000;
132 // kdDebug() << "newgame board " << board << " colors " << colors << endl; 133 // kdDebug() << "newgame board " << board << " colors " << colors << endl;
133 stone->newGame(board,colors); 134 stone->newGame(board,colors);
134 setScore(0); 135 setScore(0);
135} 136}
136 137
137bool ZSameWidget::confirmAbort() { 138bool ZSameWidget::confirmAbort() {
138 return stone->isGameover() || 139 return stone->isGameover() ||
139 stone->isOriginalBoard() || 140 stone->isOriginalBoard() ||
140 (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>"),
141 QMessageBox::Yes, 142 QMessageBox::Yes,
142 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes ); 143 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes );
143} 144}
144 145
145void ZSameWidget::m_new() { 146void ZSameWidget::m_new() {
146 if (confirmAbort()) 147 if (confirmAbort())
147 newGame(_random(),default_colors); 148 newGame(_random(),default_colors);
148 149
149} 150}
150 151
151void ZSameWidget::m_restart() { 152void ZSameWidget::m_restart() {
152 if (confirmAbort()) 153 if (confirmAbort())
153 newGame(stone->board(),default_colors); 154 newGame(stone->board(),default_colors);
154} 155}
155 156
156void ZSameWidget::m_load() { 157void ZSameWidget::m_load() {
157// kdDebug() << "menu load not supported" << endl; 158// kdDebug() << "menu load not supported" << endl;
158} 159}
159 160
160void ZSameWidget::m_save() { 161void ZSameWidget::m_save() {
161// kdDebug() << "menu save not supported" << endl; 162// kdDebug() << "menu save not supported" << endl;
162} 163}
163 164
164void ZSameWidget::m_undo() { 165void ZSameWidget::m_undo() {
165 //Q_ASSERT(stone); 166 //Q_ASSERT(stone);
166 stone->undo(); 167 stone->undo();
167} 168}
168 169
169 170
170void ZSameWidget::m_showhs() { 171void ZSameWidget::m_showhs() {
171/* Q_ASSERT(stone); 172/* Q_ASSERT(stone);
172 stone->unmark(); 173 stone->unmark();
173 KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this); 174 KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this);
174 d.addField(Board, i18n("Board"), "Board"); 175 d.addField(Board, i18n("Board"), "Board");
175 d.exec(); 176 d.exec();
176*/ 177*/
177} 178}
178 179
179void ZSameWidget::m_quit() { 180void ZSameWidget::m_quit() {
180// Q_ASSERT(stone); 181// Q_ASSERT(stone);
181 stone->unmark(); 182 stone->unmark();
182 qApp->quit(); 183 qApp->quit();
183// delete this; 184// delete this;
184} 185}
185 186
186void ZSameWidget::m_tglboard() { 187void ZSameWidget::m_tglboard() {
187 //kdDebug() << "toggled" << endl; 188 //kdDebug() << "toggled" << endl;
188} 189}
189 190
190 191
191void ZSameWidget::setColors(int colors) { 192void ZSameWidget::setColors(int colors) {
192 //status->changeItem(i18n("%1 Colors").arg(colors),1); 193 //status->changeItem(i18n("%1 Colors").arg(colors),1);
193} 194}
194 195
195void ZSameWidget::setBoard(int board) { 196void ZSameWidget::setBoard(int board) {
196 //status->changeItem(i18n("Board: %1").arg(board, 6), 2); 197 //status->changeItem(i18n("Board: %1").arg(board, 6), 2);
197} 198}
198 199
199void ZSameWidget::setMarked(int m) { 200void ZSameWidget::setMarked(int m) {
200// status->changeItem(i18n("Marked: %1").arg(m, 6),3); 201// status->changeItem(i18n("Marked: %1").arg(m, 6),3);
201} 202}
202 203
203void ZSameWidget::stonesRemoved(int,int) { 204void ZSameWidget::stonesRemoved(int,int) {
204 //KNotifyClient::event("stones removed", 205 //KNotifyClient::event("stones removed",
205 // i18n("%1 stones removed.").arg(stone->marked())); 206 // i18n("%1 stones removed.").arg(stone->marked()));
206} 207}
207 208
208void ZSameWidget::setScore(int score) { 209void ZSameWidget::setScore(int score) {
209// status->changeItem(i18n("Score: %1").arg(score, 6),4); 210// status->changeItem(i18n("Score: %1").arg(score, 6),4);
210// undo->setEnabled(stone->undoPossible()); 211// undo->setEnabled(stone->undoPossible());
211// restart->setEnabled(!stone->isOriginalBoard()); 212// restart->setEnabled(!stone->isOriginalBoard());
212} 213}
213 214
214void ZSameWidget::gameover() { 215void ZSameWidget::gameover() {
215// kdDebug() << "GameOver" << endl; 216// kdDebug() << "GameOver" << endl;
216 if (stone->hasBonus()) { 217 if (stone->hasBonus()) {
217 QMessageBox::information(this,i18n("Game won"), 218 QMessageBox::information(this,i18n("Game won"),
218 i18n("<qt>You even removed the last stone, great job! " 219 i18n("<qt>You even removed the last stone, great job! "
219 "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()));
220 } else { 221 } else {
221 QMessageBox::information(this,i18n("Game over"), 222 QMessageBox::information(this,i18n("Game over"),
222 i18n("<qt>There are no more removeable stones. " 223 i18n("<qt>There are no more removeable stones. "
223 "You got a score of %1 in total.</qt>").arg(stone->score())); 224 "You got a score of %1 in total.</qt>").arg(stone->score()));
224 } 225 }
225 stone->unmark(); 226 stone->unmark();
226} 227}
227 228
228void ZSameWidget::desktop_widget(int *f)const{ 229void ZSameWidget::desktop_widget(int *f)const{
229 230
230 QWidget* wid = QApplication::desktop(); 231 QWidget* wid = QApplication::desktop();
231 /* width > height landscape mode */ 232 /* width > height landscape mode */
232 if ( wid->width() > wid->height() ) { 233 if ( wid->width() > wid->height() ) {
233 f[0]=15; 234 f[0]=15;
234 f[1]=9; 235 f[1]=9;
235 } 236 }
236 /* normal */ 237 /* normal */
237 else{ 238 else{
238 f[0]=12; 239 f[0]=12;
239 f[1]=13; 240 f[1]=13;
240 } 241 }
241} 242}
242 243
243 244