summaryrefslogtreecommitdiff
path: root/noncore/games/oyatzee/oyatzee.h
blob: a38182daf35c829dd57c8bc42e9eca59d48eebe9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#ifndef WORDGAME_H
#define WORDGAME_H

#include <qmainwindow.h>
#include <qlabel.h>
#include <qlist.h>
#include <qmap.h>
#include <qsplitter.h>

#include <stdlib.h>       // rand() function
#include <qdatetime.h>        // seed for rand()

class Dice;
class Game;
class Scoreboard;
class DiceWidget;
class Resultboard;
class Player;

class QPoint;

typedef QList<Dice> dicesList;
typedef QList<Resultboard> resultboardList;
typedef QValueList<int> QValueListInt;
typedef QList<Player> playerList;
typedef QMap<int,int> pointMap;

class OYatzee : public QMainWindow {
	Q_OBJECT
	public:
		OYatzee( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
		~OYatzee();
		static QString appName() { return QString::fromLatin1("oyatzee"); }

		Game *g();
		DiceWidget *dw;
		Scoreboard *sb;

		QValueListInt posibilities;		
		playerList ps;
		
		void setPlayerNumber( const int num );
		void setRoundsNumber( const int num );
		
		enum {  Ones = 1, 
				Twos = 2,
				Threes = 3,
				Fours = 4,
				Fives = 5,
				Sixes = 6,
				ThreeOfAKind = 9,        //12444
				FourOfAKind = 10,        //14444
				FullHouse = 11,          //22555
				SStraight = 12,          //13456
				LStraight = 13,          //12345
				Yatzee = 14,             //55555
				Chance = 15};

	public slots:
		void slotStartGame();
		void slotRollDices();
		void slotEndRound( int );

	private:
		int numOfPlayers;
		int numOfRounds;
		int currentPlayer; /* the number of the current player */

		int oakPoints;

		void nextPlayer();

		bool lastPlayerFinished;

		/*
		 * Check what posibilities the player currently has
		 */
		void detectPosibilities();
		void displayPossibilites();

		int getPoints( const int , QValueListInt );
		
		void startGame();
		void stopGame();

};

class Dice : public QFrame
{
	Q_OBJECT
	public:
		Dice( QWidget* parent = 0, const char* name = 0 );

		bool isSelected;

		const int hasValue() const;
		void roll();

	private:
		int Value;

	private slots:
		void slotSelected();

	signals:
		void selected();
	
	protected:
		void paintEvent( QPaintEvent *e );
		void paintNumber( QPainter *p );
		virtual void mousePressEvent( QMouseEvent* );
};

class DiceWidget : public QWidget
{
	Q_OBJECT
	public:
		DiceWidget( QWidget *parent = 0, const char* name = 0 );

		QPushButton *rollButton;

		dicesList diceList;
};

class Board : public QWidget
{
	Q_OBJECT
	public:
		Board( QWidget *parent = 0, const char* name = 0 );
	
	signals:
		void clicked( QPoint );
		void item( int );
	
	protected:
		virtual void mousePressEvent( QMouseEvent* );
};

class Possibilityboard : public Board
{
	Q_OBJECT

	public:
		Possibilityboard( QWidget *parent = 0, const char* name = 0 );

		QValueListInt list;
		void setIntlist( QValueListInt& );
	
	private:
		QStringList begriffe;

	private slots:
		/*
		 * this slot returns the item the user has selected
		 */
		virtual void slotClicked(QPoint);

	protected:
		virtual void paintEvent( QPaintEvent *e );
};

class Resultboard : public Board
{
	Q_OBJECT

	public:
		Resultboard( QString playerName = 0 , QWidget *parent = 0, const char* name = 0 );
		QString pName;

		pointMap pMap;

		void updateMap( int, int );

	protected:
		virtual void paintEvent(  QPaintEvent *e );
};


class Scoreboard : public QWidget
{
	Q_OBJECT
	public:
		Scoreboard( playerList ps, QWidget *parent = 0, const char* name = 0 );

		Possibilityboard *pb;
		resultboardList rbList;
		playerList ps_;
		
		void createResultboards(const int);

		Resultboard* nextRB(int);

		
	protected:
		void paintEvent(  QPaintEvent *e );
};


class Player
{
	public:
		Player( QString name );

		QString playerName;
		int totalPoints;

		void setResults( const int , const int );

		int turn;

		void updateTotalPoints( QMap<int,int> );
		
	private:
		QValueListInt pResults; /* the individual results of the player */

		void setupResultList(); /* only in the ctor */
};

#endif // WORDGAME_H