summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2003-08-23 19:29:48 (UTC)
committer cniehaus <cniehaus>2003-08-23 19:29:48 (UTC)
commitff72e85696d070efa03975ea8130807579a6e1d9 (patch) (unidiff)
tree4708b537f98915fd01aaeb856e5ad1c4db892ac6
parent3dff9b4751fa9b63ddfd2527ec68add7fafb599d (diff)
downloadopie-ff72e85696d070efa03975ea8130807579a6e1d9.zip
opie-ff72e85696d070efa03975ea8130807579a6e1d9.tar.gz
opie-ff72e85696d070efa03975ea8130807579a6e1d9.tar.bz2
working now. Almost 1500 lines diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/oyatzee/oyatzee.cpp455
-rw-r--r--noncore/games/oyatzee/oyatzee.h98
2 files changed, 403 insertions, 150 deletions
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp
index d0e220c..0bd22f6 100644
--- a/noncore/games/oyatzee/oyatzee.cpp
+++ b/noncore/games/oyatzee/oyatzee.cpp
@@ -1,65 +1,160 @@
1#include "oyatzee.h" 1#include "oyatzee.h"
2 2
3#include <qpe/applnk.h>
4#include <qpe/global.h>
5#include <qpe/filemanager.h>
6#include <qpe/resource.h>
7#include <qpe/config.h>
8
9#include <qapplication.h>
10#include <qmessagebox.h> 3#include <qmessagebox.h>
11#include <qcombobox.h> 4#include <qapplication.h>
12#include <qdatetime.h>
13#include <qfileinfo.h>
14#include <qfile.h>
15#include <qdir.h> 5#include <qdir.h>
16#include <qiconset.h>
17#include <qlabel.h> 6#include <qlabel.h>
18#include <qlineedit.h>
19#include <qpushbutton.h> 7#include <qpushbutton.h>
20#include <qtextstream.h>
21#include <qtimer.h> 8#include <qtimer.h>
22#include <qpe/qpetoolbar.h>
23#include <qtoolbutton.h>
24#include <qvbox.h> 9#include <qvbox.h>
25#include <qwidgetstack.h>
26#include <qpainter.h> 10#include <qpainter.h>
27#include <qlayout.h> 11#include <qlayout.h>
28#include <qregexp.h> 12#include <qpoint.h>
29 13
30#include <stdlib.h> 14#include <stdlib.h>
31#include <unistd.h>
32#include <pwd.h>
33#include <sys/types.h>
34 15
35OYatzee::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 )
36{ 17{
37 QWidget *thing = new QWidget( this ); 18 QWidget *thing = new QWidget( this );
38 setCentralWidget( thing ); 19 setCentralWidget( thing );
39 20
21 setCaption( tr( "OYatzee" ) );
40 22
41 setPlayerNumber( 4 ); 23 setPlayerNumber( 4 );
42 setRoundsNumber( 1 ); 24 setRoundsNumber( 1 );
25
26 lastPlayerFinished = false;
27 currentPlayer = 1;
43 28
44 playerList ps;
45 ps.append( new Player( "Carsten" ) ); 29 ps.append( new Player( "Carsten" ) );
46 ps.append( new Player( "Julia" ) ); 30 ps.append( new Player( "Julia" ) );
47 ps.append( new Player( "Christine" ) ); 31 ps.append( new Player( "Christine" ) );
48 ps.append( new Player( "Stephan" ) ); 32 ps.append( new Player( "Stephan" ) );
49 33
50 //X Game *g = new Game( ps );
51 //X
52 34
53 QVBoxLayout *vbox = new QVBoxLayout( thing ); 35 QVBoxLayout *vbox = new QVBoxLayout( thing );
54 36
55 sb = new Scoreboard( ps, thing , "sb" ); 37 sb = new Scoreboard( ps, thing , "sb" );
38 connect( sb->pb , SIGNAL( item( int ) ), this , SLOT( slotEndRound( int ) ) );
39
56 dw = new DiceWidget( thing , "dw" ); 40 dw = new DiceWidget( thing , "dw" );
41 dw->setMaximumHeight( this->height()/4 );
57 connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); 42 connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) );
58 43
59 vbox->addWidget( sb ); 44 vbox->addWidget( sb );
60 vbox->addWidget( dw ); 45 vbox->addWidget( dw );
61} 46}
62 47
48void OYatzee::slotEndRound( int item )
49{
50 qDebug( "Der User hat Nummer %d ausgewählt" , item );
51
52 /*
53 * if the user clicked on Total, Bonus or Score and thus not on a
54 * selectable item return and do nothing
55 */
56 if ( item == 7 || item == 8 || item == 16 ) return;
57
58 /*
59 * check if the user can really click on that item
60 */
61 if ( posibilities.find( item ) == posibilities.end() ) return;
62
63 QValueListInt numbers;
64
65 Dice *d = dw->diceList.first();
66 for ( ; d != 0 ; d = dw->diceList.next() )
67 {
68 numbers.append( d->hasValue() );
69 }
70
71 int points = 0;
72
73 switch ( item )
74 {
75 case Ones:
76 points = getPoints( 1 , numbers );
77 break;
78 case Twos:
79 points = getPoints( 2 , numbers );
80 break;
81 case Threes:
82 points = getPoints( 3 , numbers );
83 break;
84 case Fours:
85 points = getPoints( 4 , numbers );
86 break;
87 case Fives:
88 points = getPoints( 5 , numbers );
89 break;
90 case Sixes:
91 points = getPoints( 6 , numbers );
92 break;
93 case ThreeOfAKind:
94 points = oakPoints;
95 break;
96 case FourOfAKind:
97 points = oakPoints;
98 break;
99 case FullHouse:
100 points = 25;
101 break;
102 case SStraight:
103 points = 30;
104 break;
105 case LStraight:
106 points = 40;
107 break;
108 case Yatzee:
109 points = 50;
110 break;
111 case Chance:
112 points = getPoints ( Chance , numbers );
113 }
114
115 sb->nextRB(currentPlayer-1)->updateMap( item , points );
116 nextPlayer();
117
118 qDebug( "Punkte: %d" , points );
119}
120
121void OYatzee::nextPlayer()
122{
123 currentPlayer++;
124
125 if ( currentPlayer > numOfPlayers )
126 {
127 currentPlayer = 1;
128 }
129
130 ps.at(currentPlayer-1)->turn = 0;
131}
132
133int OYatzee::getPoints( const int num , QValueListInt l)
134{
135 QValueListInt::Iterator it = l.begin();
136 int c = 0;
137
138 if ( num != Chance )
139 {
140 for ( ; it != l.end() ; ++it )
141 {
142 if ( *it == num )
143 c++;
144 }
145
146 return c * num;
147 }
148 else
149 {
150 for ( ; it != l.end() ; ++it )
151 {
152 c += *it;
153 }
154 return c;
155 }
156 }
157
63OYatzee::~OYatzee() 158OYatzee::~OYatzee()
64{ 159{
65} 160}
@@ -75,7 +170,7 @@ void OYatzee::detectPosibilities()
75 170
76 for ( ; d != 0 ; d = dw->diceList.next() ) 171 for ( ; d != 0 ; d = dw->diceList.next() )
77 { 172 {
78 numbers.append( d->Value ); 173 numbers.append( d->hasValue() );
79 } 174 }
80 175
81 //the 6 numbers 176 //the 6 numbers
@@ -98,7 +193,6 @@ void OYatzee::detectPosibilities()
98 } 193 }
99 } 194 }
100 195
101
102 //3er, 4er, Yatzee 196 //3er, 4er, Yatzee
103 it = numbers.begin(); 197 it = numbers.begin();
104 int count; 198 int count;
@@ -123,16 +217,18 @@ void OYatzee::detectPosibilities()
123 217
124 if ( count >= 3 ) 218 if ( count >= 3 )
125 { 219 {
126 posibilities.append( 7 ); 220 posibilities.append( 9 );
127 221
128 //now we check if it is a full house 222 //now we check if it is a full house
129 if ( count == 3 && countFH == 2 ) //aka Full House 223 if ( count == 3 && countFH == 2 ) //aka Full House
130 posibilities.append( 9 ); 224 posibilities.append( 11 );
225 if ( count >= 4 )
226 posibilities.append( 10 );
227 if ( count == 5 ) //Yatzee
228 posibilities.append( 14 );
229
230 oakPoints = count * i;
131 } 231 }
132 if ( count >= 4 )
133 posibilities.append( 8 );
134 if ( count == 5 ) //Yatzee
135 posibilities.append( 12 );
136 } 232 }
137 233
138 //S-Straight 234 //S-Straight
@@ -157,9 +253,9 @@ void OYatzee::detectPosibilities()
157 isShort = true; 253 isShort = true;
158 254
159 if ( isShort ) 255 if ( isShort )
160 posibilities.append( 10 ); 256 posibilities.append( 12 );
161 if ( isLong ) 257 if ( isLong )
162 posibilities.append( 11 ); 258 posibilities.append( 13 );
163 } 259 }
164 260
165 posibilities.append( 13 ); //Chance, well, this is allways possible 261 posibilities.append( 13 ); //Chance, well, this is allways possible
@@ -169,54 +265,66 @@ void OYatzee::detectPosibilities()
169 265
170void OYatzee::displayPossibilites() 266void OYatzee::displayPossibilites()
171{ 267{
172 for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it ) 268 //X for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it )
173 { 269 //X {
174 qDebug( QString::number( *it ) ); 270 //X qDebug( QString::number( *it ) );
175 switch ( *it ) 271 //X switch ( *it )
176 { 272 //X {
177 case Ones: 273 //X case Ones:
178 qDebug( "1er" ); 274 //X qDebug( "1er" );
179 break; 275 //X break;
180 case Twos: 276 //X case Twos:
181 qDebug( "2er" ); 277 //X qDebug( "2er" );
182 break; 278 //X break;
183 case Threes: 279 //X case Threes:
184 qDebug( "3er" ); 280 //X qDebug( "3er" );
185 break; 281 //X break;
186 case Fours: 282 //X case Fours:
187 qDebug( "4er" ); 283 //X qDebug( "4er" );
188 break; 284 //X break;
189 case Fives: 285 //X case Fives:
190 qDebug( "5er" ); 286 //X qDebug( "5er" );
191 break; 287 //X break;
192 case Sixes: 288 //X case Sixes:
193 qDebug( "6er" ); 289 //X qDebug( "6er" );
194 break; 290 //X break;
195 case ThreeOfAKind: 291 //X case ThreeOfAKind:
196 qDebug( "3oaK" ); 292 //X qDebug( "3oaK" );
197 break; 293 //X break;
198 case FourOfAKind: 294 //X case FourOfAKind:
199 qDebug( "4oaK" ); 295 //X qDebug( "4oaK" );
200 break; 296 //X break;
201 case FullHouse: 297 //X case FullHouse:
202 qDebug( "Full House" ); 298 //X qDebug( "Full House" );
203 break; 299 //X break;
204 case SStraight: 300 //X case SStraight:
205 qDebug( "Short S" ); 301 //X qDebug( "Short S" );
206 break; 302 //X break;
207 case LStraight: 303 //X case LStraight:
208 qDebug( "Long S" ); 304 //X qDebug( "Long S" );
209 break; 305 //X break;
210 case Yatzee: 306 //X case Yatzee:
211 qDebug( "Yatzee!" ); 307 //X qDebug( "Yatzee!" );
212 break; 308 //X break;
213 case Chance: 309 //X case Chance:
214 qDebug( "Chance" ); 310 //X qDebug( "Chance" );
215 break; 311 //X break;
216 } 312 //X }
217 } 313 //X }
314
315 sb->pb->setIntlist( posibilities );
316 sb->pb->update();
317}
318
319void OYatzee::startGame()
320{
321 /*
322 * TODO
323 */
218} 324}
219 325
326void OYatzee::stopGame(){}
327
220void OYatzee::setPlayerNumber( const int num ) 328void OYatzee::setPlayerNumber( const int num )
221{ 329{
222 numOfPlayers = num; 330 numOfPlayers = num;
@@ -233,6 +341,16 @@ void OYatzee::slotStartGame()
233 341
234void OYatzee::slotRollDices() 342void OYatzee::slotRollDices()
235{ 343{
344 qDebug( "Roll nummer: %d" , ps.at( currentPlayer-1 )->turn );
345
346 if ( ps.at( currentPlayer-1 )->turn == 3 )
347 {
348 QMessageBox::information( this,
349 "OYatzee",
350 tr( "Only three rolls per turn allowed." ) );
351 return;
352 }
353
236 Dice *d = dw->diceList.first(); 354 Dice *d = dw->diceList.first();
237 355
238 for ( ; d != 0 ; d = dw->diceList.next() ) 356 for ( ; d != 0 ; d = dw->diceList.next() )
@@ -241,6 +359,10 @@ void OYatzee::slotRollDices()
241 d->roll(); 359 d->roll();
242 } 360 }
243 361
362 //qDebug( "Roll nummer (vorher): %d" , ps.at( currentPlayer-1 )->turn );
363 ps.at(currentPlayer-1)->turn++;
364 //qDebug( "Roll nummer (nachher): %d" , ps.at( currentPlayer-1 )->turn );
365
244 detectPosibilities(); 366 detectPosibilities();
245} 367}
246 368
@@ -269,6 +391,17 @@ Scoreboard::Scoreboard( playerList ps, QWidget *parent, const char *name ) : QWi
269 } 391 }
270} 392}
271 393
394Resultboard* Scoreboard::nextRB( int currentPlayer )
395{
396 Resultboard *b;
397
398 b = rbList.at( currentPlayer );
399
400 qDebug( "Anzahl: %d" ,rbList.count() );
401
402 return b;
403 }
404
272void Scoreboard::createResultboards(const int num) 405void Scoreboard::createResultboards(const int num)
273{ 406{
274 Player *p = ps_.first(); 407 Player *p = ps_.first();
@@ -281,10 +414,10 @@ void Scoreboard::createResultboards(const int num)
281 414
282void Scoreboard::paintEvent( QPaintEvent * ) 415void Scoreboard::paintEvent( QPaintEvent * )
283{ 416{
284 QPainter p; 417 //X QPainter p;
285 p.begin( this ); 418 //X p.begin( this );
286 419//X
287 p.drawRect( 0,0, this->width() , this->height() ); 420 //X p.drawRect( 0,0, this->width() , this->height() );
288} 421}
289 422
290/* 423/*
@@ -307,7 +440,7 @@ void Dice::slotSelected()
307 update(); 440 update();
308} 441}
309 442
310int Dice::hasValue() 443const int Dice::hasValue() const
311{ 444{
312 return Value; 445 return Value;
313} 446}
@@ -340,25 +473,47 @@ void Dice::paintEvent( QPaintEvent * )
340 473
341void Dice::paintNumber( QPainter *p ) 474void Dice::paintNumber( QPainter *p )
342{ 475{
476 p->setBrush( Qt::black );
477
478 int w = this->width();
479 int h = this->height();
480 int r = this->width();
481 r /= 10;
482
343 switch ( Value ) 483 switch ( Value )
344 { 484 {
345 case 1: 485 case 1:
346 p->drawText( 10,10,"1"); 486 p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ;
347 break; 487 break;
348 case 2: 488 case 2:
349 p->drawText( 10,10,"2"); 489 p->drawEllipse( (int)( 0.3*w - r ) , (int)( 0.3*h - r ) , r , r ) ;
490 p->drawEllipse( (int)( 0.7*w - r ) , (int)( 0.7*h - r ) , r , r ) ;
350 break; 491 break;
351 case 3: 492 case 3:
352 p->drawText( 10,10,"3"); 493 p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ;
494 p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ;
495 p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ;
353 break; 496 break;
354 case 4: 497 case 4:
355 p->drawText( 10,10,"4"); 498 p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ;
499 p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ;
500 p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ;
501 p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ;
356 break; 502 break;
357 case 5: 503 case 5:
358 p->drawText( 10,10,"5"); 504 p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ;
505 p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ;
506 p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ;
507 p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ;
508 p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ;
359 break; 509 break;
360 case 6: 510 case 6:
361 p->drawText( 10,10,"6"); 511 p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ;
512 p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ;
513 p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ;
514 p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ;
515 p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.5*h - r ) , r , r ) ;
516 p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.5*h - r ) , r , r ) ;
362 break; 517 break;
363 } 518 }
364} 519}
@@ -394,9 +549,38 @@ DiceWidget::DiceWidget( QWidget *parent , const char *name ) : QWidget( parent
394Player::Player( QString name ) 549Player::Player( QString name )
395{ 550{
396 playerName = name; 551 playerName = name;
552 setupResultList();
553 turn = 0;
554}
555
556void Player::setupResultList()
557{
558 for ( int i = 1 ; i < 14 ; ++i )
559 {
560 pResults.append( 0 );
561 }
562}
563
564/*
565 * TODO: muss noch genutzt werden
566 */
567void Player::updateTotalPoints( pointMap m )
568{
569 pointMap::Iterator it = m.begin();
570 for ( ; it != m.end() ; ++it )
571 {
572 totalPoints += it.data();
573 }
574
397} 575}
398 576
399 577
578void Player::setResults( const int cat , const int points )
579{
580 QValueListInt::Iterator it = pResults.at( cat );
581 *it = points;
582}
583
400/* 584/*
401 * Board 585 * Board
402 */ 586 */
@@ -404,6 +588,11 @@ Board::Board( QWidget *parent , const char* name ) : QWidget ( parent , name )
404{ 588{
405} 589}
406 590
591void Board::mousePressEvent( QMouseEvent *e )
592{
593 emit clicked( e->pos() );
594}
595
407/* 596/*
408 * Resultboard 597 * Resultboard
409 */ 598 */
@@ -417,9 +606,27 @@ void Resultboard::paintEvent( QPaintEvent* )
417{ 606{
418 QPainter p; 607 QPainter p;
419 p.begin( this ); 608 p.begin( this );
609
610 const int cell_width = this->width();
611 const int cell_height = this->height()/17;
612
613 pointMap::Iterator it = pMap.begin();
614 for ( ; it != pMap.end() ; ++it )
615 {
616 int i = it.key();
617 qDebug( "ok: %d , %d" , i , it.data() );
618 p.drawText( 0, i*cell_height , cell_width , cell_height , Qt::AlignCenter , QString::number( it.data() ) );
619 }
420 620
421 p.drawText( 10,10, pName ); 621 p.drawText( 0,0,cell_width,cell_height, Qt::AlignCenter , pName ); //Playername
422 p.drawRect( 0,0, this->width() , this->height() ); 622}
623
624
625void Resultboard::updateMap( int item , int points )
626{
627 pMap.insert( item , points );
628
629 update();
423} 630}
424 631
425/* 632/*
@@ -428,18 +635,6 @@ void Resultboard::paintEvent( QPaintEvent* )
428 635
429Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name ) 636Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name )
430{ 637{
431}
432
433void Possibilityboard::paintEvent( QPaintEvent* )
434{
435 QPainter p;
436 p.begin( this );
437
438 const int cell_width = this->width();
439 const int h = this->height();
440 const int cell_height = h/17;
441
442 QStringList begriffe;
443 begriffe.append( "1er" ); 638 begriffe.append( "1er" );
444 begriffe.append( "2er" ); 639 begriffe.append( "2er" );
445 begriffe.append( "3er" ); 640 begriffe.append( "3er" );
@@ -456,29 +651,43 @@ void Possibilityboard::paintEvent( QPaintEvent* )
456 begriffe.append( "Yatzee!" ); 651 begriffe.append( "Yatzee!" );
457 begriffe.append( "Chance" ); 652 begriffe.append( "Chance" );
458 begriffe.append( "Score" ); 653 begriffe.append( "Score" );
459
460 QStringList::Iterator it = begriffe.begin();
461 654
655 connect( this , SIGNAL( clicked( QPoint ) ), this , SLOT( slotClicked( QPoint ) ) );
656}
657
658void Possibilityboard::slotClicked( QPoint p)
659{
660 emit item( p.y()/(this->height()/17) );
661}
662
663void Possibilityboard::paintEvent( QPaintEvent* )
664{
665 QPainter p;
666 p.begin( this );
667
668 const int cell_width = this->width();
669 const int cell_height = this->height()/17;
670
671 p.setBrush( Qt::blue );
672
673 QValueListInt::Iterator listIt = list.begin();
674 for ( ; listIt != list.end() ; ++listIt )
675 {
676 p.drawRect( 0 , (*listIt) * cell_height , cell_width , cell_height );
677 }
678
679 p.setBrush( Qt::black );
680 p.setBrush( Qt::NoBrush );
681 QStringList::Iterator begriffeIt = begriffe.begin();
462 for ( int i = 1 ; i < 18 ; ++i ) 682 for ( int i = 1 ; i < 18 ; ++i )
463 { 683 {
464 p.drawRect( 0 , i*cell_height , cell_width , cell_height ); 684 p.drawText( 0 , i*cell_height , cell_width , cell_height , Qt::AlignCenter , *begriffeIt );
465 p.drawText( 0 , i*cell_height , cell_width , cell_height , Qt::AlignCenter , *it ); 685 ++begriffeIt;
466 ++it;
467 } 686 }
468} 687}
469 688
470/* 689void Possibilityboard::setIntlist( QValueListInt &l )
471 * Game
472 */
473
474Game::Game( playerList pla )
475{ 690{
476 players = pla; 691 list = l;
477} 692}
478 693
479void Game::startGame()
480{}
481
482void Game::stopGame()
483{}
484
diff --git a/noncore/games/oyatzee/oyatzee.h b/noncore/games/oyatzee/oyatzee.h
index 1074f1d..048a733 100644
--- a/noncore/games/oyatzee/oyatzee.h
+++ b/noncore/games/oyatzee/oyatzee.h
@@ -4,6 +4,8 @@
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5#include <qlabel.h> 5#include <qlabel.h>
6#include <qlist.h> 6#include <qlist.h>
7#include <qmap.h>
8#include <qsplitter.h>
7 9
8#include <stdlib.h> // rand() function 10#include <stdlib.h> // rand() function
9#include <qdatetime.h> // seed for rand() 11#include <qdatetime.h> // seed for rand()
@@ -15,10 +17,13 @@ class DiceWidget;
15class Resultboard; 17class Resultboard;
16class Player; 18class Player;
17 19
20class QPoint;
21
18typedef QList<Dice> dicesList; 22typedef QList<Dice> dicesList;
19typedef QList<Resultboard> resultboardList; 23typedef QList<Resultboard> resultboardList;
20typedef QValueList<int> QValueListInt; 24typedef QValueList<int> QValueListInt;
21typedef QList<Player> playerList; 25typedef QList<Player> playerList;
26typedef QMap<int,int> pointMap;
22 27
23class OYatzee : public QMainWindow { 28class OYatzee : public QMainWindow {
24 Q_OBJECT 29 Q_OBJECT
@@ -26,37 +31,45 @@ class OYatzee : public QMainWindow {
26 OYatzee( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 31 OYatzee( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
27 ~OYatzee(); 32 ~OYatzee();
28 33
29 Game *g; 34 Game *g();
30 DiceWidget *dw; 35 DiceWidget *dw;
31 Scoreboard *sb; 36 Scoreboard *sb;
32 37
33 QValueListInt posibilities; 38 QValueListInt posibilities;
39 playerList ps;
34 40
35 void setPlayerNumber( const int num ); 41 void setPlayerNumber( const int num );
36 void setRoundsNumber( const int num ); 42 void setRoundsNumber( const int num );
37 43
38 enum { 44 enum { Ones = 1,
39 Ones=1,
40 Twos = 2, 45 Twos = 2,
41 Threes = 3, 46 Threes = 3,
42 Fours = 4, 47 Fours = 4,
43 Fives = 5, 48 Fives = 5,
44 Sixes = 6, 49 Sixes = 6,
45 ThreeOfAKind = 7, //12444 50 ThreeOfAKind = 9, //12444
46 FourOfAKind = 8, //14444 51 FourOfAKind = 10, //14444
47 FullHouse = 9, //22555 52 FullHouse = 11, //22555
48 SStraight = 10, //13456 53 SStraight = 12, //13456
49 LStraight = 11, //12345 54 LStraight = 13, //12345
50 Yatzee = 12, //55555 55 Yatzee = 14, //55555
51 Chance = 13}; 56 Chance = 15};
52 57
53 public slots: 58 public slots:
54 void slotStartGame(); 59 void slotStartGame();
55 void slotRollDices(); 60 void slotRollDices();
61 void slotEndRound( int );
56 62
57 private: 63 private:
58 int numOfPlayers; 64 int numOfPlayers;
59 int numOfRounds; 65 int numOfRounds;
66 int currentPlayer; /* the number of the current player */
67
68 int oakPoints;
69
70 void nextPlayer();
71
72 bool lastPlayerFinished;
60 73
61 /* 74 /*
62 * Check what posibilities the player currently has 75 * Check what posibilities the player currently has
@@ -64,6 +77,11 @@ class OYatzee : public QMainWindow {
64 void detectPosibilities(); 77 void detectPosibilities();
65 void displayPossibilites(); 78 void displayPossibilites();
66 79
80 int getPoints( const int , QValueListInt );
81
82 void startGame();
83 void stopGame();
84
67}; 85};
68 86
69class Dice : public QFrame 87class Dice : public QFrame
@@ -72,12 +90,13 @@ class Dice : public QFrame
72 public: 90 public:
73 Dice( QWidget* parent = 0, const char* name = 0 ); 91 Dice( QWidget* parent = 0, const char* name = 0 );
74 92
75 int Value;
76 bool isSelected; 93 bool isSelected;
77 94
78 int hasValue(); 95 const int hasValue() const;
79 void roll(); 96 void roll();
80 virtual void mousePressEvent( QMouseEvent* ); 97
98 private:
99 int Value;
81 100
82 private slots: 101 private slots:
83 void slotSelected(); 102 void slotSelected();
@@ -86,8 +105,9 @@ class Dice : public QFrame
86 void selected(); 105 void selected();
87 106
88 protected: 107 protected:
89 void paintEvent( QPaintEvent *e ); 108 void paintEvent( QPaintEvent *e );
90 void paintNumber( QPainter *p ); 109 void paintNumber( QPainter *p );
110 virtual void mousePressEvent( QMouseEvent* );
91}; 111};
92 112
93class DiceWidget : public QWidget 113class DiceWidget : public QWidget
@@ -101,12 +121,18 @@ class DiceWidget : public QWidget
101 dicesList diceList; 121 dicesList diceList;
102}; 122};
103 123
104
105class Board : public QWidget 124class Board : public QWidget
106{ 125{
107 Q_OBJECT 126 Q_OBJECT
108 public: 127 public:
109 Board( QWidget *parent = 0, const char* name = 0 ); 128 Board( QWidget *parent = 0, const char* name = 0 );
129
130 signals:
131 void clicked( QPoint );
132 void item( int );
133
134 protected:
135 virtual void mousePressEvent( QMouseEvent* );
110}; 136};
111 137
112class Possibilityboard : public Board 138class Possibilityboard : public Board
@@ -115,9 +141,21 @@ class Possibilityboard : public Board
115 141
116 public: 142 public:
117 Possibilityboard( QWidget *parent = 0, const char* name = 0 ); 143 Possibilityboard( QWidget *parent = 0, const char* name = 0 );
144
145 QValueListInt list;
146 void setIntlist( QValueListInt& );
118 147
148 private:
149 QStringList begriffe;
150
151 private slots:
152 /*
153 * this slot returns the item the user has selected
154 */
155 virtual void slotClicked(QPoint);
156
119 protected: 157 protected:
120 virtual void paintEvent( QPaintEvent *e ); 158 virtual void paintEvent( QPaintEvent *e );
121}; 159};
122 160
123class Resultboard : public Board 161class Resultboard : public Board
@@ -125,9 +163,13 @@ class Resultboard : public Board
125 Q_OBJECT 163 Q_OBJECT
126 164
127 public: 165 public:
128 Resultboard( QString playerName , QWidget *parent = 0, const char* name = 0 ); 166 Resultboard( QString playerName = 0 , QWidget *parent = 0, const char* name = 0 );
129 QString pName; 167 QString pName;
130 168
169 pointMap pMap;
170
171 void updateMap( int, int );
172
131 protected: 173 protected:
132 virtual void paintEvent( QPaintEvent *e ); 174 virtual void paintEvent( QPaintEvent *e );
133}; 175};
@@ -142,8 +184,11 @@ class Scoreboard : public QWidget
142 Possibilityboard *pb; 184 Possibilityboard *pb;
143 resultboardList rbList; 185 resultboardList rbList;
144 playerList ps_; 186 playerList ps_;
145 187
146 void createResultboards(const int); 188 void createResultboards(const int);
189
190 Resultboard* nextRB(int);
191
147 192
148 protected: 193 protected:
149 void paintEvent( QPaintEvent *e ); 194 void paintEvent( QPaintEvent *e );
@@ -157,18 +202,17 @@ class Player
157 202
158 QString playerName; 203 QString playerName;
159 int totalPoints; 204 int totalPoints;
160};
161 205
162class Game 206 void setResults( const int , const int );
163{
164 public:
165 Game( playerList pla );
166 207
167 playerList players; 208 int turn;
168 int currentPlayer;
169 209
170 void startGame(); 210 void updateTotalPoints( QMap<int,int> );
171 void stopGame(); 211
212 private:
213 QValueListInt pResults; /* the individual results of the player */
214
215 void setupResultList(); /* only in the ctor */
172}; 216};
173 217
174#endif // WORDGAME_H 218#endif // WORDGAME_H