Question

I've place three buttons the first button allows the animation to reveal the other buttons, but the user should only spend 10 points on each action.

Meaning when they press button #2 they must only lose 10 coins (-10 coins) same goes for action #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];

}

And, how do I display the -10 points immediately on the coins label?

Was it helpful?

Solution

Make conins global of type int. Let coin label is coinLabel. Make 3 bool global variable such as btn1Pressed,btn2Pressed,btn3Pressed. In viewDidLoad make as btn1Pressed = btn2Pressed = btn3Pressed =false;. Then do something like this:

-(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
    }
}
}

Hope this helps .. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top