A few Questions...

Discussion in 'iPhone/iPad Programming' started by iphonedevelop18, Mar 30, 2009.

  1. macrumors member

    #1
    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!
     
  2. macrumors 6502

    mccannmarc

    #2
    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){
    } 
    
     
  3. macrumors 6502a

    #3
  4. macrumors member

    #4
    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?
     
  5. macrumors 68010

    #5

    Code:
    - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
     

Share This Page