UIAlertView if not enough points (cocos2d iPhone)
I want a UIAlertView to popup if the user doesn't have enough points to purchase an upgrade. So far I have this code to spend points to get the upgrade. If the upgrade costs 300 points, and the user only has 150, I would like the UIAlertView to calculate the amount needed and say something like, "Sorry, you need 150 more points to buy this upgrade". Here's my code. ('mag' and 'score' are both ints.)
-(int)mag {
return [[NSUserDefaults standardUserDefaults] integerForKey:kMagDefaultsKey];
}
-(int)score {
return [[NSUserDefaults standardUserDefaults] integerForKey:kScoreDefaultsKey];
}
-(void)setMag:(int)value {
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:kMagDefaultsKey];
}
-(void)setScore:(int)value {
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:kSco开发者_运维技巧reDefaultsKey];
}
-(void)plusFiveMag:(id)sender {
self.mag = self.mag + 5;
self.score = self.score - 300;
}
Try somethin like this...
-(void)alertview
{
if(self.Mag>self.cost)
{
int difference;
difference=self.Mag-self.cost;
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"your message" message:differene delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[Alert show];
[Alert release];
}
}
精彩评论