Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------------------------------------------------------
- - SE 185: Lab 06 - Bop-It! -
- - Name: -
- - Section: -
- - NetID: -
- - Date: -
- -----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------
- - Includes -
- -----------------------------------------------------------------------------*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- /*----------------------------------------------------------------------------
- - Prototypes -
- -----------------------------------------------------------------------------*/
- int randomButton(int totalTime, int button);
- /*----------------------------------------------------------------------------
- - Notes -
- -----------------------------------------------------------------------------*/
- // Compile with gcc lab06.c -o lab06
- // Run with ./ds4rd.exe -d 054c:05c4 -D DS4_BT -t -b | ./lab06
- /*----------------------------------------------------------------------------
- - Implementation -
- -----------------------------------------------------------------------------*/
- int main(int argc, char *argv[])
- {
- int t;
- int triangle = 0;
- int circle = 0;
- int square = 0;
- int x_button = 0;
- int startTime = 2500;
- int currentTime = 0;
- int lost = 0;
- int totalTime;
- int numberOfWins = 0;
- int trianglePressed;
- int squarePressed;
- int circlePressed;
- int x_buttonPressed;
- srand(time(NULL)); /* This will ensure a random game each time. */
- printf("This is a Bop-It Game!\nPress the Circle Button to start the game!\n");
- while(1){
- scanf("%d, %d, %d, %d, %d", ¤tTime, &triangle, &circle, &x_button, &square);
- if( circle ){ break; }
- }
- while( !lost ){
- int button = rand() % 4;
- scanf("%d, %d, %d, %d, %d", ¤tTime, &triangle, &circle, &x_button, &square);
- int beginTime = currentTime;
- int currentTarget = 2500;
- while( 1 ) {
- if( startTime >= 1000 ){
- scanf("%d, %d, %d, %d, %d", ¤tTime, &triangle, &circle, &x_button, &square);
- startTime = 2500 - ( currentTime - beginTime );
- if(startTime <= currentTarget ){
- int whatButton = randomButton(currentTarget, button);
- if( currentTarget < 2400 ){
- if( triangle || circle || x_button|| square ){
- if( whatButton == 0 && triangle){
- printf("Correct! Here's another one!\n");
- printf("\n");
- numberOfWins = numberOfWins +1;
- break;
- }
- if( whatButton == 1 && circle){
- printf("Correct! Here's another one!\n");
- printf("\n");
- numberOfWins = numberOfWins +1;
- break;
- }
- if( whatButton == 2 && square){
- printf("Correct! Here's another one!\n");
- printf("\n");
- numberOfWins = numberOfWins +1;
- break;
- }
- if( whatButton == 3 && x_button){
- printf("Correct! Here's another one!\n");
- printf("\n");
- numberOfWins = numberOfWins +1;
- break;
- }
- printf("Wrong button! You lose!\n");
- printf("You made it through %d rounds!", numberOfWins);
- lost = 1;
- break;
- }
- }
- currentTarget -= 100;
- }
- if( startTime <= 1000 ){
- printf("You ran out of time!\n");
- printf("You made it through %d rounds!", numberOfWins);
- lost = 1;
- break;
- }
- }
- }
- }
- return 0;
- }
- /* Put your functions here, and be sure to put prototypes above. */
- int randomButton(int totalTime, int button){
- if(button == 0){
- printf("Press the triangle button!\nYou have %d miliseconds to respond!\n",totalTime);
- printf("\n");
- }
- if(button == 1){
- printf("Press the circle button!\nYou have %d miliseconds to respond!\n",totalTime);
- printf("\n");
- }
- if(button == 2){
- printf("Press the square button!\nYou have %d miliseconds to respond!\n",totalTime);
- printf("\n");
- }
- if(button == 3){
- printf("Press the cross button!\nYou have %d miliseconds to respond!\n",totalTime);
- printf("\n");
- }
- return button;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement