|
-
Jul 26th, 2001, 08:54 PM
#1
Thread Starter
Frenzied Member
Variable mysteriously incrementing
I have a variable called ButtonCheck. It keeps track of which click the user is on in my checkers(draughts) game. You click the piece to move(first click) and then you click where to move (second click). ButtonCheck starts as 0, and after the first click should be set to 1. Next click, if ButtonCheck is 1, then get the destination for the piece and makes the move. It sets it to 3. Then is set to 0. and waits for the next move. But my code gives ButtonCheck in a message box and it's in the thousands....it seems to get higher the longer it takes me to click it. But the thing is I never increment it! Here's the code from the WM_COMMAND, sorry its so long, but it's what does all of the moving and stuff..
Code:
case WM_COMMAND:
for(i=1;i<=8;i++) {
for(a=1;a<=8;a++) {
if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == Board[a][i]) {
if(ButtonCheck==2) { //JUMPING
if(TURN==true) {
if(GetWindowText(Board[x][y],TextChecker,2)=='x') {
if(y2-y==2) {
if(x2-x==2 || x2-x==-2) {
SetWindowText(Board[x][y],NULL); // } Acutally "moves" the pieces
SetWindowText(Board[((x2+x)/2)][((y2+y)/2)],NULL);
SetWindowText(Board[x2][y2],"x");
CheckForKings();
//SendMessage(Status, WM_SETTEXT, 0, (LPARAM) (LPCSTR) "Status: Player 2's Turn");
TURN = false;
CheckForWinner();
}
}
}
}
if(TURN==true) {
if(GetWindowText(Board[x][y],TextChecker,2)=='X') {
if(y2-y==2 || y2-y==-2) {
if(x2-x==2 || x2-x==-2) {
SetWindowText(Board[x][y],NULL); // } Acutally "moves" the pieces
SetWindowText(Board[((x2+x)/2)][((y2+y)/2)],NULL);
SetWindowText(Board[x2][y2],"x");
CheckForKings();
//SendMessage(Status, WM_SETTEXT, 0, (LPARAM) (LPCSTR) "Status: Player 2's Turn");
TURN = false;
CheckForWinner();
}
}
}
}
if(TURN==false) {
if(GetWindowText(Board[x][y],TextChecker,2)=='o') {
if(y2-y==-2) {
if(x2-x==2 || x2-x==-2) {
SetWindowText(Board[x][y],NULL); // } Acutally "moves" the pieces
SetWindowText(Board[((x2+x)/2)][((y2+y)/2)],NULL);
SetWindowText(Board[x2][y2],"o");
CheckForKings();
//SendMessage(Status, WM_SETTEXT, 0, (LPARAM) (LPCSTR) "Status: Player 1's Turn");
TURN = true;
CheckForWinner();
}
}
}
}
if(TURN==false) {
if(GetWindowText(Board[x][y],TextChecker,2)=='O') {
if(y2-y==2 || y2-y==-2) {
if(x2-x==2 || x2-x==-2) {
SetWindowText(Board[x][y],NULL); // } Acutally "moves" the pieces
SetWindowText(Board[((x2+x)/2)][((y2+y)/2)],NULL);
SetWindowText(Board[x2][y2],"o");
CheckForKings();
//SendMessage(Status, WM_SETTEXT, 0, (LPARAM) (LPCSTR) "Status: Player 1's Turn");
TURN = true;
CheckForWinner();
}
}
}
}
//MAIN MOVEMENT
if(GetWindowText(Board[x2][y2],TextChecker,2)!='x' && GetWindowText(Board[x2][y2],TextChecker,2)!='o') {
if(TURN==true) {
if(GetWindowText(Board[x][y],TextChecker,2)=='x') {
if(y2-y == 1) {
if(x2-x == 1 || x2-x == -1) {
SetWindowText(Board[x][y],NULL); // } Acutally "moves" the pieces
SetWindowText(Board[x2][y2],"x"); // }
CheckForKings();
//SendMessage(Status, WM_SETTEXT, 0, (LPARAM) (LPCSTR) "Status: Player 2's Turn");
TURN = false;
CheckForWinner();
}
}
}
}
if(GetWindowText(Board[x2][y2],TextChecker,2)!='x' && GetWindowText(Board[x2][y2],TextChecker,2)!='X' && GetWindowText(Board[x2][y2],TextChecker,2)!='o' && GetWindowText(Board[x2][y2],TextChecker,2)!='O') {
if(TURN==true) {
if(GetWindowText(Board[x][y],TextChecker,2)=='X') {
if(y2-y == 1 || y2-y == -1) {
if(x2-x == 1 || x2-x == -1) {
SetWindowText(Board[x][y],NULL); // } Acutally "moves" the pieces
SetWindowText(Board[x2][y2],"X");
CheckForKings();
//SendMessage(Status, WM_SETTEXT, 0, (LPARAM) (LPCSTR) "Status: Player 2's Turn");
TURN = false;
CheckForWinner();
}
}
}
}
if(TURN==false) {
if(GetWindowText(Board[x][y],TextChecker,2)=='o') {
if(y2-y == -1) {
if(x2-x == 1 || x2-x == -1) {
SetWindowText(Board[x][y],NULL); // } Acutally "moves" the pieces
SetWindowText(Board[x2][y2],"o");
CheckForKings();
//SendMessage(Status, WM_SETTEXT, 0, (LPARAM) (LPCSTR) "Status: Player 1's Turn");
TURN = true;
CheckForWinner();
}
}
}
}
if(GetWindowText(Board[x2][y2],TextChecker,2)!='x' && GetWindowText(Board[x2][y2],TextChecker,2)!='X' && GetWindowText(Board[x2][y2],TextChecker,2)!='o' && GetWindowText(Board[x2][y2],TextChecker,2)!='O') {
if(TURN==false) {
if(GetWindowText(Board[x][y],TextChecker,2)=='O') {
if(y2-y == 1 || y2-y == -1) {
if(x2-x == 1 || x2-x == -1) {
SetWindowText(Board[x][y],NULL); // } Acutally "moves" the pieces
SetWindowText(Board[x2][y2],"O");
CheckForKings();
//SendMessage(Status, WM_SETTEXT, 0, (LPARAM) (LPCSTR) "Status: Player 2's Turn");
TURN = true;
CheckForWinner();
}
}
}
}
}
}
}
ButtonCheck=3;
}
if(ButtonCheck==1) {
x2=a;
y2=i;
char message2[10];
sprintf(message2, itoa(a,buffer,10));
strcat(message2, " , ");
strcat(message2, itoa(i,buffer2,10));
MessageBox(hWnd, message2, "X2,Y2", MB_OK);
ButtonCheck=2;
}
if(ButtonCheck==0) {
char message[10];
x=a;
y=i;
sprintf(message, itoa(a,buffer,10));
strcat(message, " , ");
strcat(message, itoa(i,buffer2,10));
MessageBox(hWnd, message, "X,Y", MB_OK);
ButtonCheck=1;
}
if(ButtonCheck==3) { ButtonCheck=0; }
}
}
}
MessageBox(hWnd,itoa(ButtonCheck,buffer,10), "ButtonCheck", MB_OK);
return 0;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|