我做了一个测验,并希望它改变答案,使其更具挑战性。这意味着什么时候应该有一种方法可以检查哪个按钮是答案。如果答案是按钮 1,则按钮 1 包含正确答案。如果答案是按钮 4,则按钮 4 包含正确答案等。
现在,每次我玩新游戏时,代码都会改变答案,但是它将所有 4 个按钮的标题设置为相同的标题,并且正确的答案始终是按钮 1。
有任何想法吗?
菲利普
这就是我所拥有的。
- (IBAction)PlayHistory_Easy:(id)sender {
// The questions
history_Easy = [[NSMutableArray alloc] initWithObjects:kHisQ_E1, kHisQ_E2, kHisQ_E3, kHisQ_E4,nil];
numberOfQuestions = [history_Easy count];
index = arc4random() % numberOfQuestions--;
NSString *dd = [history_Easy objectAtIndex:index];
questionLabel.text = dd;
// Setup code to shuffle answers
NSMutableArray *randomizeAnswer = [[NSMutableArray alloc] initWithObjects:btnOne, btnTwo, btnThree, btnFour, nil];
NSMutableArray *ranAns = [[NSMutableArray alloc] initWithObjects:@"Answer 1", @"Answer 2", @"Answer 3", @"Answer 4", nil];
if ([questionLabel.text isEqualToString:kHisQ_E1]) { // Answer 1st button
for (UIButton *btn in randomizeAnswer) {
int i = arc4random() % ranAns.count;
NSString *str = [ranAns objectAtIndex:i];
[btnOne setTitle:[ranAns objectAtIndex:i] forState:UIControlStateNormal];
[btnTwo setTitle:[ranAns objectAtIndex:i] forState:UIControlStateNormal];
[btnThree setTitle:[ranAns objectAtIndex:i] forState:UIControlStateNormal];
[btnFour setTitle:[ranAns objectAtIndex:i] forState:UIControlStateNormal];
}
}
检查答案。这里检查答案是手动完成的,但是为了打乱答案,代码明显不同。
- (IBAction)button1:(id)sender {
if ([questionLabel.text isEqualToString:kHisQ_E1]) {
[self playRIGHTAnswer_EASY];
}
}
- (IBAction)button2:(id)sender {
if ([questionLabel.text isEqualToString:kHisQ_E1]) {
[self playWRONGAnswer_EASY];
}
}
- (IBAction)button3:(id)sender {
if ([questionLabel.text isEqualToString:kHisQ_E1]) {
[self playWRONGAnswer_EASY];
}
}
- (IBAction)button4:(id)sender {
if ([questionLabel.text isEqualToString:kHisQ_E1]) {
[self playWRONGAnswer_EASY];
}
}