Skip to main content
GameDev.net gamedev.net
🔒 Locked

Waiting for user input in C# GUI program

Started by UmaN Mar 26, 2008 at 3:29 PM 4 replies 4.8k views
Original Post
UmaN
UmaN
Hi. I'm doing a poker game where I have 5 computer players and a human player playing against each other. When it is the human players turn to act I first enable user controls and then I would like to wait for the user to make a choice (by pressing a button - "bet", "call" etc.) and only then should the next computer player be allowed to play. I don't want to add an "infinite" loop that exits when the user has made a choice. Also, I don't want to add a dialog that receives focus because I want it to be like real poker clients and also because I don't think that would be a good solution. The gameflow is like this: playTurn(); And then within playTurn each player is asked to take action like so: actionTaken = player.bet(gameInformation); With only computer players (class ComputerPlayer) there is no problem because they know exactly what to do and return immediately but when a human player is asked to take action (class HumanPlayer) I don't really know what to do. I hope I have explained myself well enough. Any help is appreciated.
TheTroll
TheTroll
It is called an event, might want to look that up.

theTroll
UmaN
UmaN
Yes that's fine. But that is not the problem.
TheTroll
TheTroll
The problem is you are trying to make a procedural system in an event driven environment. If you switch to an event driven system, then this will no longer be a problem.

theTroll
UmaN
UmaN
I can't get my mind around what that would look like in this case.

If you imagine the scenario I explained above, how would it, more or less, play out?
TheTroll
TheTroll
The way I would do it;

Create events for all the actions of the players and the dealer. Table events; Anny, Deal, Bet, Check, Fold, JoinGame, ect. Finally add a Completed Event. Everyone subscribes to the table events so they know what is happening at the table. The person following a player subscribes to that person's Completed event.

So what happens; the Dealer pushes out the Deal event, and that events has a array of structures of the cards dealt out to each player. Then each player does their turn pushing out the bet, check or fold event followed by a Completed event. I am not sure which version on poker you are playing so what happens next depends on the type of game.

But that should give you an idea of an event driven game.

theTroll

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.