如何从每个按钮动作中减去一次硬币?

时间:2014-03-25 02:40:33

标签: ios iphone objective-c ibaction

我放置了三个按钮,第一个按钮允许动画显示其他按钮,但用户每次操作只能花费10个点。

当他们按下#2按钮时,他们必须只丢失10个硬币(-10个硬币)同样用于行动#3。

-(IBAction)btnHint:(id)sender {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];


CGPoint center = [hints center];
center.x = 160;
center.y = 230;
[hints setCenter:center];

[UIView commitAnimations];
hintView.text = @"founded in 1996, and is a sub of telecome";

if(minusPoint) { coins = coins -10;
    //Minus a point
    minusPoint = NO;
    }
}

- (IBAction)firstHintq:(id)sender {
hintView.text = @"founded in 1996, and is a sub of telecome";

}

- (IBAction)secondHintq:(id)sender {

[_candletwo setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];
hintView.text = @"Type in text here 2";


}

- (IBAction)thirdHintq:(id)sender {
hintView.text = @"Type in the third hint here";
[_candlethree setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];

}

而且,如何在硬币标签上立即显示-10点?

1 个答案:

答案 0 :(得分:0)

使conins类型为int的全局。让硬币标签为coinLabel。制作3个bool全局变量,例如btn1Pressed,btn2Pressed,btn3Pressed。在viewDidLoad制作btn1Pressed = btn2Pressed = btn3Pressed =false;。然后做这样的事情:

-(IBAction)btnHint:(id)sender {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];


CGPoint center = [hints center];
center.x = 160;
center.y = 230;
[hints setCenter:center];

[UIView commitAnimations];
hintView.text = @"founded in 1996, and is a sub of telecome";
}

- (IBAction)firstHintq:(id)sender {
hintView.text = @"founded in 1996, and is a sub of telecome";
if(!btn1Pressed) { 
    if((coins -10) >= 0){
        coins = coins -10;
        btn1Pressed = true
        coinLabel.text = [NSString stringWithFormat:@"%d",coins];
    }
    else{
        //Show an alert that the user has not enough coins
    }
}
}

- (IBAction)secondHintq:(id)sender {

[_candletwo setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];
hintView.text = @"Type in text here 2";
if(!btn2Pressed) { 
    if((coins -10) >= 0){
        coins = coins -10;
        btn2Pressed = true
        coinLabel.text = [NSString stringWithFormat:@"%d",coins];
    }
    else{
        //Show an alert that the user has not enough coins
    }
}    
}

- (IBAction)thirdHintq:(id)sender {
hintView.text = @"Type in the third hint here";
[_candlethree setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];
if(!btn3Pressed) { 
    if((coins -10) >= 0){
        coins = coins -10;
        btn3Pressed = true
        coinLabel.text = [NSString stringWithFormat:@"%d",coins];
    }
    else{
        //Show an alert that the user has not enough coins
    }
}
}

希望这会有所帮助.. :)