数学游戏测验有多个答案

时间:2013-08-15 21:18:03

标签: math nsstring uibutton uilabel

我有一个数学测验游戏,我希望用户能够触摸按钮,现在它只有在我将一个按钮设置为正确答案时才能工作。是否可以将其设为按钮组合,如果答案为53,则用户可以触摸5按钮和3按钮。

ViewController.m

- (IBAction)EasyLevel:(id)发件人{

Question.hidden = NO;
SelectLevel.hidden = YES;

buttonOne.hidden = YES;
buttonTwo.hidden = YES;
buttonThree.hidden = YES;
buttonFour.hidden = YES;
buttonFive.hidden = YES;
buttonSix.hidden = YES;
buttonSeven.hidden = YES;
buttonEight.hidden = YES;
buttonNine.hidden = YES;
buttonZero.hidden = YES;

Right1.hidden = YES;
Right2.hidden = YES;
Right3.hidden = YES;
Right4.hidden = YES;
Right5.hidden = YES;
Right6.hidden = YES;
Right7.hidden = YES;
Right8.hidden = YES;
Right9.hidden = YES;
Right0.hidden = YES;

Wrong1.hidden = YES;
Wrong2.hidden = YES;
Wrong3.hidden = YES;
Wrong4.hidden = YES;
Wrong5.hidden = YES;
Wrong6.hidden = YES;
Wrong7.hidden = YES;
Wrong8.hidden = YES;
Wrong9.hidden = YES;
Wrong0.hidden = YES;



int EasyQuestion = arc4random() % 2 ;
switch (EasyQuestion) {

    case 0:
        Question.text = [NSString stringWithFormat: @"What is 4 X 2"];
        Right1.hidden = NO;

        Wrong3.hidden = NO;
        Wrong4.hidden = NO;
        Wrong5.hidden = NO;
        Wrong6.hidden = NO;
        Wrong7.hidden = NO;
        Wrong8.hidden = NO;
        Wrong9.hidden = NO;
        Wrong0.hidden = NO;

        buttonOne.hidden =  NO;
        buttonTwo.hidden =  NO;
        buttonThree.hidden =  NO;
        buttonFour.hidden =  NO;
        buttonFive.hidden =  NO;
        buttonSix.hidden =  NO;
        buttonSeven.hidden =   NO;
        buttonEight.hidden =  NO;
        buttonNine.hidden =  NO;
        buttonZero.hidden =  NO;

        buttonOne.text = [NSString stringWithFormat: @"1"];
        buttonTwo.text = [NSString stringWithFormat: @"2"];
        buttonThree.text = [NSString stringWithFormat: @"3"];
        buttonFour.text = [NSString stringWithFormat: @"4"];
        buttonFive.text = [NSString stringWithFormat: @"5"];
        buttonSix.text = [NSString stringWithFormat: @"6"];
        buttonSeven.text = [NSString stringWithFormat: @"7"];
        buttonEight.text = [NSString stringWithFormat: @"8"];
        buttonNine.text = [NSString stringWithFormat: @"9"];
        buttonZero.text = [NSString stringWithFormat: @"0"];
        break;

        case 1: .....
        default:
        break; }

感谢任何帮助,谢谢:) Stephanie

1 个答案:

答案 0 :(得分:0)

诀窍是程序如何知道用户何时按下按钮输入数字?

一种方法可能是使答案成为可编辑的文本字段(UITextField)并将焦点设置为它并将键盘设置为数字类型键盘(通过UITextField实现的UITextInputTraits协议)以便用户可以键入数字值。

如果您不想使用iOS键盘并且只想要自己的自定义按钮,那么您可以使用自己的按钮并对每个按钮执行操作,将相应的数字附加到您可能显示的答案字符串中。一个UILabel并按下按钮时更新。你想要一个后退/删除按钮,这样他们就可以删除数字并在那里更新字符串。使用这个模型,你可能有一个“确定”按钮或“完成”按钮,表示它们已完成,当前字符串是他们的答案。该按钮将是在该点接收答案字符串中的字符串并检查其是否正确的按钮。

希望这足以让你前进!