Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- /*Rules: Roll 6 dices with 6 sides for each number on the dice that
- matches the current number you get 1 point */
- int main (int argc, const char * argv[]) { //Main method
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // used for Cocoa memory management system
- /*Variable declaration and init*/
- int random = 0;
- bool gameOver = FALSE;
- int currentNum = 1;
- char checkForEnter;
- int gamePoints = 0;
- NSMutableArray *dice = [[NSMutableArray alloc] init];
- NSNumber *num = [[NSNumber alloc] init];
- NSString *str = [[NSString alloc] init];
- /*end*/
- while (!gameOver) { //Game loop
- NSLog(@"Collect the number: %i", currentNum);
- NSLog(@"\n");
- for(int i = 0; i < 7; i++)
- {
- random = arc4random()%6 + 1;
- num = [NSNumber numberWithInteger:random ];
- [dice addObject: num ];
- }
- for(int i = 1; i < 7; i++){
- NSLog(@"Dice rolled!: %d", [[dice objectAtIndex:i]intValue]);
- if ([[dice objectAtIndex:i]intValue] == currentNum) {
- ++gamePoints;
- }
- NSLog(@"Press ENTER to roll next dice!");
- scanf("%c",&checkForEnter);
- }
- [dice release];
- dice = [[NSMutableArray alloc] init];
- currentNum++;
- if(currentNum == 7){
- gameOver = TRUE;
- }
- }
- NSLog(@"Your points are: %i", gamePoints);
- NSLog(@"Ending game...");
- //Dealloc
- [num release];
- [str release];
- [dice release];
- [pool drain];
- //end
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement