Diffstat (limited to 'noncore/games/oyatzee/oyatzee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/oyatzee/oyatzee.cpp | 149 |
1 files changed, 146 insertions, 3 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 | |||
@@ -56,16 +56,159 @@ OYatzee::~OYatzee() | |||
56 | } | 56 | } |
57 | 57 | ||
58 | void OYatzee::detectPosibilities() | 58 | void 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 | |||
161 | void 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 | ||
70 | void OYatzee::setPlayerNumber( const int num ) | 213 | void OYatzee::setPlayerNumber( const int num ) |
71 | { | 214 | { |
@@ -86,9 +229,10 @@ void OYatzee::slotRollDices() | |||
86 | Dice *d = dw->diceList.first(); | 229 | Dice *d = dw->diceList.first(); |
87 | 230 | ||
88 | for ( ; d != 0 ; d = dw->diceList.next() ) | 231 | for ( ; d != 0 ; d = dw->diceList.next() ) |
89 | { | 232 | { |
90 | d->roll(); | 233 | if ( !d->isSelected ) |
234 | d->roll(); | ||
91 | } | 235 | } |
92 | 236 | ||
93 | detectPosibilities(); | 237 | detectPosibilities(); |
94 | } | 238 | } |
@@ -202,9 +346,8 @@ DiceWidget::DiceWidget( QWidget *parent , const char *name ) : QWidget( parent | |||
202 | Dice *d = diceList.first(); | 346 | Dice *d = diceList.first(); |
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 | ||
210 | hbox->addWidget( rollButton ); | 353 | hbox->addWidget( rollButton ); |