當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Player::attack方法代碼示例

本文整理匯總了PHP中Player::attack方法的典型用法代碼示例。如果您正苦於以下問題:PHP Player::attack方法的具體用法?PHP Player::attack怎麽用?PHP Player::attack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Player的用法示例。


在下文中一共展示了Player::attack方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: rand

 $player->buy($weapons[$weaponIndex]);
 // buy 0 or 1 armor
 $numArmors = rand(0, 1);
 if ($numArmors == 1) {
     $armorIndex = array_rand($armors, 1);
     $player->buy($armors[$armorIndex]);
 }
 // buy 0, 1 or 2 rings
 $numRings = rand(0, 2);
 for ($i = 0; $i < $numRings; $i++) {
     $ringIndex = array_rand($rings, 1);
     $player->buy($rings[$ringIndex]);
 }
 $playerWins = false;
 while ($boss->getHitpoints() > 0 && $player->getHitpoints() > 0) {
     $player->attack($boss);
     // boss can only attack back if he is alive
     if ($boss->isAlive()) {
         $boss->attack($player);
     }
 }
 if ($player->isAlive()) {
     if (!isset($leastSpent) || $player->getSpentCash() < $leastSpent) {
         $leastSpent = $player->getSpentCash();
         echo 'least spent: ' . $leastSpent . ' for a victory (part 1)' . PHP_EOL;
     }
 } else {
     if (!isset($mostSpent) || $player->getSpentCash() > $mostSpent) {
         $mostSpent = $player->getSpentCash();
         echo 'most spent: ' . $mostSpent . ' for a defeat (part 2)' . PHP_EOL;
     }
開發者ID:hmazter,項目名稱:advent-of-code-solutions,代碼行數:31,代碼來源:day21.php

示例2: getAttack

    {
        // 誰が撃っても威力一緒
        return self::PISTOL_ATK;
    }
}
class Hammer implements WeaponInterface
{
    public function getAttack(Player $player)
    {
        // 一撃でかいけどクリーンヒットしにくい
        $damage_rate = 1 == mt_rand(1, 3) ? 0.2 : mt_rand(100, 250) / 100;
        return $player->status_strength * $damage_rate;
    }
}
$player = new Player('Onizuka');
$player->attack();
$player->attack();
$player->attack();
$player->attack();
$player->attack();
$player->setWeapon(new Knife());
$player->attack();
$player->attack();
$player->attack();
$player->attack();
$player->attack();
$player->setWeapon(new Pistol());
$player->attack();
$player->attack();
$player->attack();
$player->attack();
開發者ID:kawazoe-yusuke,項目名稱:design-pattern,代碼行數:31,代碼來源:strategy_1.php

示例3: Player

            if ($_POST['p2weapon'] == "scissors") {
                $player2 = new Player($_POST['p2name'], $_POST['p2age'], $scissors);
            }
        }
    }
    $player1->save();
    $player2->save();
    var_dump($_SESSION['player_stats']);
    $player1_spot = $_SESSION['player_stats'][1];
    $player2_spot = $_SESSION['player_stats'][2];
    $turn = Player::whoseTurn();
    return $app['twig']->render('play.html.twig', array('player1' => $player1_spot, 'player2' => $player2_spot, 'turn' => $turn));
});
$app->post("/delete", function () use($app) {
    Player::deleteAll();
    return $app['twig']->render('home.html.twig');
});
$app->post("/attack", function () use($app) {
    print_r($_SESSION['player_stats']);
    $whoseturn = Player::whoseTurn();
    $player = Player::decidePlayer();
    $attack = Player::attack();
    return $app['twig']->render('play.html.twig', array('turn' => $whoseturn, 'attack' => $attack));
});
// $app->post("/heal", function() use ($app) {
//     print_r($_SESSION['player_stats']);
//     Player::changeTurn();
//     $whoseturn = Player::playerTurnName();
//     return $app['twig']->render('play.html.twig', array('turn' => $whoseturn));
// });
return $app;
開發者ID:jwuerch,項目名稱:Rock-Paper-Scissors-PHP,代碼行數:31,代碼來源:app.php

示例4: attack

 public function attack($damage)
 {
     return $this->player->attack($damage);
 }
開發者ID:chrisemerson,項目名稱:adventOfCode,代碼行數:4,代碼來源:PlayerDecorator.php


注:本文中的Player::attack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。