// run setup validation if (isset($_POST['test_setup'])) { try { Setup::is_valid_reflection($_POST['setup'], $_POST['reflection']); $return['valid'] = true; } catch (MyException $e) { $return['error'] = 'ERROR: ' . $e->outputMessage(); } echo json_encode($return); exit; } // run setup laser test fire if (isset($_POST['test_fire'])) { try { // returns laser_path and hits arrays $return = Pharaoh::fire_laser($_POST['color'], $_POST['board']); } catch (MyException $e) { $return['error'] = 'ERROR: ' . $e->outputMessage(); } echo json_encode($return); exit; } // run the invites stuff if (isset($_POST['invite'])) { if ('delete' == $_POST['invite']) { // make sure we are one of the two people in the invite if (Game::has_invite($_POST['game_id'], $_SESSION['player_id'])) { if (Game::delete_invite($_POST['game_id'])) { echo 'Invite Deleted'; } else { echo 'ERROR: Invite not deleted';
/** public function get_laser_path * Returns the laser path for the given move index * * @param int optional move history index * @param bool optional return as JSON string * @return array or JSON string laser path */ public function get_laser_path($index = null, $json = false) { call(__METHOD__); call($index); call($json); if (is_null($index)) { $index = count($this->_history) - 1; } $index = (int) $index; $json = (bool) $json; $count = count($this->_history); call($count); call($this->_history[$index]); if (1 > $index || $index > $count - 1) { if ($json) { return '[]'; } return false; } $color = 0 != $index % 2 ? 'silver' : 'red'; call($color); // here we need to do the move, store the board as is // and then fire the laser. // the reason being: if we just fire the laser at the previous board, // if the piece hit was rotated into the beam, it will not display correctly // and if we try and fire the laser at the current board, it will pass through // any hit piece because it's no longer there (unless it's a stacked obelisk, of course) // create a dummy pharaoh class and set the board as it was prior to the laser (-1) $PH = new Pharaoh(); $PH->set_board(expandFEN($this->_history[$index - 1]['board'])); $PH->set_extra_info($this->_extra_info); // do the move, but do not fire the laser, and store the board $pre_board = $PH->do_move($this->_history[$index]['move'], false); // now fire the laser at that board $return = Pharaoh::fire_laser($color, $pre_board, $this->_pharaoh->get_extra_info()); if ($json) { return json_encode($return['laser_path']); } return $return['laser_path']; }