Thread: Help!

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    16

    Help!

    How does this work...

    Code:
    for(int i = 0; i < 4; i++)
      for(int j = 0; j < 4; j++)
        if(map[i][j] == blank) collision = 0;
    now if any of the array returns blank it falls but I want it so if even one != blank it will return a collision.

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    I'm making assumptions here, because I can't really tell what your looking for, or how your code works... If you want 'collision' to be non-zero if one space on the 'grid' (I'm assuming) isn't 'blank':

    Code:
    collision = 0;
    for(int i = 0; i < 4; i++)
      for(int j = 0; j < 4; j++)
        if(map[i][j] != blank)
          collision++;
    Or is you want to know if 'at least one' was not blank only:

    Code:
    bool collision = false;
    for(int i = 0; i < 4 && !collision; i++)
      for(int j = 0; j < 4 && !collision; j++)
        if(map[i][j] != blank)
          collision = true;
    Hope this helps
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    16
    yeah sorry about that...

    I figured it out though.. I just needed to clear my variables before the loops.

Popular pages Recent additions subscribe to a feed