summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/oyatzee/oyatzee.cpp147
-rw-r--r--noncore/games/oyatzee/oyatzee.h19
2 files changed, 164 insertions, 2 deletions
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp
index 85d9616..5c4d1f7 100644
--- a/noncore/games/oyatzee/oyatzee.cpp
+++ b/noncore/games/oyatzee/oyatzee.cpp
@@ -57,14 +57,157 @@ OYatzee::~OYatzee()
57 57
58void OYatzee::detectPosibilities() 58void OYatzee::detectPosibilities()
59{ 59{
60 posibilities.clear();
61 qDebug( "running detectPosibilities()" );
62
60 Dice *d = dw->diceList.first(); 63 Dice *d = dw->diceList.first();
61 64
62 QValueList<int> numbers; 65 QValueListInt numbers;
63 66
64 for ( ; d != 0 ; d = dw->diceList.next() ) 67 for ( ; d != 0 ; d = dw->diceList.next() )
65 { 68 {
66 numbers.append( d->Value ); 69 numbers.append( d->Value );
67 } 70 }
71
72 //the 6 numbers
73 QValueListInt::Iterator it;
74
75 for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6
76 {
77 bool cont = false;
78 it = numbers.begin();
79 for ( ; it != numbers.end() ; ++it )
80 {
81 if ( cont )
82 continue;
83
84 if ( numbers.find( i ) != numbers.end() )
85 {
86 posibilities.append( i );
87 cont = true;
88 }
89 }
90 }
91
92
93 //3er, 4er, Yatzee
94 it = numbers.begin();
95 int count;
96 int temp;
97 int countFH = 0; //for the full-house-check
98
99 for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 at least 3 times
100 {
101 count = 0;
102 temp = 0;
103 it = numbers.begin();
104 for ( ; it != numbers.end() ; ++it )
105 {
106 if ( *it == i )
107 {
108 count++;
109 temp++;
110 }
111 if ( temp == 2 )
112 countFH = temp;
113 }
114
115 if ( count >= 3 )
116 {
117 posibilities.append( 7 );
118
119 //now we check if it is a full house
120 if ( count == 3 && countFH == 2 ) //aka Full House
121 posibilities.append( 9 );
122 }
123 if ( count >= 4 )
124 posibilities.append( 8 );
125 if ( count == 5 ) //Yatzee
126 posibilities.append( 12 );
127 }
128
129 //S-Straight
130 if ( numbers.find( 3 ) != numbers.end() && numbers.find( 4 ) != numbers.end() )
131 {
132 bool isLong = false;
133 bool isShort = true;
134 //L-Straight
135 if ( numbers.find( 2 ) != numbers.end() && numbers.find( 5 ) != numbers.end() )
136 {
137 isShort = true;
138
139 //12345 or 23456
140 if ( numbers.find( 1 ) != numbers.end() || numbers.find( 6) != numbers.end() )
141 isLong = true;
142 }
143 //1234
144 if ( numbers.find( 1 ) != numbers.end() && numbers.find( 2 ) != numbers.end() )
145 isShort = true;
146 //3456
147 if ( numbers.find( 5 ) != numbers.end() && numbers.find( 6 ) != numbers.end() )
148 isShort = true;
149
150 if ( isShort )
151 posibilities.append( 10 );
152 if ( isLong )
153 posibilities.append( 11 );
154 }
155
156 posibilities.append( 13 ); //Chance, well, this is allways possible
157
158 displayPossibilites();
159}
160
161void OYatzee::displayPossibilites()
162{
163 qDebug( "running displayPossibilites(), %d item", posibilities.count() );
164
165 for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it )
166 {
167 qDebug( QString::number( *it ) );
168 switch ( *it )
169 {
170 case Ones:
171 qDebug( "1er" );
172 break;
173 case Twos:
174 qDebug( "2er" );
175 break;
176 case Threes:
177 qDebug( "3er" );
178 break;
179 case Fours:
180 qDebug( "4er" );
181 break;
182 case Fives:
183 qDebug( "5er" );
184 break;
185 case Sixes:
186 qDebug( "6er" );
187 break;
188 case ThreeOfAKind:
189 qDebug( "3oaK" );
190 break;
191 case FourOfAKind:
192 qDebug( "4oaK" );
193 break;
194 case FullHouse:
195 qDebug( "Full House" );
196 break;
197 case SStraight:
198 qDebug( "Short S" );
199 break;
200 case LStraight:
201 qDebug( "Long S" );
202 break;
203 case Yatzee:
204 qDebug( "Yatzee!" );
205 break;
206 case Chance:
207 qDebug( "Chance" );
208 break;
209 }
210 }
68} 211}
69 212
70void OYatzee::setPlayerNumber( const int num ) 213void OYatzee::setPlayerNumber( const int num )
@@ -87,6 +230,7 @@ void OYatzee::slotRollDices()
87 230
88 for ( ; d != 0 ; d = dw->diceList.next() ) 231 for ( ; d != 0 ; d = dw->diceList.next() )
89 { 232 {
233 if ( !d->isSelected )
90 d->roll(); 234 d->roll();
91 } 235 }
92 236
@@ -203,7 +347,6 @@ DiceWidget::DiceWidget( QWidget *parent , const char *name ) : QWidget( parent
203 347
204 for ( ; d != 0 ; d = diceList.next() ) 348 for ( ; d != 0 ; d = diceList.next() )
205 { 349 {
206 d->roll();
207 hbox->addWidget( d ); 350 hbox->addWidget( d );
208 } 351 }
209 352
diff --git a/noncore/games/oyatzee/oyatzee.h b/noncore/games/oyatzee/oyatzee.h
index 01ab36d..65a18fc 100644
--- a/noncore/games/oyatzee/oyatzee.h
+++ b/noncore/games/oyatzee/oyatzee.h
@@ -14,6 +14,7 @@ class Scoreboard;
14class DiceWidget; 14class DiceWidget;
15 15
16typedef QList<Dice> dicesList; 16typedef QList<Dice> dicesList;
17typedef QValueList<int> QValueListInt;
17 18
18class OYatzee : public QMainWindow { 19class OYatzee : public QMainWindow {
19 Q_OBJECT 20 Q_OBJECT
@@ -25,10 +26,26 @@ class OYatzee : public QMainWindow {
25 DiceWidget *dw; 26 DiceWidget *dw;
26 Scoreboard *sb; 27 Scoreboard *sb;
27 28
29 QValueListInt posibilities;
28 30
29 void setPlayerNumber( const int num ); 31 void setPlayerNumber( const int num );
30 void setRoundsNumber( const int num ); 32 void setRoundsNumber( const int num );
31 33
34 enum {
35 Ones=1,
36 Twos = 2,
37 Threes = 3,
38 Fours = 4,
39 Fives = 5,
40 Sixes = 6,
41 ThreeOfAKind = 7, //12444
42 FourOfAKind = 8, //14444
43 FullHouse = 9, //22555
44 SStraight = 10, //13456
45 LStraight = 11, //12345
46 Yatzee = 12, //55555
47 Chance = 13};
48
32 public slots: 49 public slots:
33 void slotStartGame(); 50 void slotStartGame();
34 void slotRollDices(); 51 void slotRollDices();
@@ -38,6 +55,8 @@ class OYatzee : public QMainWindow {
38 int numOfRounds; 55 int numOfRounds;
39 56
40 void detectPosibilities(); 57 void detectPosibilities();
58 void displayPossibilites();
59
41}; 60};
42 61
43class Dice : public QFrame 62class Dice : public QFrame