   Turn based card game input organisation
  Hi all, I'm having something a of a software design conundrum. I'm posting here because I figure it's probably quite a beginner question :). If you want to skip the description of the problem and go straight to the question, scroll down ^_^Basically I'm having a problem with my turn-based card game. Each time the game polls a player for it's move, the player returns a "Command", which is the move they want to make, encapsulated in an object that holds the method call specific to that move. For AI players, generating the move in this way is fairly simple the game calls a method on the AI player interface, which examines the game state and return the appropriate command.I hit a wall in generating the move for a human player. The user interface for the game is written in Java's Swing, which like most GUI's, is event driven and uses its own loop for events and painting etc. So when I call a method on the user interface to get a user command, my options are quite limited. My first instinct was to write a while loop, that waits on a global variable until it is set to some usable value. This variable would be set when user does some action, such as drag a card to a valid location. However, unfortunately, sitting in the while loop and waiting on the command to be non-null seems to freeze out the Swing loop and so no repainting gets done, and the GUI locks up. To solve this problem would probably need some expert Java help so I'm not asking for help there, so basically...My question is, what sort of command input organisation can anyone recommend, for a turn based card game? Am I going about this the "wrong" way, am I making it too hard for myself??[Edited by - DrunkenLizard on June 14, 2009 8:35:06 AM]
  Hi,I guess you are missing a state in your turn depiction.When a player (AI or human) takes his turn, he will analyze his move then play his card. Your game loop could be more along these lines:method from a player classplayer.update() //called by the game loop to check what is the player doing{if analyze_ended  state = Play_commandelse  state = Analyze_gamereturn state}current_player = first_playerWhile(game not won){state = current_player.update()if state=Play_command{ProcessGamePlay(current_player.GetCommand()) //updates the game with the player actioncurrent_player.reset_state()  //resets the state for the next player turncurrent_player = get_next_player() //get the next available player}render_gameevaluate_end_game}This way you just derive from the player class your AI player and your human player. Since the game polls players to know what they are doing, you are not constrained anymore. While the human player has not selected the card to play, he is still in analyze_game state. When the player has selected the card to play, he switches to the play_command state.Hope that helps.Ghostly yours,Red.;  Ahh, I think I understand what I am doing wrong. By using Java's Swing I am allowing the application to continue in passive rendering, and this is being done in a separate thread. What you described is active rendering, I think? At least, the rendering is done explicitly in a game loop, which is not quite what I have implemented. Thankyou Red Ghost, I think I will go back to the drawing board on my design! :)   