Skip to content

Instantly share code, notes, and snippets.

@steveatinfincia
Created May 22, 2012 03:48
Show Gist options
  • Save steveatinfincia/2766443 to your computer and use it in GitHub Desktop.
Save steveatinfincia/2766443 to your computer and use it in GitHub Desktop.
Prototype slot machine logic for iOS
-(IBAction)spin:(id)sender {
int max = 4;
int min = 0;
int c1 = rand() % max + min;
int c2 = rand() % max + min;
int c3 = rand() % max + min;
[carousel1 scrollByNumberOfItems:250+c1 duration:3.5f];
[carousel2 scrollByNumberOfItems:250+c2 duration:4.0f];
[carousel3 scrollByNumberOfItems:250+c3 duration:4.5f];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sleep(5);
dispatch_async(dispatch_get_main_queue(), ^{
int r1 = carousel1.currentItemIndex;
int r2 = carousel2.currentItemIndex;
int r3 = carousel3.currentItemIndex;
UIAlertView *alert = [[UIAlertView alloc] init];
if (r1 == r2 && r2 == r3) {
// full match
alert.message = @"Full match";
}
else if (r1 == r2 || r1 == r3 || r2 == r3) {
// got 2 matches
alert.message = @"Partial match";
}
else {
// no match anywhere
alert.message = @"No match";
}
[alert addButtonWithTitle:@"OK"];
alert.cancelButtonIndex = 0;
[alert show];
[alert release];
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment