views:

124

answers:

3

Say I have simple program that emulates a board game with a number of players who take turns rolling dice to move across a board. The players can be human or computer.
If this was a command-line style game, I could simply make a loop to iterate over the players which would call the diceRoll function for that player.

If the player is a computer player, diceRoll simply tells the computer to roll the dice.
If the player is a human, the diceRoll will wait until a user inputs the roll command and then continues.

How can I transfer this idea to a graphic design? I don't think it makes sense to continuously check to see if the roll button has been pressed. I am working with actionscript 2, but ideas can be in whatever language you want. I'd just like some opinions on the best way to design this. I don't suppose there's some sort of 'waitForButtonPress' function that I don't know about?

A: 

Might want to look into events in actionscript 2:

http://www.bigroom.co.uk/blog/events-in-actionscript-2

Gurdas Nijor
A: 

depending on the game if you have N turns and every other turn is the humans turn then you could simply call a getUserResponse() from within the loop using if elses..

for i to N
if(i%2==0)
getUserRoll()
else
getComputerRoll()

and if there's any contraints check them in the if conditon.

Jreeter
That won't really work since there could be any number of human or computer players in any order. And my main concern is how to wait for the user button press inside the loop or produce a similar workflow.
Everett
Ahh yes. The idea for me would be to put the process in a thread and check a flag linked to the button, something simple like a bool flag. Not sure if this is possible with action script.
Jreeter
A: 

I think I've found a solution that I like. The main game class will have a nextTurn function like so:

nextTurn() {
   bool guiSet = false
   while (guiSet = false) {
      //Get the next player
      if (next player is human) {
         //enable the gui (ie. the 'Roll Dice' button)
         guiSet = true
      } else {
         //The player is a computer
         //Have the computer roll the dice and make any necessary decisions
      }
   }
}

When a human player is finished his turn, a call will be made to nextTurn to continue the game play. When a computer finishes a turn, the flow is still in the while loop so the game will continue.

Everett