bool foundline=true;
for (int h=0;h<BOARDHEIGHT;h++) {
for (int w=0;w<BOARDWIDTH;w++) {
if (board[w][h]>0)
foundline=false;
}
if (foundline==true) {
// delete lines
for (int i=0;i<BOARDWIDTH;i++) {
board[h]=0;
}
} else
foundline=true;
}
what's wrong with this?
I'm trying to check if a line is filled with a value greater than 0. If some of the lines in the array is filled with those values, it's going to reset them. Check the following code:
I can't find anything wrong in this code, if I remove the if statement it works, but deletes everything. See anything wrong with it?
You're setting foundline to false whenever you detect a value that is greater than zero in a given line, thereby preventing the next loop from clearing the line.
Quote:Original post by passwordWhen you say "it's going to reset them", do you mean just the values greater than 0 or all of them?
I'm trying to check if a line is filled with a value greater than 0. If some of the lines in the array is filled with those values, it's going to reset them. Check the following code:
Quote:My best guess would be that you meant the first foundline=false; line to read foundline=true.
*** Source Snippet Removed ***
I can't find anything wrong in this code, if I remove the if statement it works, but deletes everything. See anything wrong with it?
Also, if you want to reset values greater than 0, couldn't you do that in the first loop? As in:
for(int h=0; h < BOARDHEIGHT; ++h){ for(int w=0; w < BOARDWIDTH; ++w) { if(board[w][h] > 0) { board[w][h] = 0; } }}
That's the meaning of it, because I want it to be set to false if it finds even one value which is not 0 thereby preventing it to clear a line that isn't full.
Quote:Original post by templewulfQuote:Original post by passwordWhen you say "it's going to reset them", do you mean just the values greater than 0 or all of them?
I'm trying to check if a line is filled with a value greater than 0. If some of the lines in the array is filled with those values, it's going to reset them. Check the following code:Quote:My best guess would be that you meant the first foundline=false; line to read foundline=true.
*** Source Snippet Removed ***
I can't find anything wrong in this code, if I remove the if statement it works, but deletes everything. See anything wrong with it?
Also, if you want to reset values greater than 0, couldn't you do that in the first loop? As in:
*** Source Snippet Removed ***
No, it's only supposed to delete a line if the whole line is full and I mean the values greater than 0.
You do not even need the foundline boolean:
One of the few cases were goto makes sense :)
for (int h = 0; h < BOARDHEIGHT; h++){ for (int w = 0; w < BOARDWIDTH; w++) { if (board[w][h] == 0) goto out; } for (int i = 0; i < BOARDWIDTH; i++) { board[h] = 0; } out:}
One of the few cases were goto makes sense :)
I'd split it into several small functions for readability. I've read the above and I think you mean if, and only if, every element in a line is >0, set the whole line to zero. Yes? (Tetris?)
Might seem like overkill but if it gets complicated by a future development of some kind, it'll be easier to update.
int BW,BH; // boardwidth, boardheightbool LineFull(int Y){ for(int X=0;X<BW;++X) if(Board[X][Y]<=0) return false; return true;}void ClearLine(int Y){ for(int X=0;X<BW;++X) Board[X][Y]=0;}void CheckBoard(){ for(int Y=0;Y<BH;++Y) { if(LineFull(Y)) ClearLine(Y); }}
Might seem like overkill but if it gets complicated by a future development of some kind, it'll be easier to update.
Quote:Original post by EasilyConfused
I'd split it into several small functions for readability. I've read the above and I think you mean if, and only if, every element in a line is >0, set the whole line to zero. Yes? (Tetris?)
*** Source Snippet Removed ***
Exactly..
The code works like I want to aswell, thanks!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement