Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-10-2011, 03:49 AM   #126 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 5
rissvann is on a distinguished road
Default

Thanks a lot for such a nice working tutorial!
rissvann is offline   Reply With Quote
Old 12-25-2011, 02:53 PM   #127 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 79
Jaxen66 is on a distinguished road
Default Anyone?

Quote:
Originally Posted by Jaxen66 View Post
Hi, everyone!

I have now been searching around this forum site for a long time now. It looks like some of you in this thread have got the random function to work, Could you make a tutorial about how you did it, or upload the source code for the random function??
Anyone, ever find out on how to do the random stuff for this quiz?
__________________
Thanks for taking the time to help a newbie
Jaxen66 is offline   Reply With Quote
Old 12-27-2011, 08:03 AM   #128 (permalink)
Registered Member
 
marshusensei's Avatar
 
Join Date: Mar 2011
Location: Australia
Age: 28
Posts: 105
marshusensei is on a distinguished road
Default "Random Stuff"

Basically I followed the tutorial outlined in this discussion. Here is my code for the 'random' function:

Code:
-(void)askQuestion
{
	// Unhide all the answer buttons.
	[answer1 setHidden:NO];
	[answer2 setHidden:NO];
	[answer3 setHidden:NO];
	[answer4 setHidden:NO];
	[intro setHidden:NO];
	
	// Set the game to a "live" question (for timer purposes)
	questionLive = YES;
	
	// Set the time for the timer
	time = 90.0;
	
	// Go to the next question
	int i;
	int j;
	
    NSInteger row = 0;
    i = 100; //i > 1;
	{
        j = arc4random()%i;
        
        questionNumber = j + 1;
		
		if(questionNumber == 1)
		{
			row = questionNumber - 1;
			answerCount ++;
		}
		else
		{
			row = ((questionNumber - 1) * 6);
			answerCount ++;
		}}
	
	// Set the question string, and set the buttons the the answers
	NSString *selected = [theQuiz objectAtIndex:row];
	NSString *activeQuestion = [[NSString alloc] initWithFormat:@"%@", selected];
	[answer1 setTitle:[theQuiz objectAtIndex:row+1] forState:UIControlStateNormal];
	[answer2 setTitle:[theQuiz objectAtIndex:row+2] forState:UIControlStateNormal];
	[answer3 setTitle:[theQuiz objectAtIndex:row+3] forState:UIControlStateNormal];
	[answer4 setTitle:[theQuiz objectAtIndex:row+4] forState:UIControlStateNormal];
	rightAnswer = [[theQuiz objectAtIndex:row+5] intValue];
	
	// Set theQuestion label to the active question
	theQuestion.text = activeQuestion;
__________________
Please visit - MushroomPudding.com
marshusensei is offline   Reply With Quote
Old 12-29-2011, 09:00 AM   #129 (permalink)
Registered Member
 
marshusensei's Avatar
 
Join Date: Mar 2011
Location: Australia
Age: 28
Posts: 105
marshusensei is on a distinguished road
Default Jaxen

Quote:
Hey matthew!

The random thing is now working, but it ends at different points. Sometimes after 3 questions sometimes after 16.
Another problem is also that it sometimes pick the same question 2 times in the same game.

I think that the problem has something to do with this line.

NSInteger endOfQuiz = [theQuiz count];
if((((questionNumber - 1) * 6) + 6) == endOfQuiz)
{

i can't figure it out. I have been trying to make a counter so when there have been 10 questions it would end the quiz, but that did not seems to work.


I would like to make the quiz with let's say 50 questions and then it first takes the first 10, then new 10 and then new 10 and so on. Until all of the questions have been taking. After that it should mix all the 50 qustions and then pick 10, and again 10 and so on. Hope you can help me with this!
Of course this will pay of for you.

Best Regards

Jakob
Hi again, thought I'd reply to you via the forum rather than email, as you may get some more expert advice. Without seeing your code it's difficult to say where your problem is. I would suggest posting your code here (the .m file).

Have you made sure that there are at 100 questions in your .txt file?

Finally, to end the quiz after 15 questions you would need to put and if statement making use of some sort of count
Code:
//end quiz
	if (answerCount >= 15)
		
	{
		answerCount =0;
	 What ever you want it to do goes in here.
Maybe create separate arrays for sets of questions?

For info on how to produce non-repeating questions, please refer to DuncanC's post it is very helpful. Good luck with this, you'll figure it out!

Matt
__________________
Please visit - MushroomPudding.com
marshusensei is offline   Reply With Quote
Old 12-29-2011, 09:05 AM   #130 (permalink)
Registered Member
 
marshusensei's Avatar
 
Join Date: Mar 2011
Location: Australia
Age: 28
Posts: 105
marshusensei is on a distinguished road
Default Link to Duncan C's tutorial

Here is a link to Duncan's excellent tutorial on how to produce non-repeating random text...

http://www.iphonedevsdk.com/forum/ip...tml#post263506
__________________
Please visit - MushroomPudding.com
marshusensei is offline   Reply With Quote
Old 12-29-2011, 11:59 AM   #131 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 79
Jaxen66 is on a distinguished road
Default

Thanks for the help, again. First the code
NSInteger endOfQuiz = [theQuiz count]; <-- Here i get this warning: Unused variable 'endOfQuiz'
if (answerCount >= 30)

{
answerCount =0;

{


Otherwise it works great, if i put the >=30 it stops at 15, and if i put the <=4 it stops at 2. So i don't think it runs properly but i got it working. if you want it to stop after 10 questions make the >= 20.

Going to look at the link now

Here is my .m file

@implementation FodboldQuizSuperligaViewController

- (void)viewDidLoad {

questionLive = NO;
restartGame = NO;
theQuestion.text = @"Er du klar, til den ultimative Quiz?";
theScore.text = @"Score:0";
theLives.text = @"";
questionNumber = 0;
myScore = 0;
myLives = 0;
[answerOne setTitle:@"Lad os gå igang" forState:UIControlStateNormal];
[answerTwo setHidden:YES];
[answerThree setHidden:YES];
[answerFour setHidden:YES];
[appstore setHidden:NO];
[appstorelabel setHidden:NO];
[self loadQuiz];
[super viewDidLoad];
[showachievements setHidden:YES];
[ShowLeader setHidden:NO];
[submitScore setHidden:YES];
[sendsms setHidden:YES];
counter=0;
count.text = @"0/15";
answerCount=0;

self.currentLeaderBoard= kEasyLeaderboardID;
if ([GameCenterManager isGameCenterAvailable]) {

self.gameCenterManager= [[[GameCenterManager alloc] init] autorelease];
[self.gameCenterManager setDelegate: self];
[self.gameCenterManager authenticateLocalUser];


}
}

-(void)askQuestion
{
// Unhide all the answer buttons.
[answerOne setHidden:NO];
[answerTwo setHidden:NO];
[answerThree setHidden:NO];
[answerFour setHidden:NO];
[appstore setHidden:YES];
[appstorelabel setHidden:YES];
[sendsms setHidden:YES];
[ShowLeader setHidden:YES];
[animation setHidden:YES];
[animationsmiley setHidden:YES];
[count setHidden:NO];
counter=counter + 1;
count.text = [NSString stringWithFormat:@"%i/15",counter];
answerCount=answerCount + 1;

// Set the game to a "live" question (for timer purposes)
questionLive = YES;

// Set the time for the timer
time = 15.0;

// Go to the next question
questionNumber = questionNumber + 1;

// THIS IS REALLY TERRIBLE CODE!!!
// We get the question from the questionNumber * the row that we look up in the array.
// This is absolutely horrible, just a placeholder until the right way.
// I cannot even begin to describe how wrong this solution is.

// Set the question string, and set the buttons the the answers
int i;
int j;

NSInteger row = 0;
i = 20; //i > 1;
{
j = arc4random()%i;

questionNumber = j + 1;

if(questionNumber == 1)
{
row = questionNumber - 1;
answerCount ++;
}
else
{
row = ((questionNumber - 1) * 6);
answerCount ++;
}}

// Set the question string, and set the buttons the the answers
NSString *selected = [theQuiz objectAtIndex:row];
NSString *activeQuestion = [[NSString alloc] initWithFormat:@"%@", selected];
[answerOne setTitle:[theQuiz objectAtIndex:row+1] forState:UIControlStateNormal];
[answerTwo setTitle:[theQuiz objectAtIndex:row+2] forState:UIControlStateNormal];
[answerThree setTitle:[theQuiz objectAtIndex:row+3] forState:UIControlStateNormal];
[answerFour setTitle:[theQuiz objectAtIndex:row+4] forState:UIControlStateNormal];
rightAnswer = [[theQuiz objectAtIndex:row+5] intValue];


// Set theQuestion label to the active question
theQuestion.text = activeQuestion;

// Start the timer for the countdown
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];

[selected release];

}

-(void)updateScore
{
// If the score is being updated, the question is not live
questionLive = NO;

[timer invalidate];

// Hide the answers from the previous question
[ShowLeader setHidden:YES];
[sendsms setHidden:YES];
[appstore setHidden:YES];
[appstorelabel setHidden:YES];
[answerOne setHidden:YES];
[answerTwo setHidden:YES];
[answerThree setHidden:YES];
[answerFour setHidden:YES];
NSString *scoreUpdate = [[NSString alloc] initWithFormat:@"Score: %d", myScore];
theScore.text = scoreUpdate;
[scoreUpdate release];
[count setHidden: YES];

// END THE GAME.
NSInteger endOfQuiz = [theQuiz count];
if (answerCount >= 15)

{
answerCount =0;

{

// Game is over.
if(myScore < 400)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Du havde fået en fyring hvis du var træner\nDu fik %i point!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];

}
if(myScore == 450)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Ikke acceptabelt, det må du kunne gøre bedre\nDu fik kun %i point!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];

}
if(myScore == 500)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Færdig!Ok resultat, men langt fra det bedste\nDu fik kun %i point!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
if(myScore == 550)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Du burde nok se lidt mere superliga\nDu fik %i point!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];

}
if(myScore == 600)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Du er ved at være der, men mangler lidt endnu.\nDu fik %i point.", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];

}

if(myScore == 650)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Vis nu lige, at du er en rigtig fan!\nDu fik %i point.", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];

}
if(myScore > 700)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Du er en ægte dansk fodbold fan!!\nDu fik %i point. Tillykke!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];

}

theLives.text = @"";
// Make button 1 appear as a reset game button
restartGame = YES;
[answerOne setHidden:NO];
[appstore setHighlighted:NO];
[answerOne addTarget:self action:@selector(reset)forControlEvents:
UIControlEventTouchDown];
[answerOne setTitle:@"Prøv igen!" forState:UIControlStateNormal];
[showachievements setHidden:NO];
[ShowLeader setHidden:NO];
[submitScore setHidden:NO];
[appstore setHidden:YES];
[appstorelabel setHidden:YES];
[sendsms setHidden:NO];
[animation setHidden:YES];
[animationsmiley setHidden:YES];
}
}
else
{
// Give a short rest between questions
time = 3.5;

// Initialize the timer
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
}
}

-(void)reset {
[answerOne removeTarget:self action:@selector(reset)forControlEvents:UIControlE ventTouchDown];
[self viewDidLoad];
}

-(void)countDown
{
// Question live counter
if(questionLive==YES)
{
time = time - 1;
theLives.text = [NSString stringWithFormat:@"Tid tilbage: %i!", time];

if(time == 0)
{
// Loser!
questionLive = NO;
theQuestion.text = @"Desværre, tiden løb fra dig!";
myScore = myScore - 50;
[timer invalidate];
[self updateScore];
}
}
// In-between Question counter
else
{
time = time - 1;
theLives.text = [NSString stringWithFormat:@"Næste spørgsmål..%i!", time];

if(time == 0)
{
[timer invalidate];
theLives.text = @"";
[self askQuestion];
}
}
if(time < 0)
{
[timer invalidate];
}
}
__________________
Thanks for taking the time to help a newbie
Jaxen66 is offline   Reply With Quote
Old 12-29-2011, 12:03 PM   #132 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 79
Jaxen66 is on a distinguished road
Default

