ECE 4180 Final Project

Dependencies:   4DGL-uLCD-SE PinDetect mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers farkel_class.cpp Source File

farkel_class.cpp

00001 #include "farkel_class.h"
00002     
00003     uLCD_4DGL uLCD(p9,p10,p11);
00004     PinDetect pb1(p21);
00005     PinDetect pb2(p22);
00006     PinDetect pb3(p23);
00007     //set the push buttons that control sounds
00008 
00009 
00010 
00011     int xarry[] = {22,22,64,64,105,105};
00012     int yarry[] = {32,96,32,96,32,96};
00013     int diceColor = 0xFFFFFF;
00014     int identity =0;
00015     int num1 = 0;
00016     int num2 = 0;
00017     int num3 = 0;
00018     int num4 = 0;
00019     int num5 = 0;
00020     int num6 = 0;        
00021         farkel::farkel(){
00022             identity = 0; 
00023             }
00024             
00025             void farkel::testPrint(int flag){
00026                 uLCD.printf("%5.2i",flag);
00027             }
00028             
00029             void farkel::clearSc(){
00030                 uLCD.cls();
00031             }
00032             
00033             void farkel::mainMenu(int diceNum){
00034                 uLCD.text_width(1);
00035                 uLCD.text_height(1);
00036                 uLCD.locate(0,1);
00037                 uLCD.printf("who's ready\n");
00038                 uLCD.printf("to fark!!\n");
00039                 uLCD.printf("\n");
00040                 uLCD.printf("Select dice #:\n");
00041                 uLCD.printf("%5.2i", diceNum);          
00042                 }
00043                 
00044         /*int farkel::whileBrake(int mainMenuFlag){
00045             int breakflag = 1;
00046             breakflag = shakeDetect(breakflag);
00047             if(breakflag == 0){
00048                 mainMenuFlag = 2;
00049                     }
00050             return mainMenuFlag;
00051             }  */
00052             
00053             int farkel::diceNumInc(int diceNum){
00054                 if(pb1 == false){
00055                     diceNum = ((diceNum +1)%7);
00056                     }
00057                 return diceNum;
00058                 } 
00059                 
00060     
00061             
00062         farkel::farkel(int randomNum){
00063             identity = randomNum;
00064                 pb1.mode(PullUp);
00065                 pb2.mode(PullUp);
00066                 pb3.mode(PullUp);
00067             }
00068         void farkel::dicePlacer(int dicePlace,int identity,int gameScore){ 
00069         
00070             if(dicePlace == 0){
00071                 uLCD.printf("Farkel");            
00072                 uLCD.printf(" score:");       
00073                 uLCD.printf("%5.2i", gameScore);
00074             }
00075         
00076             int x1=xarry[dicePlace] + 20;
00077             int x2=xarry[dicePlace] - 20;
00078             int y1=yarry[dicePlace] + 20;
00079             int y2=yarry[dicePlace] - 20;
00080             uLCD.rectangle(x1,y1,x2,y2,WHITE);
00081         switch(identity){
00082             case 1://if dice =1
00083                 uLCD.filled_circle(xarry[dicePlace] , yarry[dicePlace] ,3, WHITE);
00084                 num1++;
00085             break;
00086             
00087             case 2://if dice =2
00088          
00089                 uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]- 10), 3, WHITE);
00090                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+10) ,3, WHITE);
00091                 num2++;
00092 
00093             break;
00094             
00095             case 3://so on
00096                 uLCD.filled_circle((xarry[dicePlace]) , (yarry[dicePlace]) ,3, WHITE);
00097                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+10) ,3, WHITE);
00098                 uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace] - 10) ,3, WHITE);
00099                 num3++;
00100 
00101             break;  
00102                       
00103             case 4://so forth 
00104                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]- 10) ,3, WHITE);
00105                 uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]+10) ,3, WHITE);
00106                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+ 10) ,3, WHITE);
00107                 uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]- 10) ,3, WHITE);
00108                 num4++;
00109 
00110             break; 
00111                        
00112             case 5:
00113               
00114                 uLCD.filled_circle((xarry[dicePlace]) , (yarry[dicePlace]) ,3, WHITE);
00115                 uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]+ 10) ,3, WHITE);
00116                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+10) ,3, WHITE);
00117                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]- 10) ,3, WHITE);
00118                 uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]- 10) ,3, WHITE);
00119                 num5++;
00120             break;                
00121             case 6:
00122        
00123                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]- 10) ,3, WHITE);
00124                 uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]+10) ,3, WHITE);
00125                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+ 10) ,3, WHITE);
00126                 uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]- 10) ,3, WHITE);
00127                 uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]) ,3, WHITE);
00128                 uLCD.filled_circle((xarry[dicePlace]- 10 ) , (yarry[dicePlace]) ,3, WHITE);
00129                 num6++;
00130                 break;  
00131             
00132             default:
00133                 break;
00134             }
00135 
00136         }
00137         
00138         int farkel::roll(){
00139 
00140             int rando = (rand()%6)+1; return rando;
00141             }
00142     
00143     
00144     bool farkel::tripCheck(){
00145             int holder1 = 0;
00146             
00147         if (num1==3){
00148             holder1++;
00149             }
00150         if (num2==3){
00151             holder1++;
00152             }
00153         if (num3==3){
00154             holder1++;
00155             }
00156         if (num4==3){
00157             holder1++;
00158             }
00159         if (num5==3){
00160             holder1++;
00161             }
00162         if (num6==3){
00163             holder1++;
00164         }
00165             
00166         if (holder1 == 2){
00167             return true;
00168         }
00169         else{
00170         return false;
00171         }
00172     }
00173     
00174     
00175     bool farkel::dubCheck(){
00176         int holder1 = 0;
00177         
00178         if (num1==2){
00179             holder1++;
00180             }
00181         if (num2==2){
00182             holder1++;
00183             }
00184         if (num3==2){
00185             holder1++;
00186             }
00187         if (num4==2){
00188             holder1++;
00189             }
00190         if (num5==2){
00191             holder1++;
00192             }
00193         if (num6==2){
00194             holder1++;
00195             }
00196             
00197         if (holder1 == 3){
00198         return true;
00199         }
00200         else{
00201         return false;
00202         }
00203     }
00204     
00205     int farkel::gameScoring(){
00206         int score = 0;
00207         if (num6 == 6 || num5 == 6 || num4 == 6 || num3 == 6 ||num2 == 6 || num1 == 6){
00208             score = 3000;
00209             return score;
00210         }
00211         
00212         else if (tripCheck()==true){
00213             score =2500;
00214             return score;
00215         }
00216         
00217         else if(num6 == 5 || num5 == 5 || num4 == 5 || num3 == 5 ||num2 == 5 || num1 == 5){
00218             score = 2000;
00219             return score;    
00220         }
00221         
00222         
00223         else if (dubCheck()==true){
00224             score =1500;
00225             return score;
00226         }
00227         
00228         else if(num6 == 1 && num5 == 1 && num4 == 1 && num3 == 1 && num2 == 1 && num1== 1){
00229             score = 1500;
00230             return score;    
00231         }
00232         
00233         else if (num1 == 3){
00234             score = 1000;
00235             return score;
00236         }
00237               
00238         else if(num6 == 4 || num5 == 4 || num4 == 4 || num3 == 4 ||num2 == 4 || num1 == 4){
00239             score = 1000;
00240             return score;    
00241         }
00242         
00243         else if (num6 == 3){
00244             score = 600;
00245             return score;
00246         }
00247     
00248         else if (num5 == 3){
00249             score = 500;
00250             return score;
00251         }
00252 
00253         else if (num4 == 3){
00254             score = 400;
00255             return score;
00256         }
00257         
00258         else if (num3 == 3){
00259             score = 300;
00260             return score;
00261         }
00262         
00263         else if (num2 == 3){
00264             score = 200;
00265             return score;
00266         }
00267         
00268         else if (num1 >= 1){
00269             score = 100;
00270             return score;
00271         }
00272         
00273         else if (num5 >= 1){
00274             score = 50;
00275             return score;
00276         }
00277         else{
00278         return 0;
00279         }  
00280     }
00281     
00282     void farkel::printfark(){
00283         uLCD.locate(0,7);
00284         uLCD.printf("You Just Got\nFarked!!!");
00285         
00286     }
00287     
00288     int farkel::resetDie(int diceNum,int scorehold){
00289         if(scorehold == 3000 || scorehold == 1500 || scorehold == 2500){
00290             diceNum = diceNum - 6;
00291         }
00292         
00293         else if(scorehold == 2000){
00294             diceNum = diceNum - 5;
00295         }
00296         
00297         else if(scorehold == 1000 && num1 != 3){
00298             diceNum = diceNum - 4;
00299         }
00300         
00301         else if(scorehold == 600 || scorehold == 500 || scorehold == 400 || scorehold == 300 || scorehold == 200 || scorehold == 1000 ){
00302             diceNum = diceNum - 3;
00303         }
00304         
00305         else if(scorehold == 100 || scorehold == 50){
00306             diceNum = diceNum - 1;
00307         }
00308         
00309         
00310         else if(scorehold == 2000){
00311             diceNum =diceNum - 5;
00312         }
00313         
00314                
00315         num1 = 0;
00316         num2 = 0;
00317         num3 = 0;
00318         num4 = 0;
00319         num5 = 0;    
00320         num6 = 0;   
00321         return diceNum; 
00322     }
00323     
00324     int farkel::scoreingScreen(int gameScore){
00325         int resetter = 1; 
00326         uLCD.cls();
00327         while(pb2 == true){
00328                 uLCD.text_width(1.5);
00329                 uLCD.text_height(1.5);
00330                 uLCD.locate(0,1);
00331                 uLCD.printf("you'r score\n");
00332                 uLCD.printf("this round: \n");
00333                 uLCD.printf("\n");
00334                 uLCD.printf("%5.2i", gameScore);   
00335                 
00336         }
00337             return resetter;
00338     }
00339     
00340     int farkel::back2MainMenu(){
00341         if (pb2 == false){
00342         return 0;
00343         }     
00344         else{
00345         return 2;
00346         }
00347     }
00348     
00349     int farkel::butDetect(int gameScore){
00350         int holder = 1;
00351         while(1){
00352             if(pb1 == false){
00353             scoreingScreen(gameScore);
00354                return holder = 1;
00355             }
00356             if(pb3 == false){
00357                return holder = 0;
00358             }
00359         }
00360     }
00361 
00362         
00363     
00364