summaryrefslogtreecommitdiff
path: root/noncore/games/tictac/tictac.cpp
Unidiff
Diffstat (limited to 'noncore/games/tictac/tictac.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/tictac/tictac.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/games/tictac/tictac.cpp b/noncore/games/tictac/tictac.cpp
index 4954ba4..9de3b58 100644
--- a/noncore/games/tictac/tictac.cpp
+++ b/noncore/games/tictac/tictac.cpp
@@ -42,49 +42,49 @@ void 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 QPEApplication::showWidget( this );
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;
@@ -312,49 +312,49 @@ TicTacToe::TicTacToe( QWidget *parent, const char *name, WFlags fl )
312 312
313 QFrame *line = new QFrame( this ); 313 QFrame *line = new QFrame( this );
314 line->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 314 line->setFrameStyle( QFrame::HLine | QFrame::Sunken );
315 l->addWidget( line ); 315 l->addWidget( line );
316 316
317 // Create the combo box for deciding who should start, and 317 // Create the combo box for deciding who should start, and
318 // connect its clicked() signals to the buttonClicked() slot 318 // connect its clicked() signals to the buttonClicked() slot
319 319
320 whoStarts = new QComboBox( this ); 320 whoStarts = new QComboBox( this );
321 whoStarts->insertItem( tr( "Computer starts" ) ); 321 whoStarts->insertItem( tr( "Computer starts" ) );
322 whoStarts->insertItem( tr( "Human starts" ) ); 322 whoStarts->insertItem( tr( "Human starts" ) );
323 l->addWidget( whoStarts ); 323 l->addWidget( whoStarts );
324 324
325 // Create the push buttons and connect their clicked() signals 325 // Create the push buttons and connect their clicked() signals
326 // to this right slots. 326 // to this right slots.
327 327
328 newGame = new QPushButton( tr( "Play!" ), this ); 328 newGame = new QPushButton( tr( "Play!" ), this );
329 connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) ); 329 connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) );
330 quit = new QPushButton( tr( "Quit" ), this ); 330 quit = new QPushButton( tr( "Quit" ), this );
331 connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); 331 connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
332 QHBoxLayout * b = new QHBoxLayout; 332 QHBoxLayout * b = new QHBoxLayout;
333 l->addLayout( b ); 333 l->addLayout( b );
334 b->addWidget( newGame ); 334 b->addWidget( newGame );
335 b->addWidget( quit ); 335 b->addWidget( quit );
336 showMaximized(); 336 QPEApplication::showWidget( this );
337 newState(); 337 newState();
338} 338}
339 339
340 340
341// -------------------------------------------------------------------------- 341// --------------------------------------------------------------------------
342// TicTacToe::newGameClicked() - SLOT 342// TicTacToe::newGameClicked() - SLOT
343// 343//
344// This slot is activated when the new game button is clicked. 344// This slot is activated when the new game button is clicked.
345// 345//
346 346
347void TicTacToe::newGameClicked() 347void TicTacToe::newGameClicked()
348{ 348{
349 board->computerStarts( whoStarts->currentItem() == 0 ); 349 board->computerStarts( whoStarts->currentItem() == 0 );
350 board->newGame(); 350 board->newGame();
351 newState(); 351 newState();
352} 352}
353 353
354 354
355// -------------------------------------------------------------------------- 355// --------------------------------------------------------------------------
356// TicTacToe::gameOver() - SLOT 356// TicTacToe::gameOver() - SLOT
357// 357//
358// This slot is activated when the TicTacGameBoard emits the signal 358// This slot is activated when the TicTacGameBoard emits the signal
359// "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.
360// 360//