Advertisement
Shavit

Casino Project

Dec 6th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.02 KB | None | 0 0
  1. /* *******************************************************
  2.    * #######   #######   #######   #   ##    #   ####### *
  3.    * #         #     #   #         #   ###   #   #     # *
  4.    * #         #######   #######   #   # ##  #   #     # *
  5.    * #         #     #         #   #   #  ## #   #     # *
  6.    * #######   #     #   #######   #   #   ###   ####### *
  7.    *******************************************************
  8. */
  9.  
  10. #include <stdio.h> // Included for printf, scanf
  11. #include <stdlib.h> // Included for system, srand, rand
  12. #include <time.h> // Included for time
  13.  
  14. #define SUCCESS 0 // Defined for return
  15.  
  16. int main()
  17. {
  18.     // Constants definition:
  19.     const short SLOTS_CHOICE = 1;
  20.     const short ROULLETE_CHOICE = 2;
  21.     const short MINIMUM_BID = 20;
  22.     const short MINUMUM_ROULLETE_NUM = 1;
  23.     const short MAXIMUM_ROULLETE_NUM = 36;
  24.    
  25.     // Variables definition:
  26.     short gameChoice;
  27.     int balance = 100;
  28.     int gambleValue;
  29.    
  30.     srand(time(NULL));
  31.    
  32.     printf("Welcome to THE CASINO!\n");
  33.     printf("Your current balance is %d$.\n", balance); // Presents balance
  34.    
  35.     printf("Which game would you like to play this time? <Choose 1 for Slots or 2 for Roulette> ");
  36.     scanf("%d", &gameChoice); // Receives game choice
  37.    
  38.     if(SLOTS_CHOICE != gameChoice && ROULLETE_CHOICE != gameChoice) // Checks if game choice is valid
  39.     {
  40.         printf("Your choice is invalid!\n");
  41.     }
  42.     else
  43.     {
  44.         printf("How much money would you like to gamble on? <The minimum is 20$, and your current balance is %d$> ", balance);
  45.         scanf("%d", &gambleValue); // Receives gamble value
  46.        
  47.         if((gambleValue > balance) || (gambleValue < MINIMUM_BID)) // Checks if gamble value is valid
  48.         {
  49.             printf("Your gamble is invalid!\n");
  50.         }  
  51.         else
  52.         {  
  53.             if(SLOTS_CHOICE == gameChoice) // Enters Slots game
  54.             {
  55.                 balance = balance - gambleValue; // Subtracts gamble value from current balance
  56.                
  57.                 printf("Welcome to SLOTS!\n");
  58.                
  59.                 int firstSign = (rand() % 3) + 35; // Random number between 35 and 37 (ASCII values of #, & and %)
  60.                 int secondSign = (rand() % 3) + 35; // Random number between 35 and 37 (ASCII values of #, & and %)
  61.                 int thirdSign = (rand() % 3) + 35; // Random number between 35 and 37 (ASCII values of #, & and %)
  62.                
  63.                 printf("The machine has generated these symbols:\n");
  64.                 printf("%10c%10c%10c\n", firstSign, secondSign, thirdSign);
  65.                
  66.                 if((firstSign == secondSign) && (secondSign == thirdSign)) // Checks if the player has won
  67.                 {
  68.                     printf("Congratulations! You have won!\n");
  69.                     balance = balance + (gambleValue * 8); // Adds the amount of money earned to the balance
  70.                 }
  71.                 else
  72.                 {
  73.                     printf("Sorry! You have lost!\n");
  74.                 }
  75.             }
  76.             else if(ROULLETE_CHOICE == gameChoice) // Enters Roulette game
  77.             {
  78.                 printf("Welcome to ROULETTE!\n");
  79.                
  80.                 int biddingNum;
  81.                
  82.                 printf("Please enter your bidding number: ");
  83.                 scanf("%d", &biddingNum); // Receives bidding value
  84.                
  85.                 if(MINUMUM_ROULLETE_NUM > biddingNum || MAXIMUM_ROULLETE_NUM < biddingNum) // Checks if the bidding number is valid
  86.                 {
  87.                     printf("The number you have chosen is invalid!\n");
  88.                 }
  89.                 else
  90.                 {
  91.                     balance = balance - gambleValue; // Subtracts gamble value from current balance
  92.                    
  93.                     int rouletteResult = (rand() % 36) + 1; // Random number between 1 and 36
  94.                    
  95.                     printf("The machine has chosen the number %d!\n", rouletteResult);
  96.                    
  97.                     if(rouletteResult == biddingNum) // Checks if the player has won
  98.                     {
  99.                         printf("Congratulations! You have won!\n");
  100.                         balance = balance + (gambleValue * 35); // Adds the amount of money earned to the balance
  101.                     }
  102.                     else
  103.                     {
  104.                         printf("Sorry! You have lost!\n");
  105.                     }
  106.                 }
  107.             }
  108.         }
  109.     }
  110.    
  111.     if(balance) // Checks if the player has money after game play
  112.     {
  113.         printf("Your final balance is %d$. Hope to see you next time!\n", balance); // Presents balance after game play
  114.     }
  115.     else
  116.     {
  117.         printf("Your final balance is %d$ - You lost all your money! What a shame...\n", balance); // Presents 0 balance
  118.     }
  119.    
  120.     system("PAUSE");
  121.    
  122.     return(SUCCESS);
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement