Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.34 KB | None | 0 0
  1. /*----------------------------------------------------------------------------
  2. -                           SE 185: Lab 06 - Bop-It!                         -
  3. -   Name:                                                                    -
  4. -   Section:                                                                 -
  5. -   NetID:                                                                   -
  6. -   Date:                                                                    -
  7. -----------------------------------------------------------------------------*/
  8.  
  9. /*----------------------------------------------------------------------------
  10. -                               Includes                                     -
  11. -----------------------------------------------------------------------------*/
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <time.h>
  15.  
  16. /*----------------------------------------------------------------------------
  17. -                               Prototypes                                   -
  18. -----------------------------------------------------------------------------*/
  19. int randomButton(int totalTime, int button);
  20.  
  21. /*----------------------------------------------------------------------------
  22. -                               Notes                                        -
  23. -----------------------------------------------------------------------------*/
  24. // Compile with gcc lab06.c -o lab06
  25. // Run with ./ds4rd.exe -d 054c:05c4 -D DS4_BT -t -b | ./lab06
  26.  
  27. /*----------------------------------------------------------------------------
  28. -                               Implementation                               -
  29. -----------------------------------------------------------------------------*/
  30. int main(int argc, char *argv[])
  31. {
  32.     int t;
  33.     int triangle = 0;
  34.     int circle = 0;
  35.     int square = 0;
  36.     int x_button = 0;
  37.     int startTime = 2500;
  38.     int currentTime = 0;
  39.     int lost = 0;
  40.     int totalTime;
  41.     int numberOfWins = 0;
  42.     int trianglePressed;
  43.     int squarePressed;
  44.     int circlePressed;
  45.     int x_buttonPressed;
  46.     srand(time(NULL)); /* This will ensure a random game each time. */
  47.        
  48.     printf("This is a Bop-It Game!\nPress the Circle Button to start the game!\n");
  49.    
  50.     while(1){
  51.         scanf("%d, %d, %d, %d, %d", &currentTime, &triangle, &circle, &x_button, &square);
  52.         if( circle ){ break; }
  53.     }
  54.    
  55.     while( !lost ){
  56.         int button = rand() % 4;
  57.         scanf("%d, %d, %d, %d, %d", &currentTime, &triangle, &circle, &x_button, &square);
  58.         int beginTime = currentTime;
  59.         int currentTarget = 2500;
  60.        
  61.         while( 1 ) {           
  62.             if( startTime >= 1000 ){               
  63.                     scanf("%d, %d, %d, %d, %d", &currentTime, &triangle, &circle, &x_button, &square);
  64.                     startTime = 2500 - ( currentTime - beginTime );
  65.  
  66.                     if(startTime <= currentTarget ){
  67.                     int whatButton = randomButton(currentTarget, button);
  68.                    
  69.                         if( currentTarget < 2400 ){
  70.                             if( triangle || circle || x_button|| square ){
  71.                                 if( whatButton == 0 && triangle){
  72.                                 printf("Correct! Here's another one!\n");
  73.                                 printf("\n");
  74.                                 numberOfWins = numberOfWins +1;
  75.                                 break;
  76.                                 }
  77.                                 if( whatButton == 1 && circle){
  78.                                 printf("Correct! Here's another one!\n");
  79.                                 printf("\n");
  80.                                 numberOfWins = numberOfWins +1;
  81.                                 break;
  82.                                 }
  83.                                 if( whatButton == 2 && square){
  84.                                 printf("Correct! Here's another one!\n");
  85.                                 printf("\n");
  86.                                 numberOfWins = numberOfWins +1;
  87.                                 break;
  88.                                 }
  89.                                 if( whatButton == 3 && x_button){
  90.                                 printf("Correct! Here's another one!\n");
  91.                                 printf("\n");
  92.                                 numberOfWins = numberOfWins +1;
  93.                                 break;
  94.                                 }
  95.                                    
  96.                                 printf("Wrong button! You lose!\n");
  97.                                 printf("You made it through %d rounds!", numberOfWins);
  98.                                 lost = 1;
  99.                                 break;
  100.                             }
  101.                         }
  102.                
  103.                         currentTarget -= 100;
  104.                     }
  105.            
  106.            
  107.                        
  108.                 if( startTime <= 1000 ){
  109.                 printf("You ran out of time!\n");
  110.                 printf("You made it through %d rounds!", numberOfWins);
  111.                 lost = 1;
  112.                 break;
  113.                 }
  114.             }
  115.         }
  116.     }
  117.     return 0;
  118. }
  119.  
  120. /* Put your functions here, and be sure to put prototypes above. */
  121. int randomButton(int totalTime, int button){
  122.     if(button == 0){
  123.         printf("Press the triangle button!\nYou have %d miliseconds to respond!\n",totalTime);
  124.         printf("\n");
  125.     }
  126.     if(button == 1){
  127.         printf("Press the circle button!\nYou have %d miliseconds to respond!\n",totalTime);
  128.         printf("\n");
  129.     }
  130.     if(button == 2){
  131.         printf("Press the square button!\nYou have %d miliseconds to respond!\n",totalTime);
  132.         printf("\n");
  133.     }
  134.     if(button == 3){
  135.         printf("Press the cross button!\nYou have %d miliseconds to respond!\n",totalTime);
  136.         printf("\n");
  137.     }
  138.    
  139.     return button;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement