Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 30, 2009, 04:47 AM   #1
iphonedevelop18
macrumors member
 
Join Date: Feb 2009
A few Questions...

First of all I am making a tic tac toe game.

1. how can a set an int to a random number, ie.
Code:
difficulty = 5;
choice = (random() % difficulty) + 1;
if (choice != 2){
}
it will stay the same throughout as i tried to set difficulty to 100 and it would stay the same.

2. How can I delay the reaction of the computer.

Thanks!
iphonedevelop18 is offline   0 Reply With Quote
Old Mar 30, 2009, 06:54 AM   #2
mccannmarc
macrumors 6502
 
Join Date: Aug 2008
Location: Manchester, UK
Send a message via MSN to mccannmarc
I will answer your first question but I don't quite get what you mean by the second one

The reason your random number will be the same is because you are not seeding the random number off of anything. if you put the following line before your code for generating the random number you will find it will start working. Try this:-

Code:
difficulty = 5;
srandom(time(NULL));
choice = (random() % difficulty) + 1;
if (choice != 2){
}
__________________
DudeWare site:- http://www.dude-ware.co.uk DudeWare forum:- http://www.forum.dude-ware.co.uk
mccannmarc is offline   0 Reply With Quote
Old Mar 30, 2009, 07:32 AM   #3
jnic
macrumors 6502a
 
Join Date: Oct 2008
Location: Cambridge
2. NSTimer
jnic is offline   0 Reply With Quote
Old Mar 30, 2009, 01:09 PM   #4
iphonedevelop18
Thread Starter
macrumors member
 
Join Date: Feb 2009
mccannmarc

Yea I already seeded it in the app delegate under didfinish launching or whatever. So I don't think I have to seed it again do I?

Last edited by iphonedevelop18; Mar 30, 2009 at 02:03 PM.
iphonedevelop18 is offline   0 Reply With Quote
Old Mar 31, 2009, 02:38 AM   #5
CocoaPuffs
macrumors 68010
 
Join Date: Aug 2008
Quote:
Originally Posted by jnic View Post

Code:
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
CocoaPuffs is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
PS/LR questions Outrigger Digital Photography 8 Nov 25, 2013 08:46 PM
October 2013 Event - Questions, questions eladnova OS X 5 Oct 9, 2013 06:40 AM
Few Questions Regarding new MP Foxdog175 Mac Pro 0 Jun 13, 2013 12:51 PM
Switch to Mac - questions, questions bscrabble iMac 8 Apr 1, 2013 09:30 PM
A Few Questions CreationArt PowerPC Macs 17 Sep 24, 2012 11:12 AM

Forum Jump

All times are GMT -5. The time now is 10:38 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC