Jump to content

  • Log In with Google      Sign In   
  • Create Account

tictactoe game switching turns problem :( help pleas


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 simondid   Members   -  Reputation: 190

Like
0Likes
Like

Posted 08 August 2012 - 05:34 PM

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

Sponsor:

#2 greenvertex   Members   -  Reputation: 510

Like
2Likes
Like

Posted 08 August 2012 - 06:22 PM

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;


#3 bluehailex   Members   -  Reputation: 143

Like
2Likes
Like

Posted 08 August 2012 - 06:26 PM

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.

#4 simondid   Members   -  Reputation: 190

Like
0Likes
Like

Posted 09 August 2012 - 04:19 AM

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

#5 NEXUSKill   Members   -  Reputation: 457

Like
0Likes
Like

Posted 09 August 2012 - 09:42 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS