我正在创建一个有4个答案的问答游戏,我想添加分数。每个正确答案都值50分,错误答案是-50分。我该怎么做?
- (IBAction)bpressed1:(id)sender {
if ([self.answer isEqualToString:@"a"]) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"yes!"
message:@"+50."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
[message release];
[self nextq];
}else{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"no!"
message:@"-50."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil]
[message show];
[message release];
[self nextq];
}
}
答案 0 :(得分:2)
你的头文件中可以有一个@property (nonatomic) int score;
和一个UILabel来显示分数。每当有人按下正确答案时,请执行self.score+=50;
并将标签的文本设置为新分数。