makeGameTable(); $this->setMessages(array()); $this->setTime(0); } else { global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $g_t_d = unserialize($typeData['data']); if ( $g_t_d ) { $this->setGameTable($g_t_d); //$this->makeGameTable(); } else { $this->makeGameTable(); } $this->setRoboPosition($typeData['robo']); $this->setFriendPosition($typeData['friend']); $this->setTableWidth($typeData['width']); $this->setTableHeight($typeData['height']); $this->setUseTools(unserialize($typeData['tools'])); $this->setMessages(unserialize($typeData['messages'])); $this->setTime($typeData['time']); //$this->setUseMirrors(true);//$typeData['mirrors']); } } protected function setGameData($d) { $this->exerciseData = $d; } public function getGameData() { return $this->exerciseData; } function setGameTable($d) { $this->gameTable = $d; } public function getGameTable() { return $this->gameTable; } function setTableHeight($d) { $this->tableHeight = $d; } public function getTableHeight() { return $this->tableHeight; } function setTableWidth($d) { $this->tableWidth = $d; } public function getTableWidth() { return $this->tableWidth; } function setRoboPosition($d) { $this->roboPosition = $d; } public function getRoboPosition() { return $this->roboPosition; } function setFriendPosition($d) { $this->friendPosition = $d; } public function getFriendPosition() { return $this->friendPosition; } function setUseTools($d) { $this->useTools = $d; } public function getUseTools() { return $this->useTools; } protected function setMessages($d) { $this->messages = $d; } public function getMessages() { return $this->messages; } protected function setTime($d) { $this->time = $d; } public function getTime() { return $this->time; } public function getActor() { return $this->actor; } public function getShowGameTime() { return true; } protected function makeGameTable() { $g_r = array(); for ( $j=0; $j<$this->getTableWidth(); $j++ ) { $g_r []= 'empty'; } $g_t = array(); for ( $i=0; $i<$this->getTableHeight(); $i++ ) { $g_t []= $g_r; } $this->setGameTable($g_t); } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO psyhvel_laser (resourceID, data) values (".$this->getResourceID().", '".$xml['data']."')"); if ($res) { $_SESSION['krihvel_notice'] = "\"".gettext("Laser")."\" ".gettext("has been imported successfully!"); } else { $_SESSION['krihvel_notice'] = gettext("Upload failed! Zip file was corrupted!"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } public function makeXML() { $xml = 'getGameData().']]>\n'; return $xml; } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionSave() { $mode = "view"; if ($this->getResourceID() == "new"){ $mode = "compile"; } $this->updateData($_POST); $this->save(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => $mode); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionCopy() { global $kdb; $this->updateData($_POST); $rid = $this->getResourceID(); parent::copy(); if ($this->getResourceID() != $rid){ $res = $kdb->query("INSERT INTO psyhvel_laser (resourceID, data) values (".$this->getResourceID().", '".$this->getGameData()."')"); if ($res) { $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Laser")."\""; } else { $_SESSION['krihvel_notice'] = gettext("Making copy failed"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } protected function save() { global $kdb; $rid = $this->getResourceID(); parent::save(); if ($rid == "new" || $this->getResourceID() != $rid){ $kdb->query("INSERT INTO psyhvel_laser (resourceID, data) values (".$this->getResourceID().", '".$this->getGameData()."')"); } } public function saveCompiledGame() { $res = $this->kdb->query("UPDATE psyhvel_laser SET data='".serialize($this->getGameTable())."', robo='".$this->getRoboPosition()."', friend='".$this->getFriendPosition()."', width='".$this->getTableWidth()."', height='".$this->getTableHeight()."', tools='".serialize($this->getUseTools())."' WHERE resourceID=".$this->getResourceID()); if ($res) { return gettext("Saved"); } return gettext("Problem"); } } ?>