Example #1
0
 public function start()
 {
     $this->console->sendMessage("Preparing to start...");
     $this->getServer()->broadcastMessage("Time up!");
     $players = $this->getServer()->getOnlinePlayers();
     if (count($players) < 8) {
         $this->phase = 0;
         $this->onTimeup();
         $this->console->sendMessage("8 players are needed to start the game.");
         $this->getServer()->broadcastMessage("Players are not enough...");
         return;
     }
     array_shuffle($players);
     array_shuffle($players);
     $this->console->sendMessage("The game will starts with " . count($players) . " players.");
     $names = array();
     if (count($players) < 24) {
         $this->console->sendMessage("All players will join.");
         $this->ingame = $players;
         foreach ($players as $p) {
             $names[] = $p->getName();
         }
     } else {
         $this->console->sendMessage("Only 24 players will join.");
         $this->ingame = $ing = array();
         for ($i = 0; $i < 24; $i++) {
             $ing[i] = $players[i];
             $names[i] = $players[i]->getName();
         }
         $this->console->sendMessage("These players will join:\n" . implode(", ", $names));
     }
     $this->getServer()->broadcastMessage("The game will starts with these players:\n" . implode(", ", $names));
     $this->out = array();
     $this->borderXZ = 30 * 60 + 10;
     $this->getServer()->generateLevel($levName = $this->levName = $this->randomName());
     $lev = $this->lev = $this->getServer()->getLevelByName($levName);
     $this->getServer()->broadcastMessage("Fine. Let's start!");
     foreach ($this->ingame as $ply) {
         $pos = new Position(mt_rand(-600, 600), 128, mt_rand(-600, 600), $levName);
         $ply->teleport($pos);
         $ply->setGamemode(0);
         $ply->setHealth(20);
         $this->getLogger()->info($ply->getName());
     }
     $this->getServer()->getScheduler()->scheduleRepeatingTask(new TickClock(10 * 60, $this), 20, 10 * 60);
     $this->ph1->dst = $this->ingame;
     $this->getServer()->getScheduler()->scheduleRepeatingTask($this->ph1, 10, 10 * 60 * 2);
     $this->getServer()->getScheduler()->scheduleRepeatingTask($this->gameover, 10, 30 * 60 * 2);
     $this->getServer()->getScheduler()->scheduleRepeatingTask($this->shrinkBorder, 10, 10 * 60 * 2);
 }
 /**
  * Shuffle the items in the collection.
  *
  * @return static
  */
 public function shuffle()
 {
     $items = $this->items;
     array_shuffle($items);
     return new static($items);
 }
			</p>
			<ul>
<?php 
        while ($rs->eof == false) {
            $company_no = $rs->fields["company_no"];
            $company_nm = $rs->fields["company_nm"];
            $src = "";
            if (file_exists(C_IMG_PATH . "logo/" . $company_no)) {
                $src = C_IMG_ROOT_URL . "logo/" . $company_no;
            }
            $shuffle[] = "<li><img src=\"" . $src . "\" alt=\"" . f_hsc($company_nm) . "\"></li>";
            $rs->move_next();
        }
        if (count($shuffle) > 0) {
            $shuffle2 = array_rand($shuffle, 38);
            $ret_shuffle = array_shuffle($shuffle2);
            foreach ($ret_shuffle as $key) {
                echo $shuffle[$key];
            }
        }
        ?>
			</ul>
<?php 
    }
    $rs->free_result();
}
?>
		</div>

<?php 
/*********************************************************************/
Example #4
0
 /**
  * 随机打乱数组
  */
 public static function shuffle($array)
 {
     return array_shuffle($array);
 }
Example #5
0
function send_emails(&$input, &$errors, &$success)
{
    require_once './includes/phpmailer/class.phpmailer.php';
    $return_val = true;
    $shuffledArray = array();
    $nonShuffledArray = array();
    foreach ($input['emails'] as $key => $email) {
        $shuffledArray[] = array('email' => $input['emails'][$key], 'name' => $input['names'][$key], 'other' => $input['others'][$key]);
        $nonShuffledArray[] = array('email' => $input['emails'][$key], 'name' => $input['names'][$key], 'other' => $input['others'][$key]);
    }
    for ($i = 0; $i <= 10; $i++) {
        $shuffledArray = array_shuffle($shuffledArray);
    }
    try {
        foreach ($shuffledArray as $key => $data) {
            $mail = new PHPMailer(true);
            $mail->IsSMTP();
            $mail->Host = MAIL_SERVER;
            $mail->SMTPDebug = 0;
            $mail->SMTPAuth = SMTP_AUTH;
            $mail->SMTPSecure = SMTP_SECURE;
            $mail->Port = SMTP_PORT;
            $mail->Username = MAIL_USERNAME;
            $mail->Password = MAIL_PASSWORD;
            $mail->AddReplyTo(FROM_EMAIL, FROM_NAME);
            $mail->SetFrom(FROM_EMAIL, FROM_NAME);
            $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
            $mail->AddAddress($nonShuffledArray[$key]['email'], $nonShuffledArray[$key]['name']);
            $mail->Subject = "Secret Santa Assigned To You: " . $data['name'];
            $messageHtml = "<p>Hi " . $nonShuffledArray[$key]['name'] . ",</p><p>You are assigned to purchase a " . $input['gift_value'] . " dollar or less gift for " . $data['name'] . ". Their email address is: " . $data['email'] . "</p>";
            if (!empty($data['other'])) {
                $messageHtml .= "<p>Some other information: " . $data['other'] . "</p>";
            }
            $messageHtml .= "<p>Have a safe and fun holiday season!</p><p>This Message brought to you via Secret Santa App at <a href='" . CANONICAL_URL . "' title='" . CANONICAL_URL . "'>" . CANONICAL_URL . "</a><p>";
            $mail->MsgHTML($messageHtml);
            $mail->Send();
            $success[] = $data['name'] . " has been assigned to a random person.";
        }
    } catch (Exception $e) {
        return_errors($errors, $input, $e);
        return false;
    }
    return true;
}
Example #6
0
 /**
  * Получить несколько случайных записей из массива с сохранением ключей
  *
  * @param array $data массив с данными
  * @param int $count требуемое число записей из массива
  * @return array|mixed
  */
 function array_random(array $data = array(), $count = 1)
 {
     $flag = array_shuffle($data);
     if ($flag) {
         if ((int) $count > 0) {
             $data = current(array_chunk($data, (int) $count, true));
         }
     } else {
         $data = array();
     }
     return $data;
 }
Example #7
0
function get_rand_words($level = 0)
{
    global $DB;
    $words = array();
    //次数
    $gold_total = rand(3, 7);
    $bigend = 5;
    if ($level >= 200) {
        $bigend = 1;
    } else {
        if ($level >= 100) {
            $bigend = 2;
        } else {
            if ($level >= 50) {
                $bigend = 3;
            } else {
                if ($level >= 30) {
                    $bigend = 4;
                }
            }
        }
    }
    //金币点数值大小
    $gold_points = array();
    for ($i = 0; $i < $gold_total; $i++) {
        //$gold_points[$i] = $u == true ? getRand(5) : rand(1, 5);
        $gold_points[$i] = rand(1, $bigend);
    }
    //所有金子总和
    $total_points1 = array_sum($gold_points);
    //找几个有points的词
    $total_points = 0;
    foreach ($gold_points as $key => $val) {
        $sql = "select * from dig_gold_words where points={$val} order by rand() limit 1";
        $rs = $DB->fetch_arrays($sql);
        if ($rs) {
            $id = $rs[0]['id'];
            $words[$id]['word'] = dealwith_kw($rs[0]['word']);
            $words[$id]['points'] = $rs[0]['points'];
            $words[$id]['dig'] = 0;
            $total_points += $rs[0]['points'];
        }
    }
    //找100-$gold_total 个 points=0的词
    $sql = "select count(id) from dig_gold_words where points='0'";
    $rs = $DB->fetch_arrays($sql);
    //从表1中取点
    $limit = 100 - $gold_total - 20;
    $max = $rs[0][0] - 300;
    $min = 500;
    $begin = rand($min, $max);
    $sql = "select * from dig_gold_words where points='0' limit {$begin}, {$limit}";
    $rs = $DB->fetch_arrays($sql);
    if ($rs && is_array($rs) && count($rs) > 0) {
        foreach ($rs as $key => $val) {
            $words[$val['id']]['word'] = dealwith_kw($val['word']);
            $words[$val['id']]['points'] = 0;
            $words[$val['id']]['dig'] = 0;
        }
    }
    //从表2里去点
    $begin = rand(1, 480);
    $sql = "select * from dig_gold_words_2 limit {$begin}, 20";
    $rs = $DB->fetch_arrays($sql);
    if ($rs && is_array($rs) && count($rs) > 0) {
        foreach ($rs as $key => $val) {
            $words[$val['id']]['word'] = dealwith_kw($val['word']);
            $words[$val['id']]['points'] = 0;
            $words[$val['id']]['dig'] = 0;
        }
    }
    return array('word' => array_shuffle($words), 'total_points' => $total_points);
}