2011-06-22 13 views
0

私は連続した質問からなる単純なゲームに取り組んでいます.30の質問の終わりに、ページは別のページにリダイレクトされます(プレイアクションから質問コントローラのアクションを終了するまで)。私はjavascriptでカウントダウンタイマーを作成するのが難しいです(合計ゲームプレイ時間が240秒に制限され、カウントダウンがプレーヤーに表示されます)。カウンターの値をにすると、連続した回答の間にカウントダウンが続きます投稿に 。 (ゲームが始まると240からカウントダウンを開始し、最初の質問に回答して投稿すると2番目の質問が表示され、カウントダウンタイマーは240 - (最初の質問に費やされた時間など)続きます)Zend Countdown Timer

public function playAction() { 
    $sess = new Zend_Session_Namespace("mysession"); 

    $qlist = $sess->qlist; 
    $qindex = $sess->currentQuestion; 
    $form = new Application_Form_QuestionForm(); 

    if ($this->getRequest()->isPost()) { 
     $formData = $this->getRequest()->getPost(); 
     if ($form->isValid($formData)) { 
      $ans = $form->getValue('Answer'); 
      $uid = Zend_Auth::getInstance()->getIdentity()->id; 
      $qid = $qlist[$qindex]['id']; 
      $qtype = $qlist[$qindex]['type']; 
      $model = $this->_getUserQuestionModel(); 

      $model->addMe($uid, $qid, $qtype, $ans); 
      $qindex++; 
      $sess->currentQuestion = $qindex; 
     } else { 
      $form->populate($formData); 
     } 
    } 
    if ($qindex > 29) { // all questions were asked 
     $this->_helper->redirector('finish'); 
    } 
    $this->view->form = $form; 
    $this->view->qname = "Question " . ($qindex + 1) . ": " . $qlist[$qindex]['verb'] . " ---> " . $qlist[$qindex]['passive']; 
} 

おかげで、

答えて

0

あなたがPHPで値質問でページを生成する代わりに、ハードの240コード化されたときにあなたが答えを提出したときに(秒経過)タイマー値をエコー提出したことがありますか?

使用してjQueryのJavaScriptライブラリ

$('#myform').bind('submit', function() 
{ 

var timer = $('#timer').val() 

$('#myform').append('<input type="hidden" value="'+ timer +'" name="timer" />'); 

});