/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     //для отображения всех ходов
     $steps = new Gamestep();
     $userStep = new Gamestep();
     if (isset($_POST['Gamestep'])) {
         $userStep->attributes = $_POST['Gamestep'];
         $cityName = trim(mb_strtolower($userStep->cityName));
         //если город, ведденный пользователем, отсутствует в нашей БД, сохраняем
         //при условии, что в Википедии существует страница, в которой сказано о существовании такого города
         if ($this->ifCityUndefined($userStep, $cityName)) {
             $this->renderContent($userStep, $steps);
             return;
         }
         $lastStepNumber = Gamestep::model()->getLastStepNumber() + 1;
         //проверяем ход пользователя
         if (!$this->checkAndSaveUserStep($userStep, $cityName, $lastStepNumber)) {
             $this->renderContent($userStep, $steps);
             return;
         }
         //получаем ответ компьютера
         $this->handleComputerStep($lastStepNumber);
     }
     $this->renderContent($userStep, $steps);
 }
Пример #2
0
 public static function checkLastAndFirstLetter($word)
 {
     $lastLetter = Gamestep::model()->getLastLetter();
     $firstLetter = mb_substr($word, 0, 1);
     if ($firstLetter !== $lastLetter) {
         return false;
     }
     return true;
 }
Пример #3
0
 public static function checkUserStep($userStep)
 {
     $textError = self::ERROR_SUCCESS;
     if (!LetterUtils::checkLastAndFirstLetter($userStep)) {
         $textError = self::ERROR_CITY_LETTER . " '" . Gamestep::model()->getLastLetter() . "'";
     }
     if (Gamestep::model()->checkCityAlreadyExist($userStep)) {
         $textError = self::ERROR_CITY_USED;
     }
     return $textError;
 }
Пример #4
0
<?php

/* @var $this GamestepController */
/* @var $model Gamestep */
?>

        <div class="span6">
            <?php 
$this->renderPartial('_form', array('model' => $model));
?>
        </div>

        <div class="span6">
            <?php 
if (Gamestep::model()->getLastStepNumber() > 0) {
    ?>
                <?php 
    $this->widget('bootstrap.widgets.TbGridView', array('dataProvider' => $step->search(), 'template' => '{items}{pager}', 'columns' => array(array('name' => 'Номер хода', 'value' => '$data->stepNumber'), array('name' => 'Города', 'value' => '$data->city->name'))));
    ?>
            <?php 
}
?>
        </div>