ECE_4180_Project / Mbed 2 deprecated Farkle_main

Dependencies:   4DGL-uLCD-SE PinDetect mbed

farkel_class.cpp

Committer:
jwalker366
Date:
2021-11-30
Revision:
0:09b7e6aa75a9

File content as of revision 0:09b7e6aa75a9:

#include "farkel_class.h"
    
    uLCD_4DGL uLCD(p9,p10,p11);
    PinDetect pb1(p21);
    PinDetect pb2(p22);
    PinDetect pb3(p23);
    //set the push buttons that control sounds



    int xarry[] = {22,22,64,64,105,105};
    int yarry[] = {32,96,32,96,32,96};
    int diceColor = 0xFFFFFF;
    int identity =0;
    int num1 = 0;
    int num2 = 0;
    int num3 = 0;
    int num4 = 0;
    int num5 = 0;
    int num6 = 0;        
        farkel::farkel(){
            identity = 0; 
            }
            
            void farkel::testPrint(int flag){
                uLCD.printf("%5.2i",flag);
            }
            
            void farkel::clearSc(){
                uLCD.cls();
            }
            
            void farkel::mainMenu(int diceNum){
                uLCD.text_width(1);
                uLCD.text_height(1);
                uLCD.locate(0,1);
                uLCD.printf("who's ready\n");
                uLCD.printf("to fark!!\n");
                uLCD.printf("\n");
                uLCD.printf("Select dice #:\n");
                uLCD.printf("%5.2i", diceNum);          
                }
                
        /*int farkel::whileBrake(int mainMenuFlag){
            int breakflag = 1;
            breakflag = shakeDetect(breakflag);
            if(breakflag == 0){
                mainMenuFlag = 2;
                    }
            return mainMenuFlag;
            }  */
            
            int farkel::diceNumInc(int diceNum){
                if(pb1 == false){
                    diceNum = ((diceNum +1)%7);
                    }
                return diceNum;
                } 
                
    
            
        farkel::farkel(int randomNum){
            identity = randomNum;
                pb1.mode(PullUp);
                pb2.mode(PullUp);
                pb3.mode(PullUp);
            }
        void farkel::dicePlacer(int dicePlace,int identity,int gameScore){ 
        
            if(dicePlace == 0){
                uLCD.printf("Farkel");            
                uLCD.printf(" score:");       
                uLCD.printf("%5.2i", gameScore);
            }
        
            int x1=xarry[dicePlace] + 20;
            int x2=xarry[dicePlace] - 20;
            int y1=yarry[dicePlace] + 20;
            int y2=yarry[dicePlace] - 20;
            uLCD.rectangle(x1,y1,x2,y2,WHITE);
        switch(identity){
            case 1://if dice =1
                uLCD.filled_circle(xarry[dicePlace] , yarry[dicePlace] ,3, WHITE);
                num1++;
            break;
            
            case 2://if dice =2
         
                uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]- 10), 3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+10) ,3, WHITE);
                num2++;

            break;
            
            case 3://so on
                uLCD.filled_circle((xarry[dicePlace]) , (yarry[dicePlace]) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace] - 10) ,3, WHITE);
                num3++;

            break;  
                      
            case 4://so forth 
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]- 10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]+10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+ 10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]- 10) ,3, WHITE);
                num4++;

            break; 
                       
            case 5:
              
                uLCD.filled_circle((xarry[dicePlace]) , (yarry[dicePlace]) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]+ 10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]- 10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]- 10) ,3, WHITE);
                num5++;
            break;                
            case 6:
       
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]- 10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]+10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]+ 10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]- 10) , (yarry[dicePlace]- 10) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]+ 10) , (yarry[dicePlace]) ,3, WHITE);
                uLCD.filled_circle((xarry[dicePlace]- 10 ) , (yarry[dicePlace]) ,3, WHITE);
                num6++;
                break;  
            
            default:
                break;
            }

        }
        
        int farkel::roll(){

            int rando = (rand()%6)+1; return rando;
            }
    
    
    bool farkel::tripCheck(){
            int holder1 = 0;
            
        if (num1==3){
            holder1++;
            }
        if (num2==3){
            holder1++;
            }
        if (num3==3){
            holder1++;
            }
        if (num4==3){
            holder1++;
            }
        if (num5==3){
            holder1++;
            }
        if (num6==3){
            holder1++;
        }
            
        if (holder1 == 2){
            return true;
        }
        else{
        return false;
        }
    }
    
    
    bool farkel::dubCheck(){
        int holder1 = 0;
        
        if (num1==2){
            holder1++;
            }
        if (num2==2){
            holder1++;
            }
        if (num3==2){
            holder1++;
            }
        if (num4==2){
            holder1++;
            }
        if (num5==2){
            holder1++;
            }
        if (num6==2){
            holder1++;
            }
            
        if (holder1 == 3){
        return true;
        }
        else{
        return false;
        }
    }
    
    int farkel::gameScoring(){
        int score = 0;
        if (num6 == 6 || num5 == 6 || num4 == 6 || num3 == 6 ||num2 == 6 || num1 == 6){
            score = 3000;
            return score;
        }
        
        else if (tripCheck()==true){
            score =2500;
            return score;
        }
        
        else if(num6 == 5 || num5 == 5 || num4 == 5 || num3 == 5 ||num2 == 5 || num1 == 5){
            score = 2000;
            return score;    
        }
        
        
        else if (dubCheck()==true){
            score =1500;
            return score;
        }
        
        else if(num6 == 1 && num5 == 1 && num4 == 1 && num3 == 1 && num2 == 1 && num1== 1){
            score = 1500;
            return score;    
        }
        
        else if (num1 == 3){
            score = 1000;
            return score;
        }
              
        else if(num6 == 4 || num5 == 4 || num4 == 4 || num3 == 4 ||num2 == 4 || num1 == 4){
            score = 1000;
            return score;    
        }
        
        else if (num6 == 3){
            score = 600;
            return score;
        }
    
        else if (num5 == 3){
            score = 500;
            return score;
        }

        else if (num4 == 3){
            score = 400;
            return score;
        }
        
        else if (num3 == 3){
            score = 300;
            return score;
        }
        
        else if (num2 == 3){
            score = 200;
            return score;
        }
        
        else if (num1 >= 1){
            score = 100;
            return score;
        }
        
        else if (num5 >= 1){
            score = 50;
            return score;
        }
        else{
        return 0;
        }  
    }
    
    void farkel::printfark(){
        uLCD.locate(0,7);
        uLCD.printf("You Just Got\nFarked!!!");
        
    }
    
    int farkel::resetDie(int diceNum,int scorehold){
        if(scorehold == 3000 || scorehold == 1500 || scorehold == 2500){
            diceNum = diceNum - 6;
        }
        
        else if(scorehold == 2000){
            diceNum = diceNum - 5;
        }
        
        else if(scorehold == 1000 && num1 != 3){
            diceNum = diceNum - 4;
        }
        
        else if(scorehold == 600 || scorehold == 500 || scorehold == 400 || scorehold == 300 || scorehold == 200 || scorehold == 1000 ){
            diceNum = diceNum - 3;
        }
        
        else if(scorehold == 100 || scorehold == 50){
            diceNum = diceNum - 1;
        }
        
        
        else if(scorehold == 2000){
            diceNum =diceNum - 5;
        }
        
               
        num1 = 0;
        num2 = 0;
        num3 = 0;
        num4 = 0;
        num5 = 0;    
        num6 = 0;   
        return diceNum; 
    }
    
    int farkel::scoreingScreen(int gameScore){
        int resetter = 1; 
        uLCD.cls();
        while(pb2 == true){
                uLCD.text_width(1.5);
                uLCD.text_height(1.5);
                uLCD.locate(0,1);
                uLCD.printf("you'r score\n");
                uLCD.printf("this round: \n");
                uLCD.printf("\n");
                uLCD.printf("%5.2i", gameScore);   
                
        }
            return resetter;
    }
    
    int farkel::back2MainMenu(){
        if (pb2 == false){
        return 0;
        }     
        else{
        return 2;
        }
    }
    
    int farkel::butDetect(int gameScore){
        int holder = 1;
        while(1){
            if(pb1 == false){
            scoreingScreen(gameScore);
               return holder = 1;
            }
            if(pb3 == false){
               return holder = 0;
            }
        }
    }