Last part of my .m file

Quote:

-(void)checkAnswerint)theAnswerValue

{
if(rightAnswer == theAnswerValue)
{
theQuestion.text = @"Sådan der! \n50 point til kontoen!";
myScore = myScore + 50;

[animationsmiley setHidden:NO];
animationsmiley.animationImages = [NSArray arrayWithObjects:

[UIImage imageNamed:@"smiley-4-2 (trukket).tiff"],
[UIImage imageNamed:@"smiley-4-3 (trukket).tiff"],
nil];

[animationsmiley setAnimationRepeatCount:0];

animationsmiley.animationDuration = 2.7;

[animationsmiley startAnimating];

NSString *path = [[NSBundle mainBundle] pathForResource:@"Korrekt" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
[theAudio play];

}
else
{
theQuestion.text = @"Desværre! \nDet fik du ikke nogle point for..!";
myScore = myScore - 0;

[animation setHidden:NO];
animation.animationImages = [NSArray arrayWithObjects:


[UIImage imageNamed:@"football_01_5-7 (trukket).tiff"],

[UIImage imageNamed:@"football_01_5-8 (trukket).tiff"],
nil];


[animation setAnimationRepeatCount:0];

animation.animationDuration = 1;

[animation startAnimating];

NSString *path = [[NSBundle mainBundle] pathForResource:@"Forkert" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
[theAudio play];

}
[self updateScore];
}
-(void)loadQuiz
{
// This is our forced-loaded array of quiz questions.
// FORMAT IS IMPORTANT!!!!
// 1: Question, 2 3 4 5: Answers 1-4 respectively, 6: The right answer
// THIS IS A TERRIBLE WAY TO DO THIS. I will figure out how to do nested arrays to make this better.
NSArray *quizArray = [[NSArray alloc] initWithObjects:

@"Hvor langtid gik der før det hurtigeste mål i superligaen blev scoret?", @"20 sekunder", @"16 sekunder", @"7 sekunder", @"18 sekunder", @"2",
@"Hvem scorede det hurtigeste mål?", @"Peter Graulund", @"Baba Collins", @"Frank Kristensen", @"Peter Møller", @"1",

@"Hvilken spiller har fået flest røde kort?", @"Thomas Rytter", @"Carsten Hemmingsen", @"Tommy Nielsen", @"Steffen Højer", @"1",
@"Hvor mange runder bliver der spillet i Superligaen?", @"34 Runder", @"32 Runder", @"33 Runder", @"30 Runder", @"3",
@"Hvor mange hold er der i Superligaen?", @"12", @"11", @"14", @"10", @"1",
@"Hvem blev topscore i sæsonen 2007-08?", @"Caeser Santin", @"Dame N'Doye", @"Peter Utaka", @"Jeppe Curth", @"4",
@"Hvad endte det første New Firm?", @"0-1", @"1-0", @"1-1", @"2-1", @"3",
@"Hvor mange selvmål blev der scoret i sæsonen 08/09?", @"10", @"14", @"20", @"7", @"2",
@"Hvor mange hattricks blev der scoret i sæsonen 08/09?", @"0", @"10", @"7", @"4", @"4",
@"Hvor gammel var den yngste spiller i superligaen nogensinde?", @"17 år og 86 dage", @"16 år og 105 dage", @"17 år og 160 dage", @"16 år og 35 dage", @"4",
@"Hvad hed den yngste spiller i superligaen nogensinde?", @"Lucas Andersen", @"Kenneth Zohore", @"Mads Beierholm", @"Navid Dayyani", @"2",
@"Hvem har spillet flest kampe all time i superligaen?", @"Jimmy Nielsen", @"Mogens Krogh", @"Per Nielsen", @"Arek Onyszko", @"3",
@"Hvem er cheftræner for AC Horsens", @"Kent Nielsen", @"Henrik Jensen", @"Troels Bech", @"Johnny Mølby", @"4",
@"Hvilket hold rykkede ned i den seneste sæson?", @"Randers FC & Esbjerg", @"Randers FC & HB Køge", @"Lyngby & HB Køge", @"Sønderjyske & Esjberg", @"1",
@"Hvilken klub har Rajko Lekic ikke spillet i?", @"Aab", @"OB", @"Silkeborg", @"Esbjerg", @"1",
@"Hvad hedder Randers FC's hjemmebane?", @"TRE-FOR Park", @"Essex Park", @"MCH Arena", @"Blue Water Arena", @"2",
@"Hvem har som den eneste formået at blive topscorer i Superligaen tre år i træk?", @"Ebbe Sand", @"Søren Frederikssen", @"Peter Møller", @"Steffen Højer", @"4",
@"Peter Utaka kom til OB i 2008, men hvilket land spillede han i før?", @"Belgien", @"Holland", @"Tyskland", @"Portugal", @"1",
@"Hvilken Superliga-klub spillede Henrik ’Store’ Larsen i, da han blev topscorer i EM 1992?", @"AGF", @"FC København", @"Aab", @"Lyngby", @"4",
@"Hvornår vandt Brøndby IF senest det danske mesterskab?", @"2006/2007", @"2004/2005", @"2003/2004", @"2005/2006", @"2",
nil];

self.theQuiz = quizArray;
[quizArray release];


}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}


- (void)dealloc {
[theQuestion release];
[theScore release];
[theLives release];
[answerOne release];
[answerTwo release];
[answerThree release];
[answerFour release];
[theQuiz release];
[timer release];
[appstore release];
[appstorelabel release];
[sendsms release];
[animationsmiley release];
[animation release];
[super dealloc];

}


- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


@end
__________________
Thanks for taking the time to help a newbie
Jaxen66 is offline   Reply With Quote
Old 12-29-2011, 09:29 PM   #133 (permalink)
Registered Member
 
marshusensei's Avatar
 
Join Date: Mar 2011
Location: Australia
Age: 28
Posts: 105
marshusensei is on a distinguished road
Default Jakob

Morning Jakob,

I had a quick look at your code and it seems to be working. I'm not sure about the warnings you are getting. I don't have much time today to look over it more closely, but when I get some free time I'll have a closer look.

When I made my quiz I put the questions and answers in a .txt file that looked like this:

Code:
Which official symbol of Australia identifies Commonwealth property?
a. The national anthem 
b. Australias national flower 
c. Commonwealth Coat of Arms
d. The Union Jack
3
Then loaded the quiz like this:

Code:
-(void)loadQuiz
{
	NSBundle *bundle = [NSBundle mainBundle];
	NSString *textFilePath = [bundle pathForResource:@"quizgame" ofType:@"txt"];
	//NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath];
	NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:nil];[NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:nil];
    
    NSArray *quizArray = [[NSArray alloc] initWithArray:[fileContents componentsSeparatedByString:@"\n"]];
	self.theQuiz = quizArray;
}
Still not the best way to deal with large numbers of questions, but a little bit 'cleaner' than the method you are presently using.

