-rw-r--r-- | noncore/games/oyatzee/oyatzee.cpp | 112 | ||||
-rw-r--r-- | noncore/games/oyatzee/oyatzee.h | 58 |
2 files changed, 160 insertions, 10 deletions
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp index 5c4d1f7..6228a8f 100644 --- a/noncore/games/oyatzee/oyatzee.cpp +++ b/noncore/games/oyatzee/oyatzee.cpp | |||
@@ -36,20 +36,29 @@ OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( | |||
36 | { | 36 | { |
37 | QWidget *thing = new QWidget( this ); | 37 | QWidget *thing = new QWidget( this ); |
38 | setCentralWidget( thing ); | 38 | setCentralWidget( thing ); |
39 | 39 | ||
40 | |||
41 | setPlayerNumber( 4 ); | ||
42 | setRoundsNumber( 1 ); | ||
43 | |||
44 | playerList ps; | ||
45 | ps.append( new Player( "Carsten" ) ); | ||
46 | ps.append( new Player( "Julia" ) ); | ||
47 | ps.append( new Player( "Christine" ) ); | ||
48 | ps.append( new Player( "Stephan" ) ); | ||
49 | |||
50 | Game *g = new Game( ps ); | ||
51 | |||
52 | |||
40 | QVBoxLayout *vbox = new QVBoxLayout( thing ); | 53 | QVBoxLayout *vbox = new QVBoxLayout( thing ); |
41 | 54 | ||
42 | sb = new Scoreboard( thing , "sb" ); | 55 | sb = new Scoreboard( ps, thing , "sb" ); |
43 | dw = new DiceWidget( thing , "dw" ); | 56 | dw = new DiceWidget( thing , "dw" ); |
57 | connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); | ||
44 | 58 | ||
45 | vbox->addWidget( sb ); | 59 | vbox->addWidget( sb ); |
46 | vbox->addWidget( dw ); | 60 | vbox->addWidget( dw ); |
47 | |||
48 | setPlayerNumber( 2 ); | ||
49 | setRoundsNumber( 1 ); | ||
50 | |||
51 | connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); | ||
52 | } | 61 | } |
53 | 62 | ||
54 | OYatzee::~OYatzee() | 63 | OYatzee::~OYatzee() |
55 | { | 64 | { |
@@ -159,10 +168,8 @@ void OYatzee::detectPosibilities() | |||
159 | } | 168 | } |
160 | 169 | ||
161 | void OYatzee::displayPossibilites() | 170 | void OYatzee::displayPossibilites() |
162 | { | 171 | { |
163 | qDebug( "running displayPossibilites(), %d item", posibilities.count() ); | ||
164 | |||
165 | for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it ) | 172 | for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it ) |
166 | { | 173 | { |
167 | qDebug( QString::number( *it ) ); | 174 | qDebug( QString::number( *it ) ); |
168 | switch ( *it ) | 175 | switch ( *it ) |
@@ -239,10 +246,38 @@ void OYatzee::slotRollDices() | |||
239 | 246 | ||
240 | /* | 247 | /* |
241 | * Scoreboard | 248 | * Scoreboard |
242 | */ | 249 | */ |
243 | Scoreboard::Scoreboard( QWidget *parent, const char *name ) : QWidget( parent , name ) | 250 | Scoreboard::Scoreboard( playerList ps, QWidget *parent, const char *name ) : QWidget( parent , name ) |
251 | { | ||
252 | ps_ = ps; | ||
253 | |||
254 | pb = new Possibilityboard( this , "pb" ); | ||
255 | |||
256 | createResultboards( 4 ); | ||
257 | |||
258 | QHBoxLayout *hbox = new QHBoxLayout( this ); | ||
259 | |||
260 | hbox->addWidget( pb ); | ||
261 | |||
262 | hbox->addSpacing( 25 ); | ||
263 | |||
264 | Resultboard *r = rbList.first(); | ||
265 | |||
266 | for ( ; r != 0 ; r = rbList.next() ) | ||
267 | { | ||
268 | hbox->addWidget( r ); | ||
269 | } | ||
270 | } | ||
271 | |||
272 | void Scoreboard::createResultboards(const int num) | ||
244 | { | 273 | { |
274 | Player *p = ps_.first(); | ||
275 | for ( int i = 0 ; i < num ; ++i , p = ps_.next() ) | ||
276 | { | ||
277 | QString n = p->playerName; | ||
278 | rbList.append( new Resultboard( n , this ) ); | ||
279 | } | ||
245 | } | 280 | } |
246 | 281 | ||
247 | void Scoreboard::paintEvent( QPaintEvent * ) | 282 | void Scoreboard::paintEvent( QPaintEvent * ) |
248 | { | 283 | { |
@@ -360,4 +395,63 @@ Player::Player( QString name ) | |||
360 | { | 395 | { |
361 | playerName = name; | 396 | playerName = name; |
362 | } | 397 | } |
363 | 398 | ||
399 | |||
400 | /* | ||
401 | * Board | ||
402 | */ | ||
403 | Board::Board( QWidget *parent , const char* name ) : QWidget ( parent , name ) | ||
404 | { | ||
405 | } | ||
406 | |||
407 | void Board::paintEvent( QPaintEvent* ) | ||
408 | { | ||
409 | QPainter p; | ||
410 | p.begin( this ); | ||
411 | |||
412 | p.drawRect( 0,0, this->width() , this->height() ); | ||
413 | } | ||
414 | |||
415 | /* | ||
416 | * Resultboard | ||
417 | */ | ||
418 | |||
419 | Resultboard::Resultboard( QString playerName , QWidget *parent , const char* name ) : Board ( parent , name ) | ||
420 | { | ||
421 | pName = playerName; | ||
422 | } | ||
423 | |||
424 | void Resultboard::paintEvent( QPaintEvent* ) | ||
425 | { | ||
426 | QPainter p; | ||
427 | p.begin( this ); | ||
428 | |||
429 | p.drawText( 10,10, pName ); | ||
430 | p.drawRect( 0,0, this->width() , this->height() ); | ||
431 | } | ||
432 | |||
433 | /* | ||
434 | * Possibilityboard | ||
435 | */ | ||
436 | |||
437 | Possibilityboard::Possibilityboard( QWidget *parent , const char* name ) : Board ( parent , name ) | ||
438 | { | ||
439 | } | ||
440 | |||
441 | void Possibilityboard::paintEvent( QPaintEvent* ) | ||
442 | { | ||
443 | QPainter p; | ||
444 | p.begin( this ); | ||
445 | |||
446 | p.drawRect( 0,0, this->width() , this->height() ); | ||
447 | } | ||
448 | |||
449 | /* | ||
450 | * Game | ||
451 | */ | ||
452 | |||
453 | Game::Game( playerList pla ) | ||
454 | { | ||
455 | players = pla; | ||
456 | } | ||
457 | |||
diff --git a/noncore/games/oyatzee/oyatzee.h b/noncore/games/oyatzee/oyatzee.h index 65a18fc..dd996ee 100644 --- a/noncore/games/oyatzee/oyatzee.h +++ b/noncore/games/oyatzee/oyatzee.h | |||
@@ -11,11 +11,15 @@ | |||
11 | class Dice; | 11 | class Dice; |
12 | class Game; | 12 | class Game; |
13 | class Scoreboard; | 13 | class Scoreboard; |
14 | class DiceWidget; | 14 | class DiceWidget; |
15 | class Resultboard; | ||
16 | class Player; | ||
15 | 17 | ||
16 | typedef QList<Dice> dicesList; | 18 | typedef QList<Dice> dicesList; |
19 | typedef QList<Resultboard> resultboardList; | ||
17 | typedef QValueList<int> QValueListInt; | 20 | typedef QValueList<int> QValueListInt; |
21 | typedef QList<Player> playerList; | ||
18 | 22 | ||
19 | class OYatzee : public QMainWindow { | 23 | class OYatzee : public QMainWindow { |
20 | Q_OBJECT | 24 | Q_OBJECT |
21 | public: | 25 | public: |
@@ -53,8 +57,11 @@ class OYatzee : public QMainWindow { | |||
53 | private: | 57 | private: |
54 | int numOfPlayers; | 58 | int numOfPlayers; |
55 | int numOfRounds; | 59 | int numOfRounds; |
56 | 60 | ||
61 | /* | ||
62 | * Check what posibilities the player currently has | ||
63 | */ | ||
57 | void detectPosibilities(); | 64 | void detectPosibilities(); |
58 | void displayPossibilites(); | 65 | void displayPossibilites(); |
59 | 66 | ||
60 | }; | 67 | }; |
@@ -93,18 +100,60 @@ class DiceWidget : public QWidget | |||
93 | 100 | ||
94 | dicesList diceList; | 101 | dicesList diceList; |
95 | }; | 102 | }; |
96 | 103 | ||
104 | |||
105 | class Board : public QWidget | ||
106 | { | ||
107 | Q_OBJECT | ||
108 | public: | ||
109 | Board( QWidget *parent = 0, const char* name = 0 ); | ||
110 | |||
111 | protected: | ||
112 | virtual void paintEvent( QPaintEvent *e ); | ||
113 | }; | ||
114 | |||
115 | class Possibilityboard : public Board | ||
116 | { | ||
117 | Q_OBJECT | ||
118 | |||
119 | public: | ||
120 | Possibilityboard( QWidget *parent = 0, const char* name = 0 ); | ||
121 | |||
122 | protected: | ||
123 | virtual void paintEvent( QPaintEvent *e ); | ||
124 | }; | ||
125 | |||
126 | class Resultboard : public Board | ||
127 | { | ||
128 | Q_OBJECT | ||
129 | |||
130 | public: | ||
131 | Resultboard( QString playerName , QWidget *parent = 0, const char* name = 0 ); | ||
132 | QString pName; | ||
133 | |||
134 | protected: | ||
135 | virtual void paintEvent( QPaintEvent *e ); | ||
136 | }; | ||
137 | |||
138 | |||
97 | class Scoreboard : public QWidget | 139 | class Scoreboard : public QWidget |
98 | { | 140 | { |
99 | Q_OBJECT | 141 | Q_OBJECT |
100 | public: | 142 | public: |
101 | Scoreboard( QWidget *parent = 0, const char* name = 0 ); | 143 | Scoreboard( playerList ps, QWidget *parent = 0, const char* name = 0 ); |
144 | |||
145 | Possibilityboard *pb; | ||
146 | resultboardList rbList; | ||
147 | playerList ps_; | ||
102 | 148 | ||
149 | void createResultboards(const int); | ||
150 | |||
103 | protected: | 151 | protected: |
104 | void paintEvent( QPaintEvent *e ); | 152 | void paintEvent( QPaintEvent *e ); |
105 | }; | 153 | }; |
106 | 154 | ||
155 | |||
107 | class Player | 156 | class Player |
108 | { | 157 | { |
109 | public: | 158 | public: |
110 | Player( QString name ); | 159 | Player( QString name ); |
@@ -112,5 +161,12 @@ class Player | |||
112 | QString playerName; | 161 | QString playerName; |
113 | int totalPoints; | 162 | int totalPoints; |
114 | }; | 163 | }; |
115 | 164 | ||
165 | class Game | ||
166 | { | ||
167 | public: | ||
168 | Game( playerList pla ); | ||
169 | playerList players; | ||
170 | }; | ||
171 | |||
116 | #endif // WORDGAME_H | 172 | #endif // WORDGAME_H |