Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 4DGL-uLCD-SE PinDetect
farkleMath.cpp
00001 //This file contains all the score calculations for the different type of dicerolls 00002 00003 #include <iostream> 00004 #include <fstream> 00005 #include <iomanip> 00006 #include <cmath> 00007 #include <cstdlib> 00008 #include <time.h> 00009 #include <string> 00010 #include <stdlib.h> 00011 #include <stdio.h> 00012 #include <sstream> 00013 00014 #include "farkleMath.h" 00015 #include "diceMath.h" 00016 #include "MMA8452.h" 00017 #include "uLCD_4DGL.h" 00018 #include "Speaker.h" 00019 #include "temperature.h" 00020 #include "PinDetect.h" 00021 #include "mbed.h" 00022 00023 using namespace std; 00024 extern MMA8452 acc; 00025 extern uLCD_4DGL uLCD; 00026 extern PinDetect pb1; 00027 extern PinDetect pb2; 00028 extern PinDetect pb3; 00029 extern Serial pc; 00030 extern Speaker mySpeaker; 00031 extern Dice dice; 00032 FarkleMath farklemath; 00033 00034 //Calls in my setters and getters so I can use them 00035 void FarkleMath::setRollScore(int input) { 00036 rollScore = input; 00037 } 00038 00039 void FarkleMath::setTurnScore(int input) { 00040 turnScore = input; 00041 } 00042 00043 int FarkleMath::getRollScore() { 00044 return rollScore; 00045 } 00046 00047 int FarkleMath::getTurnScore() { 00048 return turnScore; 00049 } 00050 00051 FarkleMath::FarkleMath() { 00052 turnScore = 0; 00053 rollScore = 0; 00054 } 00055 00056 00057 //The following code is the calculations for all possible ways 00058 //to get points in this game 00059 00060 void FarkleMath::five(bool& value) { 00061 if ((dice.getGetDiceResults(5)==(1||2))){ 00062 value = false; 00063 rollScore += (50); 00064 dice.setSetDiceResult(5, 0); 00065 dice.setTakeaway((1)); 00066 uLCD.locate(0,13); 00067 } 00068 } 00069 00070 void FarkleMath::one(bool& value) { 00071 if ((dice.getGetDiceResults(1)==(1||2))){ 00072 value = false; 00073 rollScore += (100); 00074 dice.setTakeaway((1)); 00075 dice.setSetDiceResult(1, 0); 00076 uLCD.locate(0,13); 00077 } 00078 } 00079 00080 void FarkleMath::twofive(bool& value) { 00081 if ((dice.getGetDiceResults(5)== 2)){ 00082 value = false; 00083 rollScore += (100); 00084 dice.setSetDiceResult(5, 0); 00085 dice.setTakeaway((2)); 00086 uLCD.locate(0,13); 00087 } 00088 } 00089 00090 void FarkleMath::twoone(bool& value) { 00091 if ((dice.getGetDiceResults(1)==2)){ 00092 value = false; 00093 rollScore += (200); 00094 dice.setTakeaway((2)); 00095 dice.setSetDiceResult(1, 0); 00096 uLCD.locate(0,13); 00097 } 00098 } 00099 00100 void FarkleMath::threeOne(bool& value) { 00101 if ((dice.getGetDiceResults(1)==3)){ 00102 value = false; 00103 rollScore += 1000; 00104 dice.setSetDiceResult(1, 0); 00105 dice.setTakeaway(3); 00106 uLCD.locate(0,13); 00107 } 00108 } 00109 00110 void FarkleMath::threeTwo(bool& value) { 00111 if ((dice.getGetDiceResults(2)==3)){ 00112 value = false; 00113 rollScore += 200; 00114 dice.setSetDiceResult(2, 0); 00115 dice.setTakeaway(3); 00116 uLCD.locate(0,13); 00117 } 00118 } 00119 00120 void FarkleMath::threeThree(bool& value) { 00121 if ((dice.getGetDiceResults(3)==3)){ 00122 value = false; 00123 rollScore += 300; 00124 dice.setSetDiceResult(3, 0); 00125 dice.setTakeaway(3); 00126 uLCD.locate(0,13); 00127 } 00128 } 00129 00130 void FarkleMath::threeFour(bool& value) { 00131 if ((dice.getGetDiceResults(4)==3)){ 00132 value = false; 00133 rollScore += 400; 00134 dice.setSetDiceResult(4, 0); 00135 dice.setTakeaway(3); 00136 uLCD.locate(0,13); 00137 } 00138 } 00139 00140 void FarkleMath::threeFive(bool& value) { 00141 if ((dice.getGetDiceResults(5)==3)){ 00142 value = false; 00143 rollScore += 500; 00144 dice.setSetDiceResult(5, 0); 00145 dice.setTakeaway(3); 00146 uLCD.locate(0,13); 00147 } 00148 } 00149 00150 void FarkleMath::threeSix(bool& value) { 00151 if ((dice.getGetDiceResults(6)==3)) { 00152 value = false; 00153 rollScore += 600; 00154 dice.setTakeaway(3); 00155 dice.setSetDiceResult(6, 0); 00156 uLCD.locate(0,13); 00157 } 00158 } 00159 00160 void FarkleMath::flush(bool& value) { 00161 if ((dice.getGetDiceResults(1)==1)&&(dice.getGetDiceResults(2)==2)&& 00162 (dice.getGetDiceResults(3)==3)&&(dice.getGetDiceResults(4)==4)&& 00163 (dice.getGetDiceResults(5)==5)&&(dice.getGetDiceResults(6)==6)) { 00164 value = false; 00165 rollScore += 1500; 00166 dice.setTakeaway(6); 00167 for(int i = 1; i<=6; i++) { 00168 dice.setSetDiceResult(i, 0); 00169 uLCD.locate(0,13); 00170 } 00171 } 00172 } 00173 //why find easy ways to do stuff when you can just hard code it into the game! 00174 void FarkleMath::threePairs(bool& value) { 00175 bool one = (dice.getGetDiceResults(1) == 2); 00176 bool two = (dice.getGetDiceResults(2) == 2); 00177 bool three = (dice.getGetDiceResults(3) == 2); 00178 bool four = (dice.getGetDiceResults(4) == 2); 00179 bool five = (dice.getGetDiceResults(5) == 2); 00180 bool six = (dice.getGetDiceResults(6) == 2); 00181 //all possible combinations of the dice to get 00182 bool oneTwoThree = ((one && two && three) == true); 00183 bool oneTwoFour = ((one && two && four) == true); 00184 bool oneTwoFive = ((one && two && five) == true); 00185 bool oneTwoSix = ((one && two && six) == true); 00186 bool oneThreeFour = ((one && three && four) == true); 00187 bool oneThreeFive = ((one && three && five) == true); 00188 bool oneThreeSix = ((one && three && six) == true); 00189 bool oneFourFive = ((one && four && five) == true); 00190 bool oneFourSix = ((one && four && six) == true); 00191 bool oneFiveSix = ((one && five && six) == true); 00192 bool twoThreeFour = ((two && three && four) == true); 00193 bool twoThreeFive = ((two && three && five) == true); 00194 bool twoThreeSix = ((two && three && six) == true); 00195 bool twoFourFive = ((two && four && five) == true); 00196 bool twoFourSix = ((two && four && six) == true); 00197 bool twoFiveSix = ((two && five && six) == true); 00198 bool threeFourFive = ((three && four && five) == true); 00199 bool threeFourSix = ((three && four && six) == true); 00200 bool threeFiveSix = ((three && five && six) == true); 00201 00202 if ((oneTwoThree || oneTwoFour || oneTwoFive || oneTwoSix 00203 || oneThreeFour || oneThreeFive || oneThreeSix || oneFourFive 00204 || oneFourSix || oneFiveSix || twoThreeFour || twoThreeFive 00205 || twoThreeSix || twoFourFive || twoFourSix || twoFiveSix 00206 || threeFourFive || threeFourSix || threeFiveSix) == true){ 00207 value = false; 00208 rollScore += 1500; 00209 dice.setTakeaway(6); 00210 uLCD.locate(0,13); 00211 for (int k = 1; k <=6; k++){ 00212 dice.setSetDiceResult(k, 0); 00213 } 00214 } 00215 } 00216 void FarkleMath::twoTriplets(bool& value) { 00217 for (int i = 1; i <=6; i++){ 00218 if ((dice.getGetDiceResults(i)==3)){ 00219 for (int j = 1; j <=6; j++){ 00220 if (((dice.getGetDiceResults(j)==3)&&(j != i))){ 00221 value = false; 00222 rollScore += 2500; 00223 dice.setTakeaway(6); 00224 for (int k = 1; k <=6; k++){ 00225 dice.setSetDiceResult(k, 0); 00226 uLCD.locate(0,13); 00227 } 00228 } 00229 } 00230 } 00231 } 00232 } 00233 00234 void FarkleMath::fourOfAKind(bool& value) { 00235 for (int i = 1; i <=6; i++){ 00236 if ((dice.getGetDiceResults(i)==4)) { 00237 value = false; 00238 rollScore += 1000; 00239 dice.setSetDiceResult(i, 0); 00240 dice.setTakeaway(4); 00241 uLCD.locate(0,13); 00242 } 00243 } 00244 } 00245 void FarkleMath::fiveOfAKind(bool& value) { 00246 for (int i = 1; i <=6; i++){ 00247 if ((dice.getGetDiceResults(i)==5)) { 00248 value = false; 00249 rollScore += 2000; 00250 dice.setSetDiceResult(i, 0); 00251 dice.setTakeaway(5); 00252 uLCD.locate(0,13); 00253 } 00254 } 00255 } 00256 void FarkleMath::sixOfAKind(bool& value) { 00257 for (int i = 1; i <=6; i++) { 00258 if ((dice.getGetDiceResults(i)==6)) { 00259 value = false; 00260 rollScore += 3000; 00261 dice.setSetDiceResult(i, 0); 00262 dice.setTakeaway(6); 00263 uLCD.locate(0,13); 00264 } 00265 } 00266 } 00267 00268 void FarkleMath::isZero(bool& value){ 00269 if (value == true){ 00270 rollScore = 0; 00271 } 00272 } 00273 00274 void FarkleMath::printRollScore(bool& value){ 00275 if (value == false){ 00276 uLCD.locate(0,13); 00277 uLCD.text_width(1); 00278 uLCD.text_height(1); 00279 uLCD.printf("Roll Score: %d\n",rollScore); 00280 } 00281 } 00282 void FarkleMath::printTurnScore(bool& value){ 00283 if (value == false){ 00284 uLCD.locate(0,14); 00285 uLCD.text_width(1); 00286 uLCD.text_height(1); 00287 uLCD.printf("Turn Score: %d", turnScore); 00288 } 00289 } 00290 00291 void FarkleMath::printFarkle(bool& value){ 00292 if (value == true){ 00293 rollScore = 0; 00294 turnScore = 0; 00295 uLCD.locate(0,12); 00296 uLCD.text_width(3); 00297 uLCD.text_height(3); 00298 uLCD.printf("FARKLE"); 00299 } 00300 } 00301 //Prints the end game screen with amount of points for turn 00302 void FarkleMath::printEndGame(int value) { 00303 uLCD.cls(); 00304 uLCD.text_width(2); 00305 uLCD.text_height(2); 00306 uLCD.printf("This\n"); 00307 uLCD.printf("Turns\n"); 00308 uLCD.printf("Score Is\n"); 00309 uLCD.printf("--------\n"); 00310 uLCD.printf("%d\n", value); 00311 uLCD.printf("Points!\n"); 00312 } 00313 //Calculates the score for a turn. Set in a way from what gives the 00314 //highest score to the lowest score. These are all function calls. 00315 void FarkleMath::calculateScore(){ 00316 temp = true; 00317 sixOfAKind(temp); 00318 fiveOfAKind(temp); 00319 fourOfAKind(temp); 00320 twoTriplets(temp); 00321 threePairs(temp); 00322 flush(temp); 00323 threeSix(temp); 00324 threeFive(temp); 00325 threeFour(temp); 00326 threeThree(temp); 00327 threeTwo(temp); 00328 threeOne(temp); 00329 twoone(temp); 00330 twofive(temp); 00331 one(temp); 00332 five(temp); 00333 isZero(temp); 00334 turnScore = turnScore + rollScore; 00335 printRollScore(temp); 00336 printTurnScore(temp); 00337 printFarkle(temp); 00338 rollScore = 0; 00339 }
Generated on Mon Aug 8 2022 08:07:50 by
1.7.2