Keep trying Jakob! You'll succeed.

Matt
__________________
Please visit - MushroomPudding.com
marshusensei is offline   Reply With Quote
Old 12-30-2011, 05:23 AM   #134 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 79
Jaxen66 is on a distinguished road
Default

Quote:
Originally Posted by marshusensei View Post
Morning Jakob,

I had a quick look at your code and it seems to be working. I'm not sure about the warnings you are getting. I don't have much time today to look over it more closely, but when I get some free time I'll have a closer look.

When I made my quiz I put the questions and answers in a .txt file that looked like this:

Code:
Which official symbol of Australia identifies Commonwealth property?
a. The national anthem 
b. Australias national flower 
c. Commonwealth Coat of Arms
d. The Union Jack
3
Then loaded the quiz like this:

Code:
-(void)loadQuiz
{
	NSBundle *bundle = [NSBundle mainBundle];
	NSString *textFilePath = [bundle pathForResource:@"quizgame" ofType:@"txt"];
	//NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath];
	NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:nil];[NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:nil];
    
    NSArray *quizArray = [[NSArray alloc] initWithArray:[fileContents componentsSeparatedByString:@"\n"]];
	self.theQuiz = quizArray;
}
Still not the best way to deal with large numbers of questions, but a little bit 'cleaner' than the method you are presently using.

Keep trying Jakob! You'll succeed.

Matt
I have tried to load the .txt file, and it did perfect except that it won't show the danish letters like: æ,ø,å. So that's why i don't use a .txt to store the questions. If anyone have an answer on how you can make it show danish or any other letters than english, please PM me

Today i will upload the code where i use the code you linked to, so you can see these warnings i get when i use the code. I still cant figure out have to take 10 out of 100 questions and 10 out of then 90 and then 10 out of 80. So the questions won't come to the user again before he have played it 10 times.
__________________
Thanks for taking the time to help a newbie
Jaxen66 is offline   Reply With Quote
Old 01-06-2012, 10:54 PM   #135 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 1
Dal10 is on a distinguished road
Default

Love your work! This tutorial is great - I changed it slightly to run on the iPad (which also allows for longer questions and answers) and then included it into a Grammar app I'm working on.
However it crashes the app when it is finished and I go back to the main app (via inapt navigation from main app).
Guessing it is related to the problem with the reset button? I tried to simply turn it off so that the quiz ended on the score page.
Any suggestions on how to 'close it' ?
Thanks
Dal10 is offline   Reply With Quote
Old 01-20-2012, 12:33 PM   #136 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 1
asookazian is on a distinguished road
Default

what version of XCode is required to test the sample code provided in the zip file? I am running 4.3 IIRC. thx.
asookazian is offline   Reply With Quote
Old 01-23-2012, 11:38 PM   #137 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 1
newzealandmart is on a distinguished road
Default still got confused

hey still got confused on how to upload this ... does anyone can give quick guid about how to upload it ?
newzealandmart is offline   Reply With Quote
Old 02-12-2012, 11:44 AM   #138 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 79
Jaxen66 is on a distinguished road
Default

Quote:
Originally Posted by newzealandmart View Post
hey still got confused on how to upload this ... does anyone can give quick guid about how to upload it ?
What do you want to upload?
__________________
Thanks for taking the time to help a newbie
Jaxen66 is offline   Reply With Quote
Old 02-15-2012, 12:20 PM   #139 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 79
Jaxen66 is on a distinguished road
Red face Next button?

Hey! Did any of you ever the next question button get to work, instead of using a timer?
__________________
Thanks for taking the time to help a newbie
Jaxen66 is offline   Reply With Quote
Old 04-25-2012, 05:59 AM   #140 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
alessign is on a distinguished road
Default Reveal answers?

