Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

oyatzee.h

Go to the documentation of this file.
00001 #ifndef WORDGAME_H
00002 #define WORDGAME_H
00003 
00004 #include <qmainwindow.h>
00005 #include <qlabel.h>
00006 #include <qlist.h>
00007 #include <qmap.h>
00008 #include <qsplitter.h>
00009 
00010 #include <stdlib.h>       // rand() function
00011 #include <qdatetime.h>        // seed for rand()
00012 
00013 class Dice;
00014 class Game;
00015 class Scoreboard;
00016 class DiceWidget;
00017 class Resultboard;
00018 class Player;
00019 
00020 class QPoint;
00021 
00022 typedef QList<Dice> dicesList;
00023 typedef QList<Resultboard> resultboardList;
00024 typedef QValueList<int> QValueListInt;
00025 typedef QList<Player> playerList;
00026 typedef QMap<int,int> pointMap;
00027 
00028 class OYatzee : public QMainWindow {
00029         Q_OBJECT
00030         public:
00031                 OYatzee( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
00032                 ~OYatzee();
00033                 static QString appName() { return QString::fromLatin1("oyatzee"); }
00034 
00035                 Game *g();
00036                 DiceWidget *dw;
00037                 Scoreboard *sb;
00038 
00039                 QValueListInt posibilities;             
00040                 playerList ps;
00041                 
00042                 void setPlayerNumber( const int num );
00043                 void setRoundsNumber( const int num );
00044                 
00045                 enum {  Ones = 1, 
00046                                 Twos = 2,
00047                                 Threes = 3,
00048                                 Fours = 4,
00049                                 Fives = 5,
00050                                 Sixes = 6,
00051                                 ThreeOfAKind = 9,        //12444
00052                                 FourOfAKind = 10,        //14444
00053                                 FullHouse = 11,          //22555
00054                                 SStraight = 12,          //13456
00055                                 LStraight = 13,          //12345
00056                                 Yatzee = 14,             //55555
00057                                 Chance = 15};
00058 
00059         public slots:
00060                 void slotStartGame();
00061                 void slotRollDices();
00062                 void slotEndRound( int );
00063 
00064         private:
00065                 int numOfPlayers;
00066                 int numOfRounds;
00067                 int currentPlayer; /* the number of the current player */
00068 
00069                 int oakPoints;
00070 
00071                 void nextPlayer();
00072 
00073                 bool lastPlayerFinished;
00074 
00075                 /*
00076                  * Check what posibilities the player currently has
00077                  */
00078                 void detectPosibilities();
00079                 void displayPossibilites();
00080 
00081                 int getPoints( const int , QValueListInt );
00082                 
00083                 void startGame();
00084                 void stopGame();
00085 
00086 };
00087 
00088 class Dice : public QFrame
00089 {
00090         Q_OBJECT
00091         public:
00092                 Dice( QWidget* parent = 0, const char* name = 0 );
00093 
00094                 bool isSelected;
00095 
00096                 const int hasValue() const;
00097                 void roll();
00098 
00099         private:
00100                 int Value;
00101 
00102         private slots:
00103                 void slotSelected();
00104 
00105         signals:
00106                 void selected();
00107         
00108         protected:
00109                 void paintEvent( QPaintEvent *e );
00110                 void paintNumber( QPainter *p );
00111                 virtual void mousePressEvent( QMouseEvent* );
00112 };
00113 
00114 class DiceWidget : public QWidget
00115 {
00116         Q_OBJECT
00117         public:
00118                 DiceWidget( QWidget *parent = 0, const char* name = 0 );
00119 
00120                 QPushButton *rollButton;
00121 
00122                 dicesList diceList;
00123 };
00124 
00125 class Board : public QWidget
00126 {
00127         Q_OBJECT
00128         public:
00129                 Board( QWidget *parent = 0, const char* name = 0 );
00130         
00131         signals:
00132                 void clicked( QPoint );
00133                 void item( int );
00134         
00135         protected:
00136                 virtual void mousePressEvent( QMouseEvent* );
00137 };
00138 
00139 class Possibilityboard : public Board
00140 {
00141         Q_OBJECT
00142 
00143         public:
00144                 Possibilityboard( QWidget *parent = 0, const char* name = 0 );
00145 
00146                 QValueListInt list;
00147                 void setIntlist( QValueListInt& );
00148         
00149         private:
00150                 QStringList begriffe;
00151 
00152         private slots:
00153                 /*
00154                  * this slot returns the item the user has selected
00155                  */
00156                 virtual void slotClicked(QPoint);
00157 
00158         protected:
00159                 virtual void paintEvent( QPaintEvent *e );
00160 };
00161 
00162 class Resultboard : public Board
00163 {
00164         Q_OBJECT
00165 
00166         public:
00167                 Resultboard( QString playerName = 0 , QWidget *parent = 0, const char* name = 0 );
00168                 QString pName;
00169 
00170                 pointMap pMap;
00171 
00172                 void updateMap( int, int );
00173 
00174         protected:
00175                 virtual void paintEvent(  QPaintEvent *e );
00176 };
00177 
00178 
00179 class Scoreboard : public QWidget
00180 {
00181         Q_OBJECT
00182         public:
00183                 Scoreboard( playerList ps, QWidget *parent = 0, const char* name = 0 );
00184 
00185                 Possibilityboard *pb;
00186                 resultboardList rbList;
00187                 playerList ps_;
00188                 
00189                 void createResultboards(const int);
00190 
00191                 Resultboard* nextRB(int);
00192 
00193                 
00194         protected:
00195                 void paintEvent(  QPaintEvent *e );
00196 };
00197 
00198 
00199 class Player
00200 {
00201         public:
00202                 Player( QString name );
00203 
00204                 QString playerName;
00205                 int totalPoints;
00206 
00207                 void setResults( const int , const int );
00208 
00209                 int turn;
00210 
00211                 void updateTotalPoints( QMap<int,int> );
00212                 
00213         private:
00214                 QValueListInt pResults; /* the individual results of the player */
00215 
00216                 void setupResultList(); /* only in the ctor */
00217 };
00218 
00219 #endif // WORDGAME_H

Generated on Sat Nov 5 16:17:23 2005 for OPIE by  doxygen 1.4.2