Sign in to follow this  

tictactoe game switching turns problem :( help pleas

This topic is 1955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

[CODE]
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{

}
}


}
[/CODE]


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 :(

Share this post


Link to post
Share on other sites
Something along these lines maybe:

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

Where click is a boolean outside your function:

[CODE]
boolean click = false;
[/CODE]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 1955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this