Example #1
0
/**
 * It puts a Tree element into the world. It adds it in the hashmap of static elements and in the world array
 */
function addTree()
{
    if (!isFull()) {
        $tree = new Tree();
        $row = rand(0, getSizeWorld()['row'] - 1);
        $col = rand(0, getSizeWorld()['col'] - 1);
        while (!putElement($tree, $row, $col)) {
            $row = rand(0, getSizeWorld()['row'] - 1);
            $col = rand(0, getSizeWorld()['col'] - 1);
        }
        $tree->setPosition(array($row, $col));
        addStatic($tree);
        writeFileCSV('Log', array(getTime(), 'New element', get_class($tree), $tree->getId(), '[ ' . $tree->getPosition()[0] . ' - ' . $tree->getPosition()[1] . ' ]', '', '', ''));
    } else {
        writeFileCSV('Log', array(getTime(), 'World is full! It can\'t put a tree', '', '', '', '', '', ''));
    }
}
 if ($updateFlg && REQUEST_METHOD == 'GET') {
     getRegisteredStaticData($id, $caption, $text);
 }
 $validationError = false;
 $addSuccess = false;
 if (REQUEST_METHOD == 'POST') {
     if ($caption == '') {
         $validationErrorMessages = 'caption:captionは必ず入力してください';
         $validationError = true;
     }
     // 入力チェックエラーがなければ登録処理を行う
     if (!$validationError) {
         if ($updateFlg) {
             $addSuccess = editStatic($id, $caption, $text);
         } else {
             $addSuccess = addStatic($caption, $text);
         }
     }
 }
 // 入力チェックがあれば。もしくは登録失敗したら
 if ($validationError || !$addSuccess) {
     // 失敗したら入力内容を表示
     $aft = [$caption, $text];
     $body .= staticInputHtml($aft);
     if ($updateFlg) {
         $globalFormAction = WEB_ROOT . '/static_add?id=' . $id;
     } else {
         $globalFormAction = WEB_ROOT . '/static_add';
     }
     $globalFormMethod = 'POST';
 } else {