summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-11-03 23:05:29 (UTC)
committer mickeyl <mickeyl>2003-11-03 23:05:29 (UTC)
commit8046118c7d4def83ef1a70628870b5ebad0534a4 (patch) (unidiff)
tree21f03403f1f4d42d72eace822511e084580a8772
parent7f34e7b45108c353e0a2575153904ce655cb1896 (diff)
downloadopie-8046118c7d4def83ef1a70628870b5ebad0534a4.zip
opie-8046118c7d4def83ef1a70628870b5ebad0534a4.tar.gz
opie-8046118c7d4def83ef1a70628870b5ebad0534a4.tar.bz2
noncore/games/tictac now fully merged
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/tictac/main.cpp6
-rw-r--r--noncore/games/tictac/tictac.cpp7
-rw-r--r--noncore/games/tictac/tictac.h7
-rw-r--r--noncore/games/tictac/tictac.pro9
4 files changed, 12 insertions, 17 deletions
diff --git a/noncore/games/tictac/main.cpp b/noncore/games/tictac/main.cpp
index 0185b8c..cfff683 100644
--- a/noncore/games/tictac/main.cpp
+++ b/noncore/games/tictac/main.cpp
@@ -1,19 +1,13 @@
1/**************************************************************************** 1/****************************************************************************
2<<<<<<< main.cpp
3** $Id$
4=======
5** $Id$
6>>>>>>> 1.1.8.1.2.1
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 2** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 3**
10** 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
11** program may be used, distributed and modified without limitation. 5** program may be used, distributed and modified without limitation.
12** 6**
13*****************************************************************************/ 7*****************************************************************************/
14 8
15#include <qpe/qpeapplication.h> 9#include <qpe/qpeapplication.h>
16#include <opie/oapplicationfactory.h> 10#include <opie/oapplicationfactory.h>
17#include "tictac.h" 11#include "tictac.h"
18 12
19OPIE_EXPORT_APP( OApplicationFactory<TicTacToe> ) 13OPIE_EXPORT_APP( OApplicationFactory<TicTacToe> )
diff --git a/noncore/games/tictac/tictac.cpp b/noncore/games/tictac/tictac.cpp
index 3d727ac..4954ba4 100644
--- a/noncore/games/tictac/tictac.cpp
+++ b/noncore/games/tictac/tictac.cpp
@@ -1,98 +1,98 @@
1/**************************************************************************** 1/****************************************************************************
2 ** $Id$ 2 ** tictac.cpp,v 1.3.8.1 2003/08/29 06:50:40 harlekin Exp
3 ** 3 **
4 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5 ** 5 **
6 ** This file is part of an example program for Qt. This example 6 ** This file is part of an example program for Qt. This example
7 ** program may be used, distributed and modified without limitation. 7 ** program may be used, distributed and modified without limitation.
8 ** 8 **
9 *****************************************************************************/ 9 *****************************************************************************/
10 10
11#include "tictac.h" 11#include "tictac.h"
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13#include <qpainter.h> 13#include <qpainter.h>
14#include <qdrawutil.h> 14#include <qdrawutil.h>
15#include <qcombobox.h> 15#include <qcombobox.h>
16#include <qcheckbox.h> 16#include <qcheckbox.h>
17#include <qlabel.h> 17#include <qlabel.h>
18#include <qlayout.h> 18#include <qlayout.h>
19#include <stdlib.h> // rand() function 19#include <stdlib.h> // rand() function
20#include <qdatetime.h> // seed for rand() 20#include <qdatetime.h> // seed for rand()
21#include <qstringlist.h> //needed for proper internationalization 21#include <qstringlist.h> //needed for proper internationalization
22 22
23 23
24//*************************************************************************** 24//***************************************************************************
25//* TicTacButton member functions 25//* TicTacButton member functions
26//*************************************************************************** 26//***************************************************************************
27 27
28// -------------------------------------------------------------------------- 28// --------------------------------------------------------------------------
29// Creates a TicTacButton 29// Creates a TicTacButton
30// 30//
31 31
32TicTacButton::TicTacButton( QWidget *parent ) : QPushButton( parent ) 32TicTacButton::TicTacButton( QWidget *parent ) : QPushButton( parent )
33{ 33{
34 t = Blank; // initial type 34 t = Blank; // initial type
35} 35}
36 36
37// -------------------------------------------------------------------------- 37// --------------------------------------------------------------------------
38// Paints TicTacButton 38// Paints TicTacButton
39// 39//
40 40
41void TicTacButton::drawButtonLabel( QPainter *p ) 41void TicTacButton::drawButtonLabel( QPainter *p )
42{ 42{
43 QRect r = rect(); 43 QRect r = rect();
44 p->setPen( QPen( white,2 ) ); // set fat pen 44 p->setPen( QPen( white,2 ) ); // set fat pen
45 if ( t == Circle ) { 45 if ( t == Circle ) {
46 p->drawEllipse( r.left()+4, r.top()+4, r.width()-8, r.height()-8 ); 46 p->drawEllipse( r.left()+4, r.top()+4, r.width()-8, r.height()-8 );
47 } else if ( t == Cross ) { // draw cross 47 } else if ( t == Cross ) { // draw cross
48 p->drawLine( r.topLeft() +QPoint(4,4), r.bottomRight()-QPoint(4,4)); 48 p->drawLine( r.topLeft() +QPoint(4,4), r.bottomRight()-QPoint(4,4));
49 p->drawLine( r.bottomLeft()+QPoint(4,-4),r.topRight() -QPoint(4,-4)); 49 p->drawLine( r.bottomLeft()+QPoint(4,-4),r.topRight() -QPoint(4,-4));
50 } 50 }
51} 51}
52 52
53 53
54//*************************************************************************** 54//***************************************************************************
55//* TicTacGameBoard member functions 55//* TicTacGameBoard member functions
56//*************************************************************************** 56//***************************************************************************
57 57
58// -------------------------------------------------------------------------- 58// --------------------------------------------------------------------------
59// Creates a game board with N x N buttons and connects the "clicked()" 59// Creates a game board with N x N buttons and connects the "clicked()"
60// signal of all buttons to the "buttonClicked()" slot. 60// signal of all buttons to the "buttonClicked()" slot.
61// 61//
62 62
63TicTacGameBoard::TicTacGameBoard( int n, QWidget *parent, const char *name ) 63TicTacGameBoard::TicTacGameBoard( int n, QWidget *parent, const char *name )
64 : QWidget( parent, name ) 64 : QWidget( parent, name )
65{ 65{
66 showMaximized(); 66 showMaximized();
67 st = Init; // initial state 67 st = Init; // initial state
68 nBoard = n; 68 nBoard = n;
69 n *= n; // make square 69 n *= n; // make square
70 comp_starts = FALSE; // human starts 70 comp_starts = FALSE; // human starts
71 buttons = new TicTacButtons(n); // create real buttons 71 buttons = new TicTacButtons(n); // create real buttons
72 btArray = new TicTacArray(n); // create button model 72 btArray = new TicTacArray(n); // create button model
73 QGridLayout * grid = new QGridLayout( this, 3, 3, 4 ); 73 QGridLayout * grid = new QGridLayout( this, 3, 3, 4 );
74 QPalette p( blue ); 74 QPalette p( blue );
75 for ( int i=0; i<n; i++ ) { // create and connect buttons 75 for ( int i=0; i<n; i++ ) { // create and connect buttons
76 TicTacButton *ttb = new TicTacButton( this ); 76 TicTacButton *ttb = new TicTacButton( this );
77 ttb->setPalette( p ); 77 ttb->setPalette( p );
78 ttb->setEnabled( FALSE ); 78 ttb->setEnabled( FALSE );
79 connect( ttb, SIGNAL(clicked()), SLOT(buttonClicked()) ); 79 connect( ttb, SIGNAL(clicked()), SLOT(buttonClicked()) );
80 grid->addWidget( ttb, i%3, i/3 ); 80 grid->addWidget( ttb, i%3, i/3 );
81 buttons->insert( i, ttb ); 81 buttons->insert( i, ttb );
82 btArray->at(i) = TicTacButton::Blank; // initial button type 82 btArray->at(i) = TicTacButton::Blank; // initial button type
83 } 83 }
84 QTime t = QTime::currentTime(); // set random seed 84 QTime t = QTime::currentTime(); // set random seed
85 srand( t.hour()*12+t.minute()*60+t.second()*60 ); 85 srand( t.hour()*12+t.minute()*60+t.second()*60 );
86} 86}
87 87
88TicTacGameBoard::~TicTacGameBoard() 88TicTacGameBoard::~TicTacGameBoard()
89{ 89{
90 delete buttons; 90 delete buttons;
91 delete btArray; 91 delete btArray;
92} 92}
93 93
94 94
95// -------------------------------------------------------------------------- 95// --------------------------------------------------------------------------
96// TicTacGameBoard::computerStarts( bool v ) 96// TicTacGameBoard::computerStarts( bool v )
97// 97//
98// Computer starts if v=TRUE. The human starts by default. 98// Computer starts if v=TRUE. The human starts by default.
@@ -195,187 +195,188 @@ int TicTacGameBoard::checkBoard( TicTacArray *a )
195 for ( col=0; col<nBoard && !won; col++ ) { // check vertical 195 for ( col=0; col<nBoard && !won; col++ ) { // check vertical
196 t = a->at(col); 196 t = a->at(col);
197 if ( t == TicTacButton::Blank ) 197 if ( t == TicTacButton::Blank )
198 continue; 198 continue;
199 row = 1; 199 row = 1;
200 while ( row<nBoard && a->at(row*nBoard+col) == t ) 200 while ( row<nBoard && a->at(row*nBoard+col) == t )
201 row++; 201 row++;
202 if ( row == nBoard ) 202 if ( row == nBoard )
203 won = TRUE; 203 won = TRUE;
204 } 204 }
205 if ( !won ) { // check diagonal top left 205 if ( !won ) { // check diagonal top left
206 t = a->at(0); // to bottom right 206 t = a->at(0); // to bottom right
207 if ( t != TicTacButton::Blank ) { 207 if ( t != TicTacButton::Blank ) {
208 int i = 1; 208 int i = 1;
209 while ( i<nBoard && a->at(i*nBoard+i) == t ) 209 while ( i<nBoard && a->at(i*nBoard+i) == t )
210 i++; 210 i++;
211 if ( i == nBoard ) 211 if ( i == nBoard )
212 won = TRUE; 212 won = TRUE;
213 } 213 }
214 } 214 }
215 if ( !won ) { // check diagonal bottom left 215 if ( !won ) { // check diagonal bottom left
216 int j = nBoard-1; // to top right 216 int j = nBoard-1; // to top right
217 int i = 0; 217 int i = 0;
218 t = a->at(i+j*nBoard); 218 t = a->at(i+j*nBoard);
219 if ( t != TicTacButton::Blank ) { 219 if ( t != TicTacButton::Blank ) {
220 i++; j--; 220 i++; j--;
221 while ( i<nBoard && a->at(i+j*nBoard) == t ) { 221 while ( i<nBoard && a->at(i+j*nBoard) == t ) {
222 i++; j--; 222 i++; j--;
223 } 223 }
224 if ( i == nBoard ) 224 if ( i == nBoard )
225 won = TRUE; 225 won = TRUE;
226 } 226 }
227 } 227 }
228 if ( !won ) // no winner 228 if ( !won ) // no winner
229 t = 0; 229 t = 0;
230 return t; 230 return t;
231} 231}
232 232
233 233
234// -------------------------------------------------------------------------- 234// --------------------------------------------------------------------------
235// TicTacGameBoard::computerMove() 235// TicTacGameBoard::computerMove()
236// 236//
237// Puts a piece on the game board. Very, very simple. 237// Puts a piece on the game board. Very, very simple.
238// 238//
239 239
240void TicTacGameBoard::computerMove() 240void TicTacGameBoard::computerMove()
241{ 241{
242 int numButtons = nBoard*nBoard; 242 int numButtons = nBoard*nBoard;
243 int *altv = new int[numButtons]; // buttons alternatives 243 int *altv = new int[numButtons]; // buttons alternatives
244 int altc = 0; 244 int altc = 0;
245 int stopHuman = -1; 245 int stopHuman = -1;
246 TicTacArray a = btArray->copy(); 246 TicTacArray a = btArray->copy();
247 int i; 247 int i;
248 for ( i=0; i<numButtons; i++ ) { // try all positions 248 for ( i=0; i<numButtons; i++ ) { // try all positions
249 if ( a[i] != TicTacButton::Blank ) // already a piece there 249 if ( a[i] != TicTacButton::Blank ) // already a piece there
250 continue; 250 continue;
251 a[i] = TicTacButton::Cross; // test if computer wins 251 a[i] = TicTacButton::Cross; // test if computer wins
252 if ( checkBoard(&a) == a[i] ) { // computer will win 252 if ( checkBoard(&a) == a[i] ) { // computer will win
253 st = ComputerWon; 253 st = ComputerWon;
254 stopHuman = -1; 254 stopHuman = -1;
255 break; 255 break;
256 } 256 }
257 a[i] = TicTacButton::Circle; // test if human wins 257 a[i] = TicTacButton::Circle; // test if human wins
258 if ( checkBoard(&a) == a[i] ) { // oops... 258 if ( checkBoard(&a) == a[i] ) { // oops...
259 stopHuman = i; // remember position 259 stopHuman = i; // remember position
260 a[i] = TicTacButton::Blank; // restore button 260 a[i] = TicTacButton::Blank; // restore button
261 continue; // computer still might win 261 continue; // computer still might win
262 } 262 }
263 a[i] = TicTacButton::Blank; // restore button 263 a[i] = TicTacButton::Blank; // restore button
264 altv[altc++] = i; // remember alternative 264 altv[altc++] = i; // remember alternative
265 } 265 }
266 if ( stopHuman >= 0 ) // must stop human from winning 266 if ( stopHuman >= 0 ) // must stop human from winning
267 a[stopHuman] = TicTacButton::Cross; 267 a[stopHuman] = TicTacButton::Cross;
268 else if ( i == numButtons ) { // tried all alternatives 268 else if ( i == numButtons ) { // tried all alternatives
269 if ( altc > 0 ) // set random piece 269 if ( altc > 0 ) // set random piece
270 a[altv[rand()%(altc--)]] = TicTacButton::Cross; 270 a[altv[rand()%(altc--)]] = TicTacButton::Cross;
271 if ( altc == 0 ) { // no more blanks 271 if ( altc == 0 ) { // no more blanks
272 st = NobodyWon; 272 st = NobodyWon;
273 emit finished(); 273 emit finished();
274 } 274 }
275 } 275 }
276 *btArray = a; // update model 276 *btArray = a; // update model
277 updateButtons(); // update buttons 277 updateButtons(); // update buttons
278 delete[] altv; 278 delete[] altv;
279} 279}
280 280
281 281
282//*************************************************************************** 282//***************************************************************************
283//* TicTacToe member functions 283//* TicTacToe member functions
284//*************************************************************************** 284//***************************************************************************
285 285
286// -------------------------------------------------------------------------- 286// --------------------------------------------------------------------------
287// Creates a game widget with a game board and two push buttons, and connects 287// Creates a game widget with a game board and two push buttons, and connects
288// signals of child widgets to slots. 288// signals of child widgets to slots.
289// 289//
290 290
291TicTacToe::TicTacToe( int boardSize, QWidget *parent, const char *name ) 291TicTacToe::TicTacToe( QWidget *parent, const char *name, WFlags fl )
292 : QWidget( parent, name ) 292 : QWidget( parent, name, fl )
293{ 293{
294 QVBoxLayout * l = new QVBoxLayout( this, 6 ); 294 QVBoxLayout * l = new QVBoxLayout( this, 6 );
295 295
296 // Create a message label 296 // Create a message label
297 boardSize = 3;
297 298
298 message = new QLabel( this ); 299 message = new QLabel( this );
299 message->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 300 message->setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
300 message->setAlignment( AlignCenter ); 301 message->setAlignment( AlignCenter );
301 l->addWidget( message ); 302 l->addWidget( message );
302 303
303 // Create the game board and connect the signal finished() to this 304 // Create the game board and connect the signal finished() to this
304 // gameOver() slot 305 // gameOver() slot
305 306
306 board = new TicTacGameBoard( boardSize, this ); 307 board = new TicTacGameBoard( boardSize, this );
307 connect( board, SIGNAL(finished()), SLOT(gameOver()) ); 308 connect( board, SIGNAL(finished()), SLOT(gameOver()) );
308 l->addWidget( board ); 309 l->addWidget( board );
309 310
310 // Create a horizontal frame line 311 // Create a horizontal frame line
311 312
312 QFrame *line = new QFrame( this ); 313 QFrame *line = new QFrame( this );
313 line->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 314 line->setFrameStyle( QFrame::HLine | QFrame::Sunken );
314 l->addWidget( line ); 315 l->addWidget( line );
315 316
316 // Create the combo box for deciding who should start, and 317 // Create the combo box for deciding who should start, and
317 // connect its clicked() signals to the buttonClicked() slot 318 // connect its clicked() signals to the buttonClicked() slot
318 319
319 whoStarts = new QComboBox( this ); 320 whoStarts = new QComboBox( this );
320 whoStarts->insertItem( tr( "Computer starts" ) ); 321 whoStarts->insertItem( tr( "Computer starts" ) );
321 whoStarts->insertItem( tr( "Human starts" ) ); 322 whoStarts->insertItem( tr( "Human starts" ) );
322 l->addWidget( whoStarts ); 323 l->addWidget( whoStarts );
323 324
324 // Create the push buttons and connect their clicked() signals 325 // Create the push buttons and connect their clicked() signals
325 // to this right slots. 326 // to this right slots.
326 327
327 newGame = new QPushButton( tr( "Play!" ), this ); 328 newGame = new QPushButton( tr( "Play!" ), this );
328 connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) ); 329 connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) );
329 quit = new QPushButton( tr( "Quit" ), this ); 330 quit = new QPushButton( tr( "Quit" ), this );
330 connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); 331 connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
331 QHBoxLayout * b = new QHBoxLayout; 332 QHBoxLayout * b = new QHBoxLayout;
332 l->addLayout( b ); 333 l->addLayout( b );
333 b->addWidget( newGame ); 334 b->addWidget( newGame );
334 b->addWidget( quit ); 335 b->addWidget( quit );
335 showMaximized(); 336 showMaximized();
336 newState(); 337 newState();
337} 338}
338 339
339 340
340// -------------------------------------------------------------------------- 341// --------------------------------------------------------------------------
341// TicTacToe::newGameClicked() - SLOT 342// TicTacToe::newGameClicked() - SLOT
342// 343//
343// This slot is activated when the new game button is clicked. 344// This slot is activated when the new game button is clicked.
344// 345//
345 346
346void TicTacToe::newGameClicked() 347void TicTacToe::newGameClicked()
347{ 348{
348 board->computerStarts( whoStarts->currentItem() == 0 ); 349 board->computerStarts( whoStarts->currentItem() == 0 );
349 board->newGame(); 350 board->newGame();
350 newState(); 351 newState();
351} 352}
352 353
353 354
354// -------------------------------------------------------------------------- 355// --------------------------------------------------------------------------
355// TicTacToe::gameOver() - SLOT 356// TicTacToe::gameOver() - SLOT
356// 357//
357// This slot is activated when the TicTacGameBoard emits the signal 358// This slot is activated when the TicTacGameBoard emits the signal
358// "finished()", i.e. when a player has won or when it is a draw. 359// "finished()", i.e. when a player has won or when it is a draw.
359// 360//
360 361
361void TicTacToe::gameOver() 362void TicTacToe::gameOver()
362{ 363{
363 newState(); // update text box 364 newState(); // update text box
364} 365}
365 366
366 367
367// -------------------------------------------------------------------------- 368// --------------------------------------------------------------------------
368// Updates the message to reflect a new state. 369// Updates the message to reflect a new state.
369// 370//
370 371
371void TicTacToe::newState() 372void TicTacToe::newState()
372{ 373{
373 QStringList msg; 374 QStringList msg;
374 msg << tr( "Click Play to start") 375 msg << tr( "Click Play to start")
375 << tr("Make your move") 376 << tr("Make your move")
376 << tr("You won!") 377 << tr("You won!")
377 << tr("Computer won!") 378 << tr("Computer won!")
378 << tr("It's a draw"); 379 << tr("It's a draw");
379 message->setText( msg[board->state()] ); 380 message->setText( msg[board->state()] );
380 return; 381 return;
381} 382}
diff --git a/noncore/games/tictac/tictac.h b/noncore/games/tictac/tictac.h
index ec6c79c..bb0b485 100644
--- a/noncore/games/tictac/tictac.h
+++ b/noncore/games/tictac/tictac.h
@@ -1,108 +1,111 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** tictac.h,v 1.1.10.1 2003/08/29 06:50:40 harlekin Exp
3** 3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of an example program for Qt. This example 6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation. 7** program may be used, distributed and modified without limitation.
8** 8**
9*****************************************************************************/ 9*****************************************************************************/
10 10
11#ifndef TICTAC_H 11#ifndef TICTAC_H
12#define TICTAC_H 12#define TICTAC_H
13 13
14 14
15#include <qpushbutton.h> 15#include <qpushbutton.h>
16#include <qvector.h> 16#include <qvector.h>
17 17
18class QComboBox; 18class QComboBox;
19class QLabel; 19class QLabel;
20 20
21 21
22// -------------------------------------------------------------------------- 22// --------------------------------------------------------------------------
23// TicTacButton implements a single tic-tac-toe button 23// TicTacButton implements a single tic-tac-toe button
24// 24//
25 25
26class TicTacButton : public QPushButton 26class TicTacButton : public QPushButton
27{ 27{
28 Q_OBJECT 28 Q_OBJECT
29public: 29public:
30 TicTacButton( QWidget *parent ); 30 TicTacButton( QWidget *parent );
31 enum Type { Blank, Circle, Cross }; 31 enum Type { Blank, Circle, Cross };
32 Type type() const { return t; } 32 Type type() const { return t; }
33 void setType( Type type ){ t = type; repaint(); } 33 void setType( Type type ){ t = type; repaint(); }
34 QSizePolicy sizePolicy() const 34 QSizePolicy sizePolicy() const
35 { return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); } 35 { return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); }
36 QSize sizeHint() const { return QSize( 32, 32 ); } 36 QSize sizeHint() const { return QSize( 32, 32 ); }
37 QSize minimumSizeHint() const { return QSize( 10, 10 ); } 37 QSize minimumSizeHint() const { return QSize( 10, 10 ); }
38protected: 38protected:
39 voiddrawButtonLabel( QPainter * ); 39 voiddrawButtonLabel( QPainter * );
40private: 40private:
41 Type t; 41 Type t;
42}; 42};
43 43
44// Using template vector to make vector-class of TicTacButton. 44// Using template vector to make vector-class of TicTacButton.
45// This vector is used by the TicTacGameBoard class defined below. 45// This vector is used by the TicTacGameBoard class defined below.
46 46
47 typedef QVector<TicTacButton>TicTacButtons; 47 typedef QVector<TicTacButton>TicTacButtons;
48 typedef QArray<int> TicTacArray; 48 typedef QArray<int> TicTacArray;
49 49
50 50
51// -------------------------------------------------------------------------- 51// --------------------------------------------------------------------------
52// TicTacGameBoard implements the tic-tac-toe game board. 52// TicTacGameBoard implements the tic-tac-toe game board.
53// TicTacGameBoard is a composite widget that contains N x N TicTacButtons. 53// TicTacGameBoard is a composite widget that contains N x N TicTacButtons.
54// N is specified in the constructor. 54// N is specified in the constructor.
55// 55//
56 56
57class TicTacGameBoard : public QWidget 57class TicTacGameBoard : public QWidget
58{ 58{
59 Q_OBJECT 59 Q_OBJECT
60public: 60public:
61 TicTacGameBoard( int n, QWidget *parent=0, const char *name=0 ); 61 TicTacGameBoard( int n, QWidget *parent=0, const char *name=0 );
62 ~TicTacGameBoard(); 62 ~TicTacGameBoard();
63 enumState { Init, HumansTurn, HumanWon, ComputerWon, NobodyWon }; 63 enumState { Init, HumansTurn, HumanWon, ComputerWon, NobodyWon };
64 State state() const { return st; } 64 State state() const { return st; }
65 voidcomputerStarts( bool v ); 65 voidcomputerStarts( bool v );
66 void newGame(); 66 void newGame();
67signals: 67signals:
68 void finished(); // game finished 68 void finished(); // game finished
69private slots: 69private slots:
70 voidbuttonClicked(); 70 voidbuttonClicked();
71private: 71private:
72 void setState( State state ) { st = state; } 72 void setState( State state ) { st = state; }
73 voidupdateButtons(); 73 voidupdateButtons();
74 int checkBoard( TicTacArray * ); 74 int checkBoard( TicTacArray * );
75 void computerMove(); 75 void computerMove();
76 Statest; 76 Statest;
77 int nBoard; 77 int nBoard;
78 boolcomp_starts; 78 boolcomp_starts;
79 TicTacArray *btArray; 79 TicTacArray *btArray;
80 TicTacButtons *buttons; 80 TicTacButtons *buttons;
81}; 81};
82 82
83 83
84// -------------------------------------------------------------------------- 84// --------------------------------------------------------------------------
85// TicTacToe implements the complete game. 85// TicTacToe implements the complete game.
86// TicTacToe is a composite widget that contains a TicTacGameBoard and 86// TicTacToe is a composite widget that contains a TicTacGameBoard and
87// two push buttons for starting the game and quitting. 87// two push buttons for starting the game and quitting.
88// 88//
89 89
90class TicTacToe : public QWidget 90class TicTacToe : public QWidget
91{ 91{
92 Q_OBJECT 92 Q_OBJECT
93public: 93public:
94 TicTacToe( int boardSize=3, QWidget *parent=0, const char *name=0 ); 94 TicTacToe( QWidget *parent=0, const char *name=0, WFlags fl = 0 );
95 static QString appName() { return QString::fromLatin1("tictac"); }
96
95private slots: 97private slots:
96 voidnewGameClicked(); 98 voidnewGameClicked();
97 voidgameOver(); 99 voidgameOver();
98private: 100private:
99 voidnewState(); 101 voidnewState();
100 QComboBox*whoStarts; 102 QComboBox*whoStarts;
101 QPushButton *newGame; 103 QPushButton *newGame;
102 QPushButton *quit; 104 QPushButton *quit;
103 QLabel*message; 105 QLabel*message;
104 TicTacGameBoard *board; 106 TicTacGameBoard *board;
107 int boardSize;
105}; 108};
106 109
107 110
108#endif // TICTAC_H 111#endif // TICTAC_H
diff --git a/noncore/games/tictac/tictac.pro b/noncore/games/tictac/tictac.pro
index eb0705e..5cbdbdc 100644
--- a/noncore/games/tictac/tictac.pro
+++ b/noncore/games/tictac/tictac.pro
@@ -1,32 +1,29 @@
1TEMPLATE = app 1CONFIG += qt warn_on release quick-app
2CONFIG += qt warn_on release
3HEADERS = tictac.h 2HEADERS = tictac.h
4SOURCES = main.cpp \ 3SOURCES = main.cpp \
5 tictac.cpp 4 tictac.cpp
6TARGET = tictac
7INCLUDEPATH += $(OPIEDIR)/include 5INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include 6DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe 7LIBS += -lqpe
10DESTDIR = $(OPIEDIR)/bin 8
9 TARGET = tictac
11 10
12TRANSLATIONS = ../../../i18n/de/tictac.ts \ 11TRANSLATIONS = ../../../i18n/de/tictac.ts \
13 ../../../i18n/nl/tictac.ts \ 12 ../../../i18n/nl/tictac.ts \
14 ../../../i18n/da/tictac.ts \ 13 ../../../i18n/da/tictac.ts \
15 ../../../i18n/xx/tictac.ts \ 14 ../../../i18n/xx/tictac.ts \
16 ../../../i18n/en/tictac.ts \ 15 ../../../i18n/en/tictac.ts \
17 ../../../i18n/es/tictac.ts \ 16 ../../../i18n/es/tictac.ts \
18 ../../../i18n/fr/tictac.ts \ 17 ../../../i18n/fr/tictac.ts \
19 ../../../i18n/hu/tictac.ts \ 18 ../../../i18n/hu/tictac.ts \
20 ../../../i18n/ja/tictac.ts \ 19 ../../../i18n/ja/tictac.ts \
21 ../../../i18n/ko/tictac.ts \ 20 ../../../i18n/ko/tictac.ts \
22 ../../../i18n/no/tictac.ts \ 21 ../../../i18n/no/tictac.ts \
23 ../../../i18n/pl/tictac.ts \ 22 ../../../i18n/pl/tictac.ts \
24 ../../../i18n/pt/tictac.ts \ 23 ../../../i18n/pt/tictac.ts \
25 ../../../i18n/pt_BR/tictac.ts \ 24 ../../../i18n/pt_BR/tictac.ts \
26 ../../../i18n/sl/tictac.ts \ 25 ../../../i18n/sl/tictac.ts \
27 ../../../i18n/zh_CN/tictac.ts \ 26 ../../../i18n/zh_CN/tictac.ts \
28 ../../../i18n/zh_TW/tictac.ts 27 ../../../i18n/zh_TW/tictac.ts
29 28
30
31
32include ( $(OPIEDIR)/include.pro ) 29include ( $(OPIEDIR)/include.pro )