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


PHP Game::play方法代码示例

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


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

示例1: __invoke

 public function __invoke()
 {
     $hitPoints = 103;
     $damagePoints = 9;
     $armourPoints = 2;
     $boss = new Boss($hitPoints, $damagePoints, $armourPoints);
     $game = new Game(new TurnTaker());
     $weapons = $this->getWeaponCollection();
     $armours = $this->getArmourCollection();
     $rings = $this->getRingCollection();
     $lowestCost = null;
     foreach ($weapons as $w => $weapon) {
         foreach ($armours as $a => $armour) {
             $permutations = $this->getRingPermutations(array_keys($rings));
             foreach ($permutations as $permutation) {
                 $boss->resurrect($hitPoints);
                 $r1 = $permutation[0];
                 $r2 = $permutation[1];
                 $player = new Player($weapon, $armour, $rings[$r1], $rings[$r2], 100);
                 /**
                  * @var $winner PlayerInterface
                  */
                 $winner = $game->play($player, $boss);
                 if (!$winner->isBoss()) {
                     $cost = $weapon->getCost() + $armour->getCost() + $rings[$r1]->getCost() + $rings[$r2]->getCost();
                     if (!$lowestCost || $cost < $lowestCost) {
                         $lowestCost = $cost;
                     }
                 }
             }
         }
     }
     $this->write("Lowest amount of gold to win: " . $lowestCost);
 }
开发者ID:garethellis36,项目名称:advent-of-code-2015,代码行数:34,代码来源:Puzzle1.php

示例2: winner

    }
    //check if there is a winner
    private function winner($token)
    {
        for ($row = 0; $row < 3; $row++) {
            if ($this->position[3 * $row] == $token && $this->position[3 * $row + 1] == $token && $this->position[3 * $row + 2] == $token) {
                return true;
            }
        }
        for ($col = 0; $col < 3; $col++) {
            if ($this->position[$col] == $token && $this->position[$col + 3] == $token && $this->position[$col + 6] == $token) {
                return true;
            }
        }
        if ($this->position[0] == $token && $this->position[4] == $token && $this->position[8] == $token) {
            return true;
        } else {
            if ($this->position[2] == $token && $this->position[4] == $token && $this->position[6] == $token) {
                return true;
            }
        }
        return false;
    }
}
// Initialize the board if there is no previous state from the url
$position = isset($_GET['board']) ? $_GET['board'] : null;
$game = new Game($position);
$game->play();
?>
</body>
</html>
开发者ID:eigenket1,项目名称:4711,代码行数:31,代码来源:index.php

示例3: testInvalidInputSource

 public function testInvalidInputSource()
 {
     $game = new Game(new Board());
     $this->setExpectedException('RuntimeException');
     $game->play(__DIR__ . '/resources/file_not_found.txt');
 }
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:6,代码来源:MineSweeperTest.php

示例4: Game

        //put the computer's hand into session array
        Session::put('result', $result);
        //put the result of the match into session array
        $game->setscore($user->data()->id, $user->data()->hiscore);
        //set the score for the user, and pass in id and hiscore in case of id
        Redirect::to('index.php');
        //redirect to index (refresh)
    }
} else {
    require_once 'includes/templates/landing.php';
    //require landing page template
    if (Input::exists()) {
        //if input exists
        $game = new Game();
        //instantiate hand
        $game->randomHand();
        //generate computer's random hand
        $game->play(Input::get('hand'));
        //play the player's hand from input
        $computerHand = $game->computerHand();
        //set the computer's hand
        $result = $game->result();
        //set the result
        Session::put('computerHand', $computerHand);
        //put the computer's hand into session array
        Session::put('result', $result);
        //put the result of the match into session array
        Redirect::to('index.php');
        //redirect to index (refresh)
    }
}
开发者ID:rafalstapinski,项目名称:rps,代码行数:31,代码来源:index.php

示例5: array

<?php

require_once "Game.php";
require_once "Deck.php";
$numGames = 100000;
$results = array();
$winningStates = array();
for ($i = 0; $i < $numGames; ++$i) {
    if ($i % 10000 == 0) {
        echo "{$i}...";
    }
    $d = new Deck();
    $d->shuffle();
    $g = new Game($d);
    $turns = $g->play();
    $results[] = $turns;
    if ($turns == 1) {
        echo "YOU WON!\n";
        $winningStates[] = $g->boardToString();
    }
}
echo "Final results:\n";
foreach ($results as $result) {
    echo "{$result},";
}
echo "\n";
echo "Average: " . array_sum($results) / count($results) . "\n";
var_dump($winningStates);
开发者ID:awshepard,项目名称:nextdoor,代码行数:28,代码来源:nextdoor.php

示例6: array

<?php

require 'Card.php';
require 'Deck.php';
require 'Player.php';
require 'Game.php';
$players = array('John', 'Kaley', 'Delan', 'Sam');
$game = new Game($players, 5);
echo $game->play();
开发者ID:sameg14,项目名称:php-mastery-code,代码行数:9,代码来源:index.php


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