Ejemplo n.º 1
0
function addAnimalToMap(World $world, $animal)
{
    for ($i = 0; $i < 10; $i++) {
        $tempX = rand(1, $world->getWidth());
        $tempY = rand(1, $world->getHeight());
        if (!$world->getCellContents($tempX, $tempY)) {
            $world->addAnimal(new $animal($tempX, $tempY));
            return;
        }
    }
}
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function runTheWorld()
 {
     $iterations = $this->iterations;
     $input = array_shift($iterations);
     $cellManager = new CellManager(5);
     $world = new World($cellManager);
     foreach ($iterations as $expected) {
         $actual = $world->iteration($this->cleanArray($input));
         $this->assertEquals($this->cleanArray($expected), $actual);
         $input = $expected;
     }
 }
Ejemplo n.º 3
0
 /**
  * Return array for XML output.
  *
  * @return array
  */
 private function getArray()
 {
     $array = ['world' => ['cells' => $this->world->getCells(), 'iterations' => $this->world->getIterations()], 'organisms' => []];
     foreach ($this->world->getLife() as $life) {
         foreach ($life as $organism) {
             if ($organism->isDead()) {
                 continue;
             }
             array_push($array['organisms'], ['x_pos' => $organism->x, 'y_pos' => $organism->y, 'species' => $organism->species]);
         }
     }
     return $array;
 }
Ejemplo n.º 4
0
function updates()
{
    header('Content-Type: application/json; charset=utf-8');
    $query_count = params("queries");
    if ($query_count < 1) {
        $query_count = 1;
    }
    if ($query_count > 500) {
        $query_count = 500;
    }
    $worlds = array();
    for ($i = 0; $i < $query_count; $i++) {
        $id = mt_rand(1, 10000);
        $world = World::find($id);
        $world->randomnumber = mt_rand(1, 10000);
        $world->save();
        $worlds[] = $world->to_array();
    }
    return json($worlds);
}
Ejemplo n.º 5
0
<?php

namespace Frork;

require_once 'exception.inc.php';
require_once 'autoloader.inc.php';
require_once 'world.inc.php';
World::$BASE_PATH = realpath(__DIR__ . '/..');
AutoLoader::initialise(World::$BASE_PATH);
AutoLoader::addNamespaceMapping('/inc/api');
World::$ENV = 'run';
World::$TPL = new MVC\View\HandlerFactory(World::$BASE_PATH . '/inc/tpl');
Ejemplo n.º 6
0
<?php

require_once '../lib/World.php';
require_once '../lib/Util.php';
require_once '../vendor/submodule-test-01/Submodule01.php';
require_once '../vendor/submodule-test-02/Submodule02.php';
$world = new World();
$s1 = new Submodule01();
$s2 = new Submodule02();
?>
<!DOCTYPE html>
<html>
	<head>
		<title>This is a Test</title>
		<script data-main="scripts/main" src="scripts/require.js"></script>
	</head>
	<body>
		<h1><?php 
print $world->getMessage();
?>
</h1>
		<h2 id="clickMe">Click here for a message from a Require JS module.</h2>
		<hr />
		<h1>Submodule Info:</h1>
		<ol>
			<li>01 Version: <?php 
print $s1->getVersion();
?>
</li>
			<li>02 Version: <?php 