Hi guys, I am now trying to include action connected to UISegmented control to reveal the correct answer as a training mode. When the value from UISegmentedControl is selected, I would like to have the .alpha of the correct answer set to 1.0 and the other to 0.2. I was playing with it but couldn't find the way to link it together. How do I know which button is the correct one? In the method checkAnswer is only string involved...
Code:
    if(rightAnswer == theAnswerValue)
	{
		theQuestion.text = @"Correct answer!";
		myScore = myScore + 1;
              
	}
	else
	{
		theQuestion.text = @"Wrong answer!";
		myScore = myScore - 1;

                if([segmentControl selectedSegmentIndex] == 1){
                ??button.alpha = 0.2;                   

                     }
	}
	[self updateScore];
Can anybody point on how to get to know the correct button name please?

Thank you
Alessign
alessign is offline   Reply With Quote
Old 04-26-2012, 01:39 PM   #141 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
alessign is on a distinguished road
Default Revealing the answers

Ok, I came a bit closer to the solution. It is still making mess a bit. If somebody can point me the right direction, it would be much appreciated. Thank you

1) I set up tags to each button in viewDidLoad
Code:
 answerOne.tag = 1;
    answerTwo.tag = 2;
    answerThree.tag = 3;
    answerFour.tag = 4;
2) I set up IBAction and connected to the UISegmentedControl("segment" below) in XIB

Code:
   //------    not equal
     if ([segment selectedSegmentIndex] == 0 ){
        self.answerOne.alpha = 1.0;
        self.answerTwo.alpha = 1.0;
        self.answerThree.alpha = 1.0;
        self.answerFour.alpha = 1.0;
       
    }
3) I set up method in countDown section:
Code:
if(time == 0)
		{
			[timer invalidate];            
			theLives.text = @"";
            [self askQuestion];
            
            //------------- TEST MODE
            
            if ([segment selectedSegmentIndex] == 1 && answerOne.tag != rightAnswer){
                self.answerOne.alpha = 0.3;                
            }
            else {
                self.answerOne.alpha = 1.0;
            }
            
            if ([segment selectedSegmentIndex] == 1 && answerTwo.tag != rightAnswer){     
                self.answerTwo.alpha = 0.3;                
            }
            else {
                self.answerTwo.alpha = 1.0;
            }
            
            if ([segment selectedSegmentIndex] == 1 && answerThree.tag != rightAnswer){                
                self.answerThree.alpha = 0.3;              
            }
            else {
                self.answerThree.alpha = 1.0;
            }
            
            if ([segment selectedSegmentIndex] == 1 && answerFour.tag != rightAnswer){               
                self.answerFour.alpha = 0.3;               
            }
            else {
                self.answerFour.alpha = 1.0;
            } 
        
		}
If I run the app and select the test mode, it will lower the opacity correctly but I need to hide the segmentedControl, when the "Ready" button is pressed.

If I select the normal mode again, all buttons appear with alpha 1.0 as wanted.

How can I hide the UISegmented control in the right moment please?

Thanks!

Last edited by alessign; 04-26-2012 at 02:22 PM.
alessign is offline   Reply With Quote
Old 04-26-2012, 03:13 PM   #142 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
alessign is on a distinguished road
Default Revealing the answers

Got it. Not sure if it is the right approach, but it is doing what I need. There is the code if somebody will needed. Implement this code to the askQuestion method on the end:
Code:
if(myScore <= 0 && myScore >=0){
        segment.hidden = YES;
    }
alessign is offline   Reply With Quote
Old 04-30-2012, 05:26 PM   #143 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
alessign is on a distinguished road
Default Randomise?

I was trying to create the randomise function, but missing something. If somebody can have a look at it and suggest improvements, it will help to lot of people.

I've created NSMutableArrays to get rid of duplicates:
-(void)viewLoad method:
Code:
int length = 10; 
    indexes = [[NSMutableArray alloc] initWithCapacity:length];
    
   for (int i=0; i<10; i++) [indexes addObject:[NSNumber numberWithInt:i]];
    shuffle = [[NSMutableArray alloc] initWithCapacity:length];
    while ([indexes count])
    {
        //int index = rand()%[indexes count];
        int index = arc4random()%[indexes count];
        
        [shuffle addObject:[indexes objectAtIndex:index]];
        NSLog(@"shuffle: %@", shuffle);
        [indexes removeObjectAtIndex:index]; 
        NSLog(@"indexes: %@ ", indexes);
    }
    
    for (int i=0; i<[shuffle count]; i++)
        NSLog(@"Shuffles%@", [shuffle objectAtIndex:i]);
