UIAlertView如果不够点(cocos2d iPhone)
如果用户没有足够的积分来购买升级,我希望弹出 UIAlertView。到目前为止,我有这个代码可以花费积分来获得升级。如果升级需要 300 点,而用户只有 150 点,我希望 UIAlertView 计算所需的金额,并说“抱歉,您还需要 150 点来购买此升级”。这是我的代码。 (“mag”和“score”都是整数。)
-(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:kScoreDefaultsKey];
}
-(void)plusFiveMag:(id)sender {
self.mag = self.mag + 5;
self.score = self.score - 300;
}
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:kScoreDefaultsKey];
}
-(void)plusFiveMag:(id)sender {
self.mag = self.mag + 5;
self.score = self.score - 300;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情......
Try somethin like this...