demos/hangman/protected/controllers/GameController.php
public function actionPlay()
	{
		static $levels=array(
			'10'=>'Easy game; you are allowed 10 misses.',
			'5'=>'Medium game; you are allowed 5 misses.',
			'3'=>'Hard game; you are allowed 3 misses.',
		);

		// if a difficulty level is correctly chosen
		if(isset($_POST['level']) && isset($levels[$_POST['level']]))
		{
			$this->word=$this->generateWord();
			$this->guessWord=str_repeat('_',strlen($this->word));
			$this->level=$_POST['level'];
			$this->misses=0;
			$this->setPageState('guessed',null);
			// show the guess page
			$this->render('guess');
		}
		else
		{
			$params=array(
				'levels'=>$levels,
				// if this is a POST request, it means the level is not chosen
				'error'=>Yii::app()->request->isPostRequest,
			);
			// show the difficulty level page
			$this->render('play',$params);
		}
	}
public function actionPlay()
	{
		static $levels=array(
			'10'=>'Easy game; you are allowed 10 misses.',
			'5'=>'Medium game; you are allowed 5 misses.',
			'3'=>'Hard game; you are allowed 3 misses.',
		);

		// if a difficulty level is correctly chosen
		if(isset($_POST['level']) && isset($levels[$_POST['level']]))
		{
			$this->word=$this->generateWord();
			$this->guessWord=str_repeat('_',strlen($this->word));
			$this->level=$_POST['level'];
			$this->misses=0;
			$this->setPageState('guessed',null);
			// show the guess page
			$this->render('guess');
		}
		else
		{
			$params=array(
				'levels'=>$levels,
				// if this is a POST request, it means the level is not chosen
				'error'=>Yii::app()->request->isPostRequest,
			);
			// show the difficulty level page
			$this->render('play',$params);
		}
	}
public function actionPlay ( ) { static $ levels = array ( '10' => 'Easy game; you are allowed 10 misses.' , '5' => 'Medium game; you are allowed 5 misses.' , '3' => 'Hard game; you are allowed 3 misses.' , ) ; // if a difficulty level is correctly chosen if ( isset ( $ _POST [ 'level' ] ) && isset ( $ levels [ $ _POST [ 'level' ] ] ) ) { $ this -> word = $ this -> generateWord ( ) ; $ this -> guessWord = str_repeat ( '_' , strlen ( $ this -> word ) ) ; $ this -> level = $ _POST [ 'level' ] ; $ this -> misses = 0 ; $ this -> setPageState ( 'guessed' , null ) ; // show the guess page $ this -> render ( 'guess' ) ; } else { $ params = array ( 'levels' => $ levels , // if this is a POST request, it means the level is not chosen 'error' => Yii :: app ( ) -> request -> isPostRequest , ) ; // show the difficulty level page $ this -> render ( 'play' , $ params ) ; } }
The 'play' action.
In this action, users are asked to choose a difficulty level
of the game.
The play action . In this action users are asked to choose a difficulty level of the game .