当前位置: 首页>>代码示例>>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;未经允许,请勿转载。