/** * This function is extended from the baseoutput class. * It creates and saves the gamefield each cycle as png file to /v1/tmp/png. * * @param GameFieldController $_gameFieldController The gamefieldcontroller which contains the gamefield. * @param int $_numCycles The amount of rounds the game should be played. */ public function output(GameFieldController $_gameFieldController, $_numCycles) { $pngCreator = new PngCreator(); for ($cycle = 0; $cycle < $_numCycles; $cycle++) { // Creates a png for each cycle. $pngCreator->createPng($_gameFieldController->getGameField(), $cycle); $_gameFieldController->run(); } }
/** * This function is extended from the baseoutput class. * It creates and saves the game cycles as a gif file to /v1/tmp/gif. * * @param GameFieldController $_gameFieldController The gamefieldcontroller which contains the gamefield. * @param int $_numCycles The amount of rounds the game should be played. */ public function output(GameFieldController $_gameFieldController, $_numCycles) { $pngCreator = new PngCreator(); $gifCreator = new GifCreator(0, 2, array(-1, -1, -1)); for ($cycle = 0; $cycle < $_numCycles; $cycle++) { // Creates a png for each cycle and adds it to the gif frame. $pngCreator->createPng($_gameFieldController->getGameField(), $cycle); $gifCreator->addFrame(file_get_contents(__DIR__ . "/../../tmp/png/png" . $cycle . ".png"), 50); unlink(__DIR__ . "/../../tmp/png/png" . $cycle . ".png"); $_gameFieldController->run(); } file_put_contents(__DIR__ . "/../../tmp/gif/animation.gif", $gifCreator->getAnimation()); }