summaryrefslogtreecommitdiff
path: root/noncore/games/oyatzee/oyatzee.cpp
Unidiff
Diffstat (limited to 'noncore/games/oyatzee/oyatzee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/oyatzee/oyatzee.cpp50
1 files changed, 28 insertions, 22 deletions
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp
index a55aa73..27c0a9f 100644
--- a/noncore/games/oyatzee/oyatzee.cpp
+++ b/noncore/games/oyatzee/oyatzee.cpp
@@ -1,68 +1,74 @@
1#include "oyatzee.h" 1#include "oyatzee.h"
2 2
3/* OPIE */
4#include <opie2/odebug.h>
5using namespace Opie::Core;
6
7/* QT */
3#include <qmessagebox.h> 8#include <qmessagebox.h>
4#include <qpushbutton.h> 9#include <qpushbutton.h>
5#include <qpainter.h> 10#include <qpainter.h>
6#include <qlayout.h> 11#include <qlayout.h>
7 12
13/* STD */
8#include <stdlib.h> 14#include <stdlib.h>
9 15
10OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl ) 16OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl )
11{ 17{
12 QWidget *thing = new QWidget( this ); 18 QWidget *thing = new QWidget( this );
13 setCentralWidget( thing ); 19 setCentralWidget( thing );
14 20
15 setCaption( tr( "OYatzee" ) ); 21 setCaption( tr( "OYatzee" ) );
16 22
17 setPlayerNumber( 4 ); 23 setPlayerNumber( 4 );
18 setRoundsNumber( 1 ); 24 setRoundsNumber( 1 );
19 25
20 lastPlayerFinished = false; 26 lastPlayerFinished = false;
21 currentPlayer = 1; 27 currentPlayer = 1;
22 28
23 ps.append( new Player( "Carsten" ) ); 29 ps.append( new Player( "Carsten" ) );
24 ps.append( new Player( "Julia" ) ); 30 ps.append( new Player( "Julia" ) );
25 ps.append( new Player( "Christine" ) ); 31 ps.append( new Player( "Christine" ) );
26 ps.append( new Player( "Stephan" ) ); 32 ps.append( new Player( "Stephan" ) );
27 33
28 34
29 QVBoxLayout *vbox = new QVBoxLayout( thing ); 35 QVBoxLayout *vbox = new QVBoxLayout( thing );
30 36
31 sb = new Scoreboard( ps, thing , "sb" ); 37 sb = new Scoreboard( ps, thing , "sb" );
32 connect( sb->pb , SIGNAL( item(int) ), this , SLOT( slotEndRound(int) ) ); 38 connect( sb->pb , SIGNAL( item(int) ), this , SLOT( slotEndRound(int) ) );
33 39
34 dw = new DiceWidget( thing , "dw" ); 40 dw = new DiceWidget( thing , "dw" );
35 dw->setMaximumHeight( this->height()/4 ); 41 dw->setMaximumHeight( this->height()/4 );
36 connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); 42 connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) );
37 43
38 vbox->addWidget( sb ); 44 vbox->addWidget( sb );
39 vbox->addWidget( dw ); 45 vbox->addWidget( dw );
40} 46}
41 47
42void OYatzee::slotEndRound( int item ) 48void OYatzee::slotEndRound( int item )
43{ 49{
44 qDebug( "Der User hat Nummer %d ausgewählt" , item ); 50 odebug << "Der User hat Nummer " << item << " ausgewählt" << oendl;
45 51
46 /* 52 /*
47 * if the user clicked on Total, Bonus or Score and thus not on a 53 * if the user clicked on Total, Bonus or Score and thus not on a
48 * selectable item return and do nothing 54 * selectable item return and do nothing
49 */ 55 */
50 if ( item == 7 || item == 8 || item == 16 ) return; 56 if ( item == 7 || item == 8 || item == 16 ) return;
51 57
52 /* 58 /*
53 * check if the user can really click on that item 59 * check if the user can really click on that item
54 */ 60 */
55 if ( posibilities.find( item ) == posibilities.end() ) return; 61 if ( posibilities.find( item ) == posibilities.end() ) return;
56 62
57 QValueListInt numbers; 63 QValueListInt numbers;
58 64
59 Dice *d = dw->diceList.first(); 65 Dice *d = dw->diceList.first();
60 for ( ; d != 0 ; d = dw->diceList.next() ) 66 for ( ; d != 0 ; d = dw->diceList.next() )
61 { 67 {
62 numbers.append( d->hasValue() ); 68 numbers.append( d->hasValue() );
63 } 69 }
64 70
65 int points = 0; 71 int points = 0;
66 72
67 switch ( item ) 73 switch ( item )
68 { 74 {
@@ -88,96 +94,96 @@ void OYatzee::slotEndRound( int item )
88 points = oakPoints; 94 points = oakPoints;
89 break; 95 break;
90 case FourOfAKind: 96 case FourOfAKind:
91 points = oakPoints; 97 points = oakPoints;
92 break; 98 break;
93 case FullHouse: 99 case FullHouse:
94 points = 25; 100 points = 25;
95 break; 101 break;
96 case SStraight: 102 case SStraight:
97 points = 30; 103 points = 30;
98 break; 104 break;
99 case LStraight: 105 case LStraight:
100 points = 40; 106 points = 40;
101 break; 107 break;
102 case Yatzee: 108 case Yatzee:
103 points = 50; 109 points = 50;
104 break; 110 break;
105 case Chance: 111 case Chance:
106 points = getPoints ( Chance , numbers ); 112 points = getPoints ( Chance , numbers );
107 } 113 }
108 114
109 sb->nextRB(currentPlayer-1)->updateMap( item , points ); 115 sb->nextRB(currentPlayer-1)->updateMap( item , points );
110 nextPlayer(); 116 nextPlayer();
111 117
112 qDebug( "Punkte: %d" , points ); 118 odebug << "Punkte: " << points << "" << oendl;
113} 119}
114 120
115void OYatzee::nextPlayer() 121void OYatzee::nextPlayer()
116{ 122{
117 currentPlayer++; 123 currentPlayer++;
118 124
119 if ( currentPlayer > numOfPlayers ) 125 if ( currentPlayer > numOfPlayers )
120 { 126 {
121 currentPlayer = 1; 127 currentPlayer = 1;
122 } 128 }
123 129
124 ps.at(currentPlayer-1)->turn = 0; 130 ps.at(currentPlayer-1)->turn = 0;
125} 131}
126 132
127int OYatzee::getPoints( const int num , QValueListInt l) 133int OYatzee::getPoints( const int num , QValueListInt l)
128{ 134{
129 QValueListInt::Iterator it = l.begin(); 135 QValueListInt::Iterator it = l.begin();
130 int c = 0; 136 int c = 0;
131 137
132 if ( num != Chance ) 138 if ( num != Chance )
133 { 139 {
134 for ( ; it != l.end() ; ++it ) 140 for ( ; it != l.end() ; ++it )
135 { 141 {
136 if ( *it == num ) 142 if ( *it == num )
137 c++; 143 c++;
138 } 144 }
139 145
140 return c * num; 146 return c * num;
141 } 147 }
142 else 148 else
143 { 149 {
144 for ( ; it != l.end() ; ++it ) 150 for ( ; it != l.end() ; ++it )
145 { 151 {
146 c += *it; 152 c += *it;
147 } 153 }
148 return c; 154 return c;
149 } 155 }
150 } 156 }
151 157
152OYatzee::~OYatzee() 158OYatzee::~OYatzee()
153{ 159{
154} 160}
155 161
156void OYatzee::detectPosibilities() 162void OYatzee::detectPosibilities()
157{ 163{
158 posibilities.clear(); 164 posibilities.clear();
159 qDebug( "running detectPosibilities()" ); 165 odebug << "running detectPosibilities()" << oendl;
160 166
161 Dice *d = dw->diceList.first(); 167 Dice *d = dw->diceList.first();
162 168
163 QValueListInt numbers; 169 QValueListInt numbers;
164 170
165 for ( ; d != 0 ; d = dw->diceList.next() ) 171 for ( ; d != 0 ; d = dw->diceList.next() )
166 { 172 {
167 numbers.append( d->hasValue() ); 173 numbers.append( d->hasValue() );
168 } 174 }
169 175
170 //the 6 numbers 176 //the 6 numbers
171 QValueListInt::Iterator it; 177 QValueListInt::Iterator it;
172 178
173 for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 179 for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6
174 { 180 {
175 bool cont = false; 181 bool cont = false;
176 it = numbers.begin(); 182 it = numbers.begin();
177 for ( ; it != numbers.end() ; ++it ) 183 for ( ; it != numbers.end() ; ++it )
178 { 184 {
179 if ( cont ) 185 if ( cont )
180 continue; 186 continue;
181 187
182 if ( numbers.find( i ) != numbers.end() ) 188 if ( numbers.find( i ) != numbers.end() )
183 { 189 {
@@ -240,179 +246,179 @@ void OYatzee::detectPosibilities()
240 isLong = true; 246 isLong = true;
241 } 247 }
242 //1234 248 //1234
243 if ( numbers.find( 1 ) != numbers.end() && numbers.find( 2 ) != numbers.end() ) 249 if ( numbers.find( 1 ) != numbers.end() && numbers.find( 2 ) != numbers.end() )
244 isShort = true; 250 isShort = true;
245 //3456 251 //3456
246 if ( numbers.find( 5 ) != numbers.end() && numbers.find( 6 ) != numbers.end() ) 252 if ( numbers.find( 5 ) != numbers.end() && numbers.find( 6 ) != numbers.end() )
247 isShort = true; 253 isShort = true;
248 254
249 if ( isShort ) 255 if ( isShort )
250 posibilities.append( 12 ); 256 posibilities.append( 12 );
251 if ( isLong ) 257 if ( isLong )
252 posibilities.append( 13 ); 258 posibilities.append( 13 );
253 } 259 }
254 260
255 posibilities.append( 13 ); //Chance, well, this is allways possible 261 posibilities.append( 13 ); //Chance, well, this is allways possible
256 262
257 displayPossibilites(); 263 displayPossibilites();
258} 264}
259 265
260void OYatzee::displayPossibilites() 266void OYatzee::displayPossibilites()
261{ 267{
262 //X for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it ) 268 //X for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it )
263 //X { 269 //X {
264 //X qDebug( QString::number( *it ) ); 270 //X odebug << QString::number( *it ) << oendl;
265 //X switch ( *it ) 271 //X switch ( *it )
266 //X { 272 //X {
267 //X case Ones: 273 //X case Ones:
268 //X qDebug( "1er" ); 274 //X odebug << "1er" << oendl;
269 //X break; 275 //X break;
270 //X case Twos: 276 //X case Twos:
271 //X qDebug( "2er" ); 277 //X odebug << "2er" << oendl;
272 //X break; 278 //X break;
273 //X case Threes: 279 //X case Threes:
274 //X qDebug( "3er" ); 280 //X odebug << "3er" << oendl;
275 //X break; 281 //X break;
276 //X case Fours: 282 //X case Fours:
277 //X qDebug( "4er" ); 283 //X odebug << "4er" << oendl;
278 //X break; 284 //X break;
279 //X case Fives: 285 //X case Fives:
280 //X qDebug( "5er" ); 286 //X odebug << "5er" << oendl;
281 //X break; 287 //X break;
282 //X case Sixes: 288 //X case Sixes:
283 //X qDebug( "6er" ); 289 //X odebug << "6er" << oendl;
284 //X break; 290 //X break;
285 //X case ThreeOfAKind: 291 //X case ThreeOfAKind:
286 //X qDebug( "3oaK" ); 292 //X odebug << "3oaK" << oendl;
287 //X break; 293 //X break;
288 //X case FourOfAKind: 294 //X case FourOfAKind:
289 //X qDebug( "4oaK" ); 295 //X odebug << "4oaK" << oendl;
290 //X break; 296 //X break;
291 //X case FullHouse: 297 //X case FullHouse:
292 //X qDebug( "Full House" ); 298 //X odebug << "Full House" << oendl;
293 //X break; 299 //X break;
294 //X case SStraight: 300 //X case SStraight:
295 //X qDebug( "Short S" ); 301 //X odebug << "Short S" << oendl;
296 //X break; 302 //X break;
297 //X case LStraight: 303 //X case LStraight:
298 //X qDebug( "Long S" ); 304 //X odebug << "Long S" << oendl;
299 //X break; 305 //X break;
300 //X case Yatzee: 306 //X case Yatzee:
301 //X qDebug( "Yatzee!" ); 307 //X odebug << "Yatzee!" << oendl;
302 //X break; 308 //X break;
303 //X case Chance: 309 //X case Chance:
304 //X qDebug( "Chance" ); 310 //X odebug << "Chance" << oendl;
305 //X break; 311 //X break;
306 //X } 312 //X }
307 //X } 313 //X }
308 314
309 sb->pb->setIntlist( posibilities ); 315 sb->pb->setIntlist( posibilities );
310 sb->pb->update(); 316 sb->pb->update();
311} 317}
312 318
313void OYatzee::startGame() 319void OYatzee::startGame()
314{ 320{
315 /* 321 /*
316 * TODO 322 * TODO
317 */ 323 */
318} 324}
319 325
320void OYatzee::stopGame(){} 326void OYatzee::stopGame(){}
321 327
322void OYatzee::setPlayerNumber( const int num ) 328void OYatzee::setPlayerNumber( const int num )
323{ 329{
324 numOfPlayers = num; 330 numOfPlayers = num;
325} 331}
326 332
327void OYatzee::setRoundsNumber( const int num ) 333void OYatzee::setRoundsNumber( const int num )
328{ 334{
329 numOfRounds = num; 335 numOfRounds = num;
330} 336}
331 337
332void OYatzee::slotStartGame() 338void OYatzee::slotStartGame()
333{ 339{
334} 340}
335 341
336void OYatzee::slotRollDices() 342void OYatzee::slotRollDices()
337{ 343{
338 qDebug( "Roll nummer: %d" , ps.at( currentPlayer-1 )->turn ); 344 odebug << "Roll nummer: " << ps.at( currentPlayer-1 )->turn << "" << oendl;
339 345
340 if ( ps.at( currentPlayer-1 )->turn == 3 ) 346 if ( ps.at( currentPlayer-1 )->turn == 3 )
341 { 347 {
342 QMessageBox::information( this, 348 QMessageBox::information( this,
343 "OYatzee", 349 "OYatzee",
344 tr( "Only three rolls per turn allowed." ) ); 350 tr( "Only three rolls per turn allowed." ) );
345 return; 351 return;
346 } 352 }
347 353
348 Dice *d = dw->diceList.first(); 354 Dice *d = dw->diceList.first();
349 355
350 for ( ; d != 0 ; d = dw->diceList.next() ) 356 for ( ; d != 0 ; d = dw->diceList.next() )
351 { 357 {
352 if ( !d->isSelected ) 358 if ( !d->isSelected )
353 d->roll(); 359 d->roll();
354 } 360 }
355 361
356 //qDebug( "Roll nummer (vorher): %d" , ps.at( currentPlayer-1 )->turn ); 362 //odebug << "Roll nummer (vorher): " << ps.at( currentPlayer-1 )->turn << "" << oendl;
357 ps.at(currentPlayer-1)->turn++; 363 ps.at(currentPlayer-1)->turn++;
358 //qDebug( "Roll nummer (nachher): %d" , ps.at( currentPlayer-1 )->turn ); 364 //odebug << "Roll nummer (nachher): " << ps.at( currentPlayer-1 )->turn << "" << oendl;
359 365
360 detectPosibilities(); 366 detectPosibilities();
361} 367}
362 368
363/* 369/*
364 * Scoreboard 370 * Scoreboard
365 */ 371 */
366Scoreboard::Scoreboard( playerList ps, QWidget *parent, const char *name ) : QWidget( parent , name ) 372Scoreboard::Scoreboard( playerList ps, QWidget *parent, const char *name ) : QWidget( parent , name )
367{ 373{
368 ps_ = ps; 374 ps_ = ps;
369 375
370 pb = new Possibilityboard( this , "pb" ); 376 pb = new Possibilityboard( this , "pb" );
371 377
372 createResultboards( 4 ); 378 createResultboards( 4 );
373 379
374 QHBoxLayout *hbox = new QHBoxLayout( this ); 380 QHBoxLayout *hbox = new QHBoxLayout( this );
375 381
376 hbox->addWidget( pb ); 382 hbox->addWidget( pb );
377 383
378 hbox->addSpacing( 25 ); 384 hbox->addSpacing( 25 );
379 385
380 Resultboard *r = rbList.first(); 386 Resultboard *r = rbList.first();
381 387
382 for ( ; r != 0 ; r = rbList.next() ) 388 for ( ; r != 0 ; r = rbList.next() )
383 { 389 {
384 hbox->addWidget( r ); 390 hbox->addWidget( r );
385 } 391 }
386} 392}
387 393
388Resultboard* Scoreboard::nextRB( int currentPlayer ) 394Resultboard* Scoreboard::nextRB( int currentPlayer )
389{ 395{
390 Resultboard *b; 396 Resultboard *b;
391 397
392 b = rbList.at( currentPlayer ); 398 b = rbList.at( currentPlayer );
393 399
394 qDebug( "Anzahl: %d" ,rbList.count() ); 400 odebug << "Anzahl: " << rbList.count() << "" << oendl;
395 401
396 return b; 402 return b;
397 } 403 }
398 404
399void Scoreboard::createResultboards(const int num) 405void Scoreboard::createResultboards(const int num)
400{ 406{
401 Player *p = ps_.first(); 407 Player *p = ps_.first();
402 for ( int i = 0 ; i < num ; ++i , p = ps_.next() ) 408 for ( int i = 0 ; i < num ; ++i , p = ps_.next() )
403 { 409 {
404 QString n = p->playerName; 410 QString n = p->playerName;
405 rbList.append( new Resultboard( n , this ) ); 411 rbList.append( new Resultboard( n , this ) );
406 } 412 }
407} 413}
408 414
409void Scoreboard::paintEvent( QPaintEvent * ) 415void Scoreboard::paintEvent( QPaintEvent * )
410{ 416{
411 //X QPainter p; 417 //X QPainter p;
412 //X p.begin( this ); 418 //X p.begin( this );
413//X 419//X
414 //X p.drawRect( 0,0, this->width() , this->height() ); 420 //X p.drawRect( 0,0, this->width() , this->height() );
415} 421}
416 422
417/* 423/*
418 * Dice 424 * Dice
@@ -587,49 +593,49 @@ void Board::mousePressEvent( QMouseEvent *e )
587 emit clicked( e->pos() ); 593 emit clicked( e->pos() );
588} 594}
589 595
590/* 596/*
591 * Resultboard 597 * Resultboard
592 */ 598 */
593 599
594Resultboard::Resultboard( QString playerName , QWidget *parent , const char* name ) : Board ( parent , name ) 600Resultboard::Resultboard( QString playerName , QWidget *parent , const char* name ) : Board ( parent , name )
595{ 601{
596 pName = playerName; 602 pName = playerName;
597} 603}
598 604
599void Resultboard::paintEvent( QPaintEvent* ) 605void Resultboard::paintEvent( QPaintEvent* )
600{ 606{
601 QPainter p; 607 QPainter p;
602 p.begin( this ); 608 p.begin( this );
603 609
604 const int cell_width = this->width(); 610 const int cell_width = this->width();
605 const int cell_height = this->height()/17; 611 const int cell_height = this->height()/17;
606 612
607 pointMap::Iterator it = pMap.begin(); 613 pointMap::Iterator it = pMap.begin();
608 for ( ; it != pMap.end() ; ++it ) 614 for ( ; it != pMap.end() ; ++it )
609 { 615 {
610 int i = it.key(); 616 int i = it.key();
611 qDebug( "ok: %d , %d" , i , it.data() ); 617 odebug << "ok: " << i << " , " << it.data() << "" << oendl;
612 p.drawText( 0, i*cell_height , cell_width , cell_height , Qt::AlignCenter , QString::number( it.data() ) ); 618 p.drawText( 0, i*cell_height , cell_width , cell_height , Qt::AlignCenter , QString::number( it.data() ) );
613 } 619 }
614 620
615 p.drawText( 0,0,cell_width,cell_height, Qt::AlignCenter , pName ); //Playername 621 p.drawText( 0,0,cell_width,cell_height, Qt::AlignCenter , pName ); //Playername
616} 622}
617 623
618 624
619void Resultboard::updateMap( int item , int points ) 625void Resultboard::updateMap( int item , int points )
620{ 626{
621 pMap.insert( item , points ); 627 pMap.insert( item , points );
622 628
623 update(); 629 update();
624} 630}
625 631
626/* 632/*
627 * Possibilityboard 633 * Possibilityboard
628 */ 634 */
629 635
630Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name ) 636Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name )
631{ 637{
632 begriffe.append( "1er" ); 638 begriffe.append( "1er" );
633 begriffe.append( "2er" ); 639 begriffe.append( "2er" );
634 begriffe.append( "3er" ); 640 begriffe.append( "3er" );
635 begriffe.append( "4er" ); 641 begriffe.append( "4er" );