tictactoe game switching turns problem :( help pleas

Started by
3 comments, last by NEXUSKill 11 years, 8 months ago
hey

okay so I'm kinda new to game development :)

so I have this game where I need to switch turns after each mouse click the way I forth I cut due this was to put this code inside the update part


if((mouseX>25&&mouseX<195)&&(mouseY<605&&mouseY>435)){
if(Mouse.isButtonDown(0)){
if(playTurn ==1){
places[1] = 1;
playTurn = 2;


}else if(playTurn ==2){
places[1] = 2;
playTurn = 1;


}else{

}
}


}



but it's simply updating to fast so when the user holds down the mouse button / clicking slow it don't just switch turn 1 time but maybe 100 times witch I don't want I need it to only switch turn one pre click no matter what&nbsp; how can I do this ??
have been traying to fix this bay using thread but i'm not good at using threads :( so can't get it working :(

sry for my english :(
Advertisement
Something along these lines maybe:


if(Mouse.isButtonDown(0)) {
click = true;
} else if(click) {
click = false;
//if(playTurn == 1)...
}


Where click is a boolean outside your function:


boolean click = false;
I think you need to switch the turns when the mouse button is released, not down. The problem is your loop is updating so many times while the mouse button is down that it switches the turn 100+ times before the user lets the button up.
thanks for the good answeres i ended op using greenvertex replay :) works perfektly :)

bluehaliex i have been think the same as you but can find the right code for that to work :(

sry for my english :(
Changing turns on a tic tac toe has nothing to do with a mouse click, at least not directly, the turn changes only after the current player successfully places a new mark, if he clicks on an already marked cell, nothing should happen, if he clicks outside the board, nothing should happen, ect.

As for the mouse event, what you want to catch is the moment the mouse button is released and at which screen position that happens.
Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272


This topic is closed to new replies.

Advertisement