print $s2->getVersion();
Ejemplo n.º 7
0
            $consonant = rand(0, count($this->consonants) - 1);
            $word .= $this->vowels[$vowel] . $this->consonants[$consonant];
        }
        return mb_convert_case($word, MB_CASE_TITLE, "UTF-8");
    }
}
class World
{
    public $name = '';
    public $day = 1;
    public $wordBuilder;
    public function __construct()
    {
    }
    public function Generate()
    {
        $this->wordBuilder = new WordBuilder();
        $this->name = $this->wordBuilder->getWorldName();
        $this->day = 1;
    }
}
$world = new World();
$world->Generate();
$tales_list = ['Отваге', "Слабоумии", "Могуществе", "Сундуках", "Ракушках", "Бамбуке", "Героях", "Странствиях", "Палках", "Собаках", "Сладких рулетах", "Камнях", "Страсти", "Жадности", "Самопожертвовании", "Отчаянии", "Верности", "Долге", "Коварстве"];
$tales = [];
$tales[0] = $tales_list[rand(0, count($tales_list) - 1)];
$tales[1] = $tales_list[rand(0, count($tales_list) - 1)];
$incredible_list = ['Невероятные', "Невозможные", "Былинные", "Древние"];
$stories_list = ['истории', "рассказы", "былины", "повести"];
$stories = $stories_list[rand(0, count($stories_list) - 1)];
$incredible = $incredible_list[rand(0, count($incredible_list) - 1)];
Ejemplo n.º 8
0
//
// Set content type
header("Content-type: application/json");
// Database connection
// http://www.php.net/manual/en/ref.pdo-mysql.php
// $pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass');
# inclue the ActiveRecord library
require_once 'php-activerecord/ActiveRecord.php';
ActiveRecord\Config::initialize(function ($cfg) {
    $cfg->set_model_directory('models');
    $cfg->set_connections(array('development' => 'mysql://*****:*****@localhost/hello_world'));
});
// Read number of queries to run from URL parameter
$query_count = 1;
if (!empty($_GET)) {
    $query_count = $_GET["queries"];
}
// Create an array with the response string.
$arr = array();
// For each query, store the result set values in the response array
for ($i = 0; $i < $query_count; $i++) {
    // Choose a random row
    // http://www.php.net/mt_rand
    $id = mt_rand(1, 10000);
    $world = World::find_by_id($id);
    // Store result in array.
    $arr[] = $world->to_json();
}
// Use the PHP standard JSON encoder.
// http://www.php.net/manual/en/function.json-encode.php
echo json_encode($arr);
Ejemplo n.º 9
0
 * This is an example of Convaw's Game of Life at PHP (https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)
 *
 * There is no need for use some framework.
 * This example shows analytics, OOP, PHP, programming and English skills.
 *
 * For this example index is shortened (functions, css, php, html). In real situation it will be in separated files.
 *
 * For website example look at http://www.tartaletka.cz/ (my girlfriend's website created by me).
 */
require_once 'lib/Writer/IWriter.php';
require_once 'lib/Writer/XML.php';
function __autoload($class)
{
    require_once 'lib/' . $class . '.php';
}
$world = new World(new XML());
$life = $world->simulate();
?>

<style type="text/css">
	table {
		border-collapse: collapse;
	}

	table td {
		width: 10px;
		height: 10px;
		text-align: center;
		border: 1px solid #eeeeee;
	}
</style>
Ejemplo n.º 10
0
 public static function test()
 {
     World::who() . PHP_EOL;
     static::who() . PHP_EOL;
 }
Ejemplo n.º 11
0
        $worlds[] = $world;
    }
    return response()->json($worlds);
});
$app->get("updates", function (Request $request) {
    $query_count = $request->input("queries");
    if ($query_count < 1) {
        $query_count = 1;
    }
    if ($query_count > 500) {
        $query_count = 500;
    }
    $worlds = array();
    for ($i = 0; $i < $query_count; $i++) {
        $id = mt_rand(1, 10000);
        $world = World::find($id);
        $world->randomNumber = mt_rand(1, 10000);
        $world->save();
        $worlds[] = $world;
    }
    return response()->json($worlds);
});
$app->get("fortune", function () use($app) {
    $fortunes = Fortune::all()->toArray();
    $new_fortune = array("id" => 0, "message" => "Additional fortune added at request time.");
    $fortunes[] = $new_fortune;
    $fortunes = array_sort($fortunes, function ($value) {
        return $value["message"];
    });
    return view("fortune", ["fortunes" => $fortunes]);
});
Ejemplo n.º 12
0
<?php

namespace Kitsune\ClubPenguin;

date_default_timezone_set("America/Los_Angeles");
error_reporting(E_ALL ^ E_STRICT);
spl_autoload_register(function ($path) {
    $realPath = str_replace("\\", "/", $path) . ".php";
    $includeSuccess = (include_once $realPath);
    if (!$includeSuccess) {
        echo "Unable to load {$realPath}\n";
    }
});
$cp = new World();
$cp->listen(0, 9875);
while (true) {
    $cp->acceptClients();
}