예제 #1
0
 /**
  * @test
  */
 public function end_game_result()
 {
     $arenaWidth = 10;
     $arenaHeight = 10;
     $arenaLimits = new Cartesian\Point($arenaWidth, $arenaHeight);
     $scoreStrategy = array('Hit' => '\\Iannsp\\PhpWar\\Game\\Score\\Hit', 'Neibor' => '\\Iannsp\\PhpWar\\Game\\Score\\Neibor');
     $arena = new Iannsp\PhpWar\Arena($arenaLimits, $scoreStrategy);
     $players = array(new Iannsp\PhpWar\Player\P1($arena->getLimits()), new Iannsp\PhpWar\Player\P1($arena->getLimits()));
     $game = new Iannsp\PhpWar\Game($arena, $players);
     foreach ($game as $currentTurn) {
         // Render stuff here.
     }
     $stats = $arena->stats();
     $this->assertArrayHasKey(1, $stats, 'Missing player 1 on status.');
     $this->assertArrayHasKey(0, $stats, 'Missing player 0 on status.');
     $this->assertGreaterThan($stats[0], $stats[1], 'Expected that player 1 wins every time.');
 }
예제 #2
0
파일: playgame.php 프로젝트: iannsp/phpwar
<?php

require 'bootstrap.php';
$scoreStrategy = array('Hit' => '\\Iannsp\\PhpWar\\Game\\Score\\Hit', 'Neibor' => '\\Iannsp\\PhpWar\\Game\\Score\\Neibor');
$arenaLimits = new Iannsp\PhpWar\Geometry\Cartesian\Point(10, 10);
$arena = new Iannsp\PhpWar\Arena($arenaLimits, $scoreStrategy);
$players = array(new Iannsp\PhpWar\Player\P1($arenaLimits), new Iannsp\PhpWar\Player\P1($arenaLimits));
$game = new Iannsp\PhpWar\Game($arena, $players);
$frameRate = 4;
foreach ($game as $currentTurn) {
    print $game->render($frameRate);
}
echo "\n    _____  _    _ _____   __          __\n   |  __ \\| |  | |  __ \\  \\ \\        / /\n   | |__) | |__| | |__) |  \\ \\  /\\  / /_ _ _ __\n   |  ___/|  __  |  ___/    \\ \\/  \\/ / _` | '__|\n   | |    | |  | | |         \\  /\\  / (_| | |\n   |_|    |_|  |_|_|          \\/  \\/ \\__,_|_|\n\n    \nResult\n";
$stats = $arena->stats();
foreach ($stats as $id => $stat) {
    if ($id !== '.') {
        echo "Player {$id} has {$stat} position(s).\n";
    }
}