MatthijsFontys

Technology Camel Race

Sep 6th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. /*
  2. Color sensor = S3
  3. \EV3 System Files\Sounds
  4. playSoundFile("/home/root/lms2012/resources/Sounds/Active");
  5. */
  6.  
  7.  
  8.  
  9.     // Mijn set motor sync functie
  10. void setBoth(int speed){
  11.     setMotorSpeed(motorB, speed);
  12.     setMotorSpeed(motorC, speed);
  13. }
  14.  
  15.     // Swap 2 int values
  16. /*
  17. void swapVal(int val_1, int val_2){
  18.     int swapper = val_1;
  19.     val_1 = val_2;
  20.     val_2 = swapper;
  21.     */
  22.  
  23. task main()
  24. {
  25.     bool done = false;
  26.     waitUntil(getTouchValue(S1));
  27.    
  28.     // Start de motoren
  29.     setBoth(20);
  30.  
  31.     // Als de kleur niet zwart is blijf doorgaan
  32.     while(getColorName(S3) != colorBlack){
  33.     }
  34.  
  35.     // Stop de motoren, omdat hij bij de zwarte streep is
  36.     setBoth(0);
  37.     playSound(soundBeepBeep); // play active sound instead
  38.    
  39.     // als de bot nog niet bij wit is
  40.     while(done == false){
  41.     // De variabele voor de som
  42.     int tafel = 10;
  43.     int randomSum = random(10);
  44.     int answer = randomSum * tafel;
  45.     int wrong;
  46.     int good_button;
  47.     // zorg ervoor dat het verkeerde antwoord niet gelijk is aan het goede antwoord
  48.     do{
  49.         wrong = random(10) * tafel;
  50.         }while(wrong == tafel);
  51.  
  52.     // Sometimes swaps the left and right number in the sum
  53.     if(random(1) == 0){
  54.         //swapVal(tafel, randomSum);
  55.         int swapper = tafel;
  56.         tafel = randomSum;
  57.         randomSum = swapper;
  58.     }
  59.  
  60.     if(random(1) == 0){
  61.         //swapVal(answer, wrong);
  62.         int swapper = answer;
  63.         answer = wrong;
  64.         wrong = swapper;
  65.         good_button = 1; // rechtse knop is goed
  66.     }
  67.     else{good_button = 0;
  68.         } // linkse knop is goed
  69.  
  70.     // Display de som
  71.     while(getButtonPress(buttonLeft) == 0 && getButtonPress(buttonRight) == 0){
  72.     displayBigTextLine(2, "%d x %d", tafel, randomSum);
  73.    
  74.     // display antwoord mogelijkheden
  75.     displayBigTextLine(6, "%d    %d", answer, wrong);
  76. }
  77.  
  78.  
  79.     if((getButtonPress(buttonLeft) == 1 && good_button == 0) || (getButtonPress(buttonRight) == 1 && good_button == 1)){
  80.         displayBigTextLine(2, "Goed");
  81.         setBoth(50);
  82.         delay(2000);
  83.         setBoth(0);
  84.     }
  85.     else{
  86.         displayBigTextLine(2, "Fout");
  87.         delay(50000);
  88.     }
  89. }
  90.    
  91. }
Advertisement
Add Comment
Please, Sign In to add comment