当前位置: 首页>>代码示例>>PHP>>正文


PHP Setup::convert_to_1方法代码示例

本文整理汇总了PHP中Setup::convert_to_1方法的典型用法代码示例。如果您正苦于以下问题:PHP Setup::convert_to_1方法的具体用法?PHP Setup::convert_to_1怎么用?PHP Setup::convert_to_1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Setup的用法示例。


在下文中一共展示了Setup::convert_to_1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: invite

 /** static public function invite
  *		Creates the game from _POST data
  *
  * @param void
  * @action creates an invite
  * @return int game id
  */
 public static function invite()
 {
     call(__METHOD__);
     call($_POST);
     $Mysql = Mysql::get_instance();
     // DON'T sanitize the data
     // it gets sani'd in the MySQL->insert method
     $_P = $_POST;
     // translate (filter/sanitize) the data
     $_P['white_id'] = (int) $_SESSION['player_id'];
     $_P['black_id'] = (int) $_P['opponent'];
     $_P['setup_id'] = (int) $_P['setup'];
     $_P['laser_battle'] = is_checked($_P['laser_battle_box']);
     $_P['battle_front_only'] = is_checked($_P['battle_front_only']);
     $_P['battle_hit_self'] = is_checked($_P['battle_hit_self']);
     $_P['move_sphynx'] = is_checked($_P['move_sphynx']);
     call($_P);
     // grab the setup
     $query = "\n\t\t\tSELECT setup_id\n\t\t\tFROM " . Setup::SETUP_TABLE . "\n\t\t";
     $setup_ids = $Mysql->fetch_value_array($query);
     call($setup_ids);
     // check for random setup
     if (0 == $_P['setup_id']) {
         shuffle($setup_ids);
         shuffle($setup_ids);
         $_P['setup_id'] = (int) reset($setup_ids);
         sort($setup_ids);
     }
     // make sure the setup id is valid
     if (!in_array($_P['setup_id'], $setup_ids)) {
         throw new MyException(__METHOD__ . ': Setup is not valid');
     }
     $query = "\n\t\t\tSELECT board\n\t\t\tFROM " . Setup::SETUP_TABLE . "\n\t\t\tWHERE setup_id = '{$_P['setup_id']}'\n\t\t";
     $setup = $Mysql->fetch_value($query);
     // laser battle cleanup
     // only run this if the laser battle box was open
     if ($_P['laser_battle']) {
         ifer($_P['battle_dead'], 1, false);
         ifer($_P['battle_immune'], 1);
         // we can only hit ourselves in the sides or back, never front
         if ($_P['battle_front_only']) {
             $_P['battle_hit_self'] = false;
         }
         $extra_info = array('battle_dead' => (int) max((int) $_P['battle_dead'], 1), 'battle_immune' => (int) max((int) $_P['battle_immune'], 0), 'battle_front_only' => (bool) $_P['battle_front_only'], 'battle_hit_self' => (bool) $_P['battle_hit_self']);
     }
     $extra_info['white_color'] = $_P['color'];
     $extra_info['move_sphynx'] = $_P['move_sphynx'];
     $setup = expandFEN($setup);
     try {
         if (is_checked($_P['convert_to_1']) || is_checked($_P['rand_convert_to_1'])) {
             $setup = Setup::convert_to_1($setup);
         } elseif (is_checked($_P['convert_to_2']) || is_checked($_P['rand_convert_to_2'])) {
             $setup = Setup::convert_to_2($setup);
         }
     } catch (MyException $e) {
         throw $e;
     }
     $extra_info['invite_setup'] = packFEN($setup);
     call($extra_info);
     $diff = array_compare($extra_info, self::$_EXTRA_INFO_DEFAULTS);
     $extra_info = $diff[0];
     ksort($extra_info);
     call($extra_info);
     if (!empty($extra_info)) {
         $_P['extra_info'] = serialize($extra_info);
     }
     // create the game
     $required = array('white_id', 'setup_id');
     $key_list = array_merge($required, array('black_id', 'extra_info'));
     try {
         $_DATA = array_clean($_P, $key_list, $required);
     } catch (MyException $e) {
         throw $e;
     }
     $_DATA['state'] = 'Waiting';
     $_DATA['create_date '] = 'NOW( )';
     // note the trailing space in the field name, this is not a typo
     $_DATA['modify_date '] = 'NOW( )';
     // note the trailing space in the field name, this is not a typo
     $insert_id = $Mysql->insert(self::GAME_TABLE, $_DATA);
     if (empty($insert_id)) {
         throw new MyException(__METHOD__ . ': Invite could not be created');
     }
     // send the email
     if ($_DATA['black_id']) {
         Email::send('invite', $_DATA['black_id'], array('opponent' => $GLOBALS['_PLAYERS'][$_DATA['white_id']], 'page' => 'invite.php'));
     }
     return $insert_id;
 }
开发者ID:benjamw,项目名称:pharaoh,代码行数:96,代码来源:game.class.php


注:本文中的Setup::convert_to_1方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。