Hello there! I'm a beginner in iOS developing , and I am trying to build a small app where there's a comparison of two ProgressViews' progress.
Button1 is meant to decrease progress2.progress while Button2 increases it.
start is a button which is touchable only on the beginning of the game and its purpose is to hide the information and launch the first level.
The point of the game is to maintain progress2.progress close to progress1.progress during a small interval of time. Obviously , a user should tap the buttons rapidly to reach the game's objective.
On each turn a random value for progress1.progress is given therefore if the user can maintain progress2.progress close to progress1.progress , the "game" continues and a new random value will be given to progress1.progress.
The problem: Supposing a user was able to pass the first turn or level , and without forgetting that this first level went smoothly , when this user reaches the second level , progress1.progress starts taking random values quickly without stopping. And , if the user taps button1 or button2 the game directly ends.
What is causing this issue? I tried creating different timers and many changes in newGame , but still no solution... I even tried to inactivate timers before they repeat but again , nothing helps.
Here is my piece of code:
Button1 is meant to decrease progress2.progress while Button2 increases it.
start is a button which is touchable only on the beginning of the game and its purpose is to hide the information and launch the first level.
The point of the game is to maintain progress2.progress close to progress1.progress during a small interval of time. Obviously , a user should tap the buttons rapidly to reach the game's objective.
On each turn a random value for progress1.progress is given therefore if the user can maintain progress2.progress close to progress1.progress , the "game" continues and a new random value will be given to progress1.progress.
The problem: Supposing a user was able to pass the first turn or level , and without forgetting that this first level went smoothly , when this user reaches the second level , progress1.progress starts taking random values quickly without stopping. And , if the user taps button1 or button2 the game directly ends.
What is causing this issue? I tried creating different timers and many changes in newGame , but still no solution... I even tried to inactivate timers before they repeat but again , nothing helps.
Here is my piece of code:
Code:
- (void)viewDidLoad
{
progress1.progress=arc4random() % 11 * 0.1;
label1.hidden = NO;
gameOver.hidden = YES;
[super viewDidLoad];
}
-(void)regulator{
timer4 =[NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(conditioner) userInfo:nil repeats:YES];
;}
-(void)conditioner {
if (fabs(progress2.progress-progress1.progress)<=0.3
)
{
[self newGame];
} else{
gameOver.hidden=NO;
}
}
-(void)newGame{
progress1.progress=arc4random() % 11 * 0.1;}
- (IBAction)start:(UIButton *)sender {
progress2.progress=arc4random() % 11 * 0.1;
timer1 = [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(regulator) userInfo:nil repeats:YES];
[self regulator];
label1.hidden=YES;
UIButton *button1 = (UIButton *)sender;
button1.enabled = NO;
UIButton *button2 = (UIButton *)sender;
button2.enabled = NO;
}
- (IBAction)button1:(UIButton *)sender {
progress2.progress=progress2.progress-0.04;
[self regulator];
}
- (IBAction)button2:(UIButton *)sender
{
progress2.progress=progress2.progress+0.04;
[self regulator];
}