Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <Foundation/Foundation.h>
  2.  
  3. /*Rules: Roll 6 dices with 6 sides for each number on the dice that
  4.  matches the current number you get 1 point */
  5.  
  6. int main (int argc, const char * argv[]) { //Main method
  7.    
  8.    
  9.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // used for Cocoa memory management system
  10.    
  11.     /*Variable declaration and init*/
  12.     int             random = 0;
  13.     bool            gameOver = FALSE;
  14.     int             currentNum = 1;
  15.     char            checkForEnter;
  16.     int             gamePoints = 0;
  17.    
  18.     NSMutableArray  *dice = [[NSMutableArray alloc] init];
  19.     NSNumber        *num =  [[NSNumber alloc] init];
  20.     NSString        *str =  [[NSString alloc] init];
  21.    
  22.     /*end*/
  23.  
  24.    
  25.     while (!gameOver) { //Game loop
  26.    
  27.         NSLog(@"Collect the number: %i", currentNum);
  28.         NSLog(@"\n");
  29.         for(int i = 0; i < 7; i++)
  30.         {
  31.             random = arc4random()%6 + 1;
  32.             num = [NSNumber numberWithInteger:random ];
  33.             [dice addObject: num ];
  34.         }
  35.        
  36.         for(int i = 1; i < 7; i++){
  37.        
  38.             NSLog(@"Dice rolled!: %d", [[dice objectAtIndex:i]intValue]);
  39.             if ([[dice objectAtIndex:i]intValue] == currentNum) {
  40.                 ++gamePoints;
  41.             }
  42.             NSLog(@"Press ENTER to roll next dice!");
  43.            
  44.             scanf("%c",&checkForEnter);
  45.            
  46.         }
  47.        
  48.         [dice release];
  49.         dice = [[NSMutableArray alloc] init];
  50.        
  51.         currentNum++;
  52.         if(currentNum == 7){
  53.             gameOver = TRUE;
  54.         }
  55.        
  56.     }
  57.    
  58.     NSLog(@"Your points are: %i", gamePoints);
  59.     NSLog(@"Ending game...");
  60.    
  61.     //Dealloc
  62.     [num release];
  63.     [str release];
  64.     [dice release];
  65.         [pool drain];
  66.     //end
  67.    
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement