Thread: Timer?

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

    Timer?

    I want to update the int line every time a line is cleared in my tetris game. And I want to tell how many lines are cleared at once so I can adjust the score accordingly....

    Code:
    void ClearLine()
    {
      int num;
      static int line;
    
      for(int j = 20; j > 0; j--)
      {
        num = 0;
        for(int i = 0; i < 10; i++)
        {
          if(map[i][j] != (BITMAP*)data[Blank].dat) num++;
        }
    
        if(num == 10)
        {
          line++;
          Current.lines++;
          for(int l= j; l >= 1; l--)
            for(int k = 0; k < 10; k++)
            {
              map[k][l] = map[k][l - 1];
            }
        }
    
      }
      
       if(line == 1) score += 1000;
       if(line == 2) score += 2000;
       line = 0;
    }
    now it always adds only 1000... never 2000... how can I make it wait to see howmany are cleared at once?

  2. #2
    Aryoc
    Guest
    Now I'm not exactly sure what you're doing there, didn't feel like examining the code so closely, but wouldn't it be easier to first check all the lines to see if they are "full" (ie. if they should disappear and give points), and only then adjust the lines (erase full ones, move ones above lower and so forth)? Because if you check one and adjust it right away, it'll probably make figuring out where to continue checking harder.

  3. #3
    J.Ewing
    Guest
    Here is the crux of your problem: When you find a full line, you are taking all of the blocks above that line and moving them down by one (ie. "up" one within your "map" array). Then the loop ends and decrements "j" by one. However, since the lines have been moved down one, the line that was above line "j" is now ~on~ line "j" - so "j" should not be decremented. The value of "j" should remain the same on the next iteration of the loop, since the lines above have been shuffled down by one. The easiest way to do this is to simply increment "j" by one after you have done the other necessary operations.

    So this variation should work (there are a couple of touch-ups in there, but the "j++;" is the important one):


    void ClearLine()
    {
    int num, line = 0;

    for(int j = 20; j > 0; j--)
    {
    for(num = 0; num < 10; num++)
    {
    if(map[i][j] != (BITMAP*)data[Blank].dat) break;
    }

    if(num >= 10)
    {
    line++;
    Current.lines++;
    for(int l= j; l >= 1; l--)
    for(int k = 0; k < 10; k++)
    {
    map[k][l] = map[k][l - 1];
    }
    j++; /** the critical component **/
    }

    }
    score += line * 1000;
    line = 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM
  4. Timer again.
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 05-04-2005, 10:19 PM