views:

454

answers:

2

I'm trying to figure out the best solution to create a "game-round" timer in Ruby/Rails. Right now I'm just jotting notes, but in theory I'd like to set a 30 second timer on each round of game activity. Once the timer hits 0, the users turn is over.

On Ruby's end, I know I can accomplish this with a while loop and sleep(30), or some combination of the Timer class.

However, i'm getting stumped trying to design the best way to show the user their time left on the clock. Use Ajax? periodiocally_call_remote? What should I query for?

Just thinking out loud, figured I'd ask the crowd.

A: 

actually i would go with periodiocally_call_remote, i dont know if its still cause some issue with internet explorer 6 or not, good luck

Waheedi
+1  A: 

Build a javascript timer. When the countdown is over, call your end_turn() method.

I wouldn't want to hit the server every second just for a countdown. You can do it all client-side and only hit the server when the turn is over (or a move is made)

wesgarrison
Good Suggestion, that's what i was worried about... polling too much. But keeping it completely client side and running a method at the end of the timer should work fine. I'll give it a shot.
Nick L