NSLogs will show the arrays. It works well, no duplicates of numbers

Next one is to get the number.
-(void)askQuestion method:
Code:
.
..
...
	// Set the time for the timer
	time = 8.0;
	
    questionNumber = [[shuffle objectAtIndex:0] intValue] + 1;
       
    	NSInteger row = 0;
   
	if(questionNumber == 1)
	{
		row = questionNumber - 1;
        
	}
	else
	{
		row = ((questionNumber - 1) * 6);
       
	}
...
..
.
shuffle & indexes are NSMutableArrays declared in .h file

There is a bug in the withdrawing the number of the question somewhere here:

questionNumber = [[shuffle objectAtIndex:0] intValue] + 1;

because I get only first number from the array and next question will be the same number on and on. If I understand it right, each time the question is asked, it picks the objectAtIndex:0. It is alright for the first time, but next number should be different. Is there any way to change "0" for something else or include ++ somehow?

Thank you for your time!!!
alessign is offline   Reply With Quote
Old 05-03-2012, 05:23 AM   #144 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
alessign is on a distinguished road
Default Randomise

I got it to work! The method 'while' was doing the mess. It actually created all indexes and the new array by viewDidLoad, before the question was asked. That's way it kept repeating one number. Here is the code:
declare NSMutableArrays in .h file
Code:
NSMutableArray *shuffle;
    NSMutableArray *indexes;    
...

@property (retain, nonatomic) NSMutableArray *shuffle;
@property (retain, nonatomic) NSMutableArray *indexes;
Than synthetize & initialise the arrays in the viewDidLoad method:
Code:
    int length = 10; 
    indexes = [[NSMutableArray alloc] initWithCapacity:length];
    
    for (int i=0; i<10; i++) [indexes addObject:[NSNumber numberWithInt:i]];
    shuffle = [[NSMutableArray alloc] initWithCapacity:length];
Last thing to include in askQuestion method:
Code:
...
..
.
time = 8.0;
	
   
        int index = arc4random()%[indexes count];
        
        [shuffle addObject:[indexes objectAtIndex:index]];
        NSLog(@"shuffle: %@", shuffle);
        [indexes removeObjectAtIndex:index]; 
        NSLog(@"indexes: %@ ", indexes);
      
    for (int i=0; i<[shuffle count]; i++)
    
    questionNumber = [[shuffle objectAtIndex:i] intValue] + 1;  
           
      
    	NSInteger row = 0;
...
..
.
The only problem to solve is that if the question number 10 has been selected, the quiz is finished. That means, if you get the Q nr. 10 as first selected , the quiz will terminate after first question displayed...

Any ideas how to prevent this behaviour?

Thanks A.
alessign is offline   Reply With Quote
Old 05-09-2012, 07:47 AM   #145 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
alessign is on a distinguished road
Default Random function solved!!!

I have finally solved the random function completely. Last piece to the puzzle is the code below. All you need to add is:

-(void)updateScore method:
Code:
...
..
.
// END THE GAME.
   
    if ([indexes count] == 0) 	
    {
        
		// Game is over.
		if(myScore > 0)
		{
			NSString *finishingStatement = [[NSString alloc] initWithFormat:@"You scored %i!", myScore];
			theQuestion.text = finishingStatement;
.
..
...
alessign is offline   Reply With Quote
Old 05-11-2012, 11:51 PM   #146 (permalink)
New User
 
Join Date: May 2012
Posts: 1
gordo26 is an unknown quantity at this point
Default App Crashes

This app worked fine without the text file, but whenever I try and use the text file the app crashes the second I press the Play Now button?! At first I was getting a deprecated error but now that's fixed. The app builds with no errors. Anyone else have this problem, or know of any solution?

I know the problem lies within the below function, specifically with the array. I'm just not sure how to fix it!

-(void)askQuestion
{
// Unhide all the answer buttons.
[answerOne setHidden:NO];
[answerTwo setHidden:NO];
[answerThree setHidden:NO];
[answerFour setHidden:NO];

// Set the game to a "live" question (for timer purposes)
//questionLive = YES;

// Set the time for the timer
time = 8.0;

// Go to the next question
questionNumber = questionNumber + 1;

// THIS IS REALLY TERRIBLE CODE!!!
// We get the question from the questionNumber * the row that we look up in the array.
// This is absolutely horrible, just a placeholder until the right way.
// I cannot even begin to describe how wrong this solution is.
NSInteger row = 0;
if(questionNumber == 1)
{
row = questionNumber - 1;
}
else
{
row = ((questionNumber - 1) * 6);
}
// Set the question string, and set the buttons the the answers

NSString *selected = [theQuiz objectAtIndex:row];
NSLog(@"The Selected String = %@", selected);
NSString *activeQuestion = [[NSString alloc] initWithFormat:@"Question: %@", selected];
[answerOne setTitle:[theQuiz objectAtIndex:row+1] forState:UIControlStateNormal];
[answerTwo setTitle:[theQuiz objectAtIndex:row+2] forState:UIControlStateNormal];
[answerThree setTitle:[theQuiz objectAtIndex:row+3] forState:UIControlStateNormal];
[answerFour setTitle:[theQuiz objectAtIndex:row+4] forState:UIControlStateNormal];
rightAnswer = [[theQuiz objectAtIndex:row+5] intValue];

// Set theQuestion label to the active question
theQuestion.text = activeQuestion;

// Start the timer for the countdown
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];

[selected release];
[activeQuestion release];
}

Looking at the console after doing NSLog on the variable selected, which I assume gives me the string of the selected row, I instead get the entire txt file logging??

The console gives this message: Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]

