Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
//

#import "Easy level.h"



@implementation Easy_level

@synthesize QuestionNumber , correctAnswers, wrongAnswers, points, time , timerInt;

-(void)updatelabels
{
    CorrectAnswersCounter.text = [[NSString alloc] initWithFormat:@"%d", correctAnswers];
    WrongAnswersCounter.text = [[NSString alloc] initWithFormat:@"%d", wrongAnswers];
    YourPoints.text = [[NSString alloc ] initWithFormat:@"%d", points];
    YourTime.text = [[NSString alloc] initWithFormat:@"Your time.... %d",timerInt];

}
-(void)refresh
{
    Answer1.hidden = NO;
    Answer2.hidden= NO;
    Answer3.hidden = NO;
    Answer4.hidden = NO;

    CorrectWrong.text =@"correct/wrong";
}

-(void)endOfGame
    {
        if (Question1.hidden == YES) {
            if (Question2.hidden == YES) {
                if (Question3.hidden == YES) {
                    if (Question4.hidden == YES) {
                        if (Question5.hidden == YES) {
                            if (Question6.hidden == YES) {
                                if (Question7.hidden == YES) {
                                    if (Question8.hidden == YES) {
                                        if (Question9.hidden == YES) {
                                            if (Question10.hidden == YES) {
                                                NSString *endMessage = [[NSString alloc] initWithFormat:@"Points: %d/100    |   %d correct answers  %d  wrong answers", points,CorrectAnswers,wrongAnswers];

                                                UIAlertView *end = [[UIAlertView alloc] initWithTitle:@"End Of Game" message:endMessage delegate:self cancelButtonTitle:nil otherButtonTitles:@"Restart Quiz", nil];
                                                [end show];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

    }

-(IBAction)LevelSelected:(id)sender
{
    Question1.enabled = NO;
    Question2.enabled = NO;
    Question3.enabled = NO;
    Question4.enabled = NO;
    Question5.enabled = NO;
    Question6.enabled = NO;
    Question7.enabled = NO;
    Question8.enabled = NO;
    Question9.enabled = NO;
    Question10.enabled = NO;

    if (timerInt > 0) {
        [time invalidate];
        [self setTimerInt:0];
        time = [NSTimer scheduledTimerWithTimeInterval:(0.75/1.0)
                                                target:self
                                              selector: @selector(alertVoid)
                                              userInfo:nil
                                               repeats:YES];

    }
    else{
        time = [NSTimer scheduledTimerWithTimeInterval:(0.75/1.0)
                                                target:self
                                              selector:@selector(alertVoid)
                                              userInfo:nil
                                               repeats:YES];
    }
    if ([sender tag] == 1)
    {
        Question.text = @"The sequence 2,7,12,17.... is ";
        labelAnswer1.text = @"Odd"  ;
        labelAnswer2.text = @"Even";
        labelAnswer3.text = @"Arithmetic";
        labelAnswer4.text = @"Geometric";

        [self setQuestionNumber:1];
    }
    if ([sender tag] == 2)
    {
        Question.text = @"The nth term of the sequence 2,7,12,17... is";
        labelAnswer1.text = @"Apple";
        labelAnswer2.text = @"Nothing";
        labelAnswer3.text = @"Orange";
        labelAnswer4.text = @"Banana";

        [self setQuestionNumber:2];
    }
    if ([sender tag] == 3)
    {
        Question.text = @"what is the best";
        labelAnswer1.text = @"Apple";
        labelAnswer2.text = @"Nothing";
        labelAnswer3.text = @"Orange";
        labelAnswer4.text = @"Banana";

        [self setQuestionNumber:3];
    }
    if ([sender tag] == 4)
    {
        Question.text = @"If two variables are highly correlated, which one of the following statements is true? ";
        labelAnswer1.text = @"The two variables always go together.";
        labelAnswer2.text = @"High values on one variable lead to high values on the other variable.";
        labelAnswer3.text = @"There are no other variables responsible for the relationship.";
        labelAnswer4.text = @"There are no other variables responsible for the relationship.";

        [self setQuestionNumber:4];
    }
    if ([sender tag] == 5)
    {
        Question.text = @"what is the best";
        labelAnswer1.text = @"Apple";
        labelAnswer2.text = @"Nothing";
        labelAnswer3.text = @"Orange";
        labelAnswer4.text = @"Banana";

        [self setQuestionNumber:5];
    }
    if ([sender tag] == 6)
    {
        Question.text = @"Given the regression line (ln Y) = 4.08X - 10.4, estimate the value of Y when X = 5.";

        labelAnswer1.text = @"-2.1545";
        labelAnswer2.text = @"-1.3235";
        labelAnswer3.text = @"10";
        labelAnswer4.text = @"22 026";

        [self setQuestionNumber:6];
    }
    if ([sender tag] == 7)
    {
        Question.text = @"what is the best";
        labelAnswer1.text = @"Apple";
        labelAnswer2.text = @"Nothing";
        labelAnswer3.text = @"Orange";
        labelAnswer4.text = @"Banana";

        [self setQuestionNumber:7];
    }
    if ([sender tag] == 8)
    {
        Question.text = @"what is the best";
        labelAnswer1.text = @"Apple";
        labelAnswer2.text = @"Nothing";
        labelAnswer3.text = @"Orange";
        labelAnswer4.text = @"Banana";

        [self setQuestionNumber:8];
    }
    if ([sender tag] == 9)
    {
        Question.text = @"what is the best";
        labelAnswer1.text = @"Apple";
        labelAnswer2.text = @"Nothing";
        labelAnswer3.text = @"Orange";
        labelAnswer4.text = @"Banana";

        [self setQuestionNumber:9];
    }
    if ([sender tag] == 10)
    {
        Question.text = @"what is the best";
        labelAnswer1.text = @"Apple";
        labelAnswer2.text = @"Nothing";
        labelAnswer3.text = @"Orange";
        labelAnswer4.text = @"Banana";

        [self setQuestionNumber:10];
    }

    [self performSelector:@selector(buttonEnable) withObject:nil afterDelay:1.1f];

    NSString *level = [sender titleForState:UIControlStateNormal];
    YourLevel.text = level;
    [self updatelabels];
    [self refresh];
}

-(void) buttonEnable
{
    Question1.enabled = YES;
    Question2.enabled = YES;
    Question3.enabled = YES;
    Question4.enabled = YES;
    Question5.enabled = YES;
    Question6.enabled = YES;
    Question7.enabled = YES;
    Question8.enabled = YES;
    Question9.enabled = YES;
    Question10.enabled = YES;


}

-(void)alertVoid
{
    timerInt += 1;
    YourTime.text = [[NSString alloc] initWithFormat:@"Your time..... %d",timerInt];
}

-(void)CorrectAnswer
{
    [self setCorrectAnswers:[self correctAnswers] + 1];
    CalculatedScore = 100/(timerInt +1 );
    CorrectWrong.text = [[NSString alloc] initWithFormat:@"Correct! Points.%d",CalculatedScore];
    [self setPoints:[self points] + CalculatedScore];

    if (QuestionNumber == 1)
    {
        Question1.hidden = YES;
    }
    if (QuestionNumber == 2)
    {

        Question2.hidden = YES;
    }

    if (QuestionNumber == 3)
    {
        Question3.hidden = YES;
    }
    if (QuestionNumber == 4)
    {
        Question4.hidden = YES;
    }

    if (QuestionNumber == 5)
    {
        Question5.hidden = YES;
    }

    if (QuestionNumber == 6)
    {
        Question6.hidden = YES;
    }
    if (QuestionNumber == 7)
    {
        Question7.hidden = YES;
    }
    if (QuestionNumber == 8)
    {
        Question8.hidden = YES;
    }
    if (QuestionNumber == 9)
    {
        Question9.hidden = YES;
    }
    if (QuestionNumber == 10)
    {
        Question10.hidden = YES;
    }
    Answer1.hidden = YES;
    Answer2.hidden = YES;
    Answer3.hidden = YES;
    Answer4.hidden = YES;

    [time invalidate];
    [self updatelabels];
    [self endOfGame];
}


-(void)WrongAnswer
{
    [self setWrongAnswers:[self wrongAnswers] +1 ];
    [self setPoints:[self points] - 10];
    CorrectWrong.text = @"Wrong... -10 Points";
}

-(IBAction)Answer:(id)sender
{
    if ([sender tag ] == 1)
    {
        //answer1
        //question1
        if (QuestionNumber == 1)
        {
            [ self WrongAnswer];
        }
        //qustion2
        if (QuestionNumber == 2)
        {
            [ self WrongAnswer];
        }
         //qustion3
        if (QuestionNumber == 3)
        {
            [ self CorrectAnswer];
        }
         //qustion4
        if (QuestionNumber == 4)
        {
            [ self WrongAnswer];
        }
         //qustion5
        if (QuestionNumber == 5)
        {
            [ self WrongAnswer];
        }
     //qustion6
        if (QuestionNumber == 6)
        {
            [ self WrongAnswer];
        }
     //qustion7
        if (QuestionNumber == 7)
        {
            [ self WrongAnswer];
        }
     //qustion8
        if (QuestionNumber == 8)
        {
            [ self WrongAnswer];
        }
     //qustion9
        if (QuestionNumber == 9)
        {
            [ self WrongAnswer];
        }
     //qustion10
        if (QuestionNumber == 10)
        {
            [ self WrongAnswer];
        }
    }

    if ([sender tag ] == 2)
    {
        //answer2
        //question1
        if (QuestionNumber == 1)
        {
            [ self WrongAnswer];
        }
        //qustion2
        if (QuestionNumber == 2)
        {
            [ self WrongAnswer];
        }
        //qustion3
        if (QuestionNumber == 3)
        {
            [ self WrongAnswer];
        }
        //qustion4
        if (QuestionNumber == 4)
        {
            [ self WrongAnswer];
        }
        //qustion5
        if (QuestionNumber == 5)
        {
            [ self WrongAnswer];
        }
        //qustion6
        if (QuestionNumber == 6)
        {
            [ self CorrectAnswer];
        }
        //qustion7
        if (QuestionNumber == 7)
        {
            [ self WrongAnswer];
        }
        //qustion8
        if (QuestionNumber == 8)
        {
            [ self WrongAnswer];
        }
        //qustion9
        if (QuestionNumber == 9)
        {
            [ self WrongAnswer];
        }
        //qustion10
        if (QuestionNumber == 10)
        {
            [ self WrongAnswer];
        }
    }

    if ([sender tag ] == 3)
    {
        //answer3
        //question1
        if (QuestionNumber == 1)
        {
            [ self CorrectAnswer];
        }
        //qustion2
        if (QuestionNumber == 2)
        {
            [ self CorrectAnswer];
        }
        //qustion3
        if (QuestionNumber == 3)
        {
            [ self WrongAnswer];
        }
        //qustion4
        if (QuestionNumber == 4)
        {
            [ self WrongAnswer];
        }
        //qustion5
        if (QuestionNumber == 5)
        {
            [ self CorrectAnswer];
        }
        //qustion6
            if (QuestionNumber == 6)
        {
            [ self WrongAnswer];
        }
        //qustion7
        if (QuestionNumber == 7)
        {
            [ self CorrectAnswer];
        }
        //qustion8
        if (QuestionNumber == 8)
        {
            [ self CorrectAnswer];
        }
        //qustion9
        if (QuestionNumber == 9)
        {
            [ self CorrectAnswer];
        }
        //qustion10
        if (QuestionNumber == 10)
        {
            [ self CorrectAnswer];
        }

    }


    if ([sender tag ] == 4)
    {
        //answer3
        //question1
        if (QuestionNumber == 1)
        {
            [ self WrongAnswer];
        }
        //qustion2
        if (QuestionNumber == 2)
        {
            [ self WrongAnswer];
        }
        //qustion3
        if (QuestionNumber == 3)
        {
            [ self WrongAnswer];
        }
        //qustion4
        if (QuestionNumber == 4)
        {
            [ self CorrectAnswer];
        }
        //qustion5
        if (QuestionNumber == 5)
        {
            [ self WrongAnswer];
        }
        //qustion6
        if (QuestionNumber == 6)
        {
            [ self WrongAnswer];
        }
        //qustion7
        if (QuestionNumber == 7)
        {
            [ self WrongAnswer];
        }
        //qustion8
        if (QuestionNumber == 8)
        {
            [ self WrongAnswer];
        }
        //qustion9
        if (QuestionNumber == 9)
        {
            [ self WrongAnswer];
        }
        //qustion10
        if (QuestionNumber == 10)
        {
        [ self WrongAnswer];
        }
    }
    NSString *answerChosen = [sender titleForState:UIControlStateNormal];
    NSLog(@" Answer Chosen = %@" , answerChosen);
    [self updatelabels];



}

-(IBAction)Restart
{
    UIAlertView *restartAlert = [[UIAlertView alloc] initWithTitle:@"are you sure?"
                                                           message:nil
                                                          delegate:self
                                                 cancelButtonTitle:@"Cancel"
                                                 otherButtonTitles:@"yes ,restart", nil ];
    [restartAlert show];
    [self updatelabels];

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1 || buttonIndex == 0)
    {
        [time invalidate];
        [self setTimerInt:0];
        [self refresh];
        [self setPoints:0];
        [self setCorrectAnswers:0];
        [self setWrongAnswers:0];
        [self setQuestionNumber:0];

        Question1.hidden = NO;
        Question2.hidden = NO;
        Question3.hidden = NO;
        Question4.hidden = NO;
        Question5.hidden = NO;
        Question6.hidden = NO;
        Question7.hidden = NO;
        Question8.hidden = NO;
        Question9.hidden = NO;
        Question10.hidden = NO;

        Question.text = @"choose A level";
        labelAnswer1.text = @"";
        labelAnswer2.text = @"";
        labelAnswer3.text = @"";
        labelAnswer4.text = @"";
        [self updatelabels];

    }
}
Posted
Comments
Richard MacCutchan 30-Dec-14 5:57am    
This is far too much code for anyone to go through in order to try and figure out what your problem is. Please show only the relevant parts of the code, and explain clearly what you are trying to achieve.

1 solution

Drag and drop of controls can be done with gesture recognizers. Here is sample from Ray Wenderlich. The principles and some code should be reuseable for your needs.

Tip: rethink and simplify your code, I would call it "Spaghetti-code" ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900