Last edited by gordo26; 05-12-2012 at 07:10 PM.
gordo26 is offline   Reply With Quote
Old 05-13-2012, 12:53 PM   #147 (permalink)
New User
 
Join Date: Apr 2012
Location: Florence, Italy
Posts: 1
lucciorebus is on a distinguished road
Default One question about the "random stuff"

Quote:
Originally Posted by alessign View Post
I have finally solved the random function completely. Last piece to the puzzle is the code below. All you need to add is:

-(void)updateScore method:
Code:
...
..
.
// END THE GAME.
   
    if ([indexes count] == 0) 	
    {
        
		// Game is over.
		if(myScore > 0)
		{
			NSString *finishingStatement = [[NSString alloc] initWithFormat:@"You scored %i!", myScore];
			theQuestion.text = finishingStatement;
.
..
...

Hey, it works fine. GREAT JOB!
But I have one question: if I got it right let's say you have 20 question and this "shuffles" them.
What would you suggest if I have 50 questions and I want to shuffle (let's say) 10 of them randomly?

I hope my question is clear, quite a newbie here...

And thank you for your great solution!

Lamberto
lucciorebus is offline   Reply With Quote
Old 05-18-2012, 07:06 PM   #148 (permalink)
New User
 
Join Date: May 2012
Posts: 2
RocketBaby is an unknown quantity at this point
Default

Fantastik discussion. Thanks!

But Can you please make some notes/updates regarding IOS5 (2012) and integration of sqlite? Also please a code for multiplayer (Playing quiz game against friend) - I have some serious errors here

Codes would be appreciated. Thank you so much for a nice thread!

RocketBaby
RocketBaby is offline   Reply With Quote
Old 05-19-2012, 10:44 AM   #149 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
alessign is on a distinguished road
Default

Quote:
Originally Posted by lucciorebus View Post
Hey, it works fine. GREAT JOB!
But I have one question: if I got it right let's say you have 20 question and this "shuffles" them.
What would you suggest if I have 50 questions and I want to shuffle (let's say) 10 of them randomly?

I hope my question is clear, quite a newbie here...

And thank you for your great solution!

Lamberto
I think you have few options here. Have a look at Arrays in general. It depends if you want to shuffle random 10 of 50 or specific 10 of 50. You can access separate them by ObjectAtIndex method or just do 2 arrays 10 + 40...
alessign is offline   Reply With Quote
Old 05-21-2012, 09:05 AM   #150 (permalink)
New User
 
Join Date: May 2012
Posts: 1
David-T is an unknown quantity at this point
Default

Damn I keep getting the SIGABRT warning! I included an image, if anyone know what's going on..

I've restarted my system, Xcode, all that and it still gives me that error?

Yesterday the Quiz worked alright, got some warnings about implementation (only yellow ones) but it worked!

I can't even play the app now :S

I wanted to rebuild the app from scratch in XCode 4.3, but it's kind of difficult when I can no longer refer to the original Quiz app

Does anyone have a updated version of this game, after iOS5 was released?
Attached Images
File Type: jpg sigabrt.jpg (66.4 KB, 4 views)

Last edited by David-T; 05-21-2012 at 09:11 AM.
David-T is offline   Reply With Quote
Reply

Bookmarks

Tags
game, quiz, tutorial

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 408
8 members and 400 guests
13dario13, ChrisYates, fredidf, iOS.Lover, Leslie80, Meoz, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:38 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0