Exemplo n.º 1
0
 function testSave()
 {
     $table = new FoosTable(dirname(__FILE__) . '/testData/');
     $table->loadCurrentStatus();
     $table->calculateScore();
     $table->saveToFile('games2.json');
     $file = file_get_contents(dirname(__FILE__) . '/testData/games.json');
     $file2 = file_get_contents(dirname(__FILE__) . '/testData/games2.json');
     $this->assertEqual($file, $file2);
 }
Exemplo n.º 2
0
<?php

//** Model **//
require_once 'foos.class.php';
//** Constants **//
$workingPath = '/userhome/marek/foos/';
//** Controller **//
// Delete
if (isset($_GET['delete'])) {
    $timestamp = $_GET['delete'] * 1;
    $tmpTable = new FoosTable($workingPath);
    $tmpTable->loadCurrentStatus();
    $tmpTable->deleteMatch($timestamp);
    $tmpTable->saveToFile();
    // Remove ?delete=xxx part from URL
    header('Location: foos.php');
    die;
}
// Current data
$table = new FoosTable($workingPath);
$maxGamesInGraph = 50;
$table->setLogMaxSize($maxGamesInGraph);
$table->loadCurrentStatus();
$table->calculateScore();
// Table with data 48h old (to display changes)
$tableOld = new FoosTable($workingPath);
$tableOld->loadStatusForTime(time() - 48 * 60 * 60);
$tableOld->calculateScore();
//** View **//
?>
<!doctype html>
Exemplo n.º 3
0
    $player4 = $table->getPlayerByName($toks[4]);
    $team2 = new FoosTeam($player3, $player4);
    $player1Old = $tableOld->getPlayerByName($toks[0]);
    $player2Old = $tableOld->getPlayerByName($toks[1]);
    $player3Old = $tableOld->getPlayerByName($toks[3]);
    $player4Old = $tableOld->getPlayerByName($toks[4]);
    $tableOld->sortPlayers();
    $match = new FoosMatch($team1, $toks[2], $team2, $toks[5]);
    $table->addMatch($match);
    echo "Game " . $table->getNumberOfMatches() . ": " . $match->getPlayer1()->getName() . " beat " . $match->getPlayer2()->getName() . "\n";
    $table->calculateScore();
    echo $player1->getName() . ' => ' . 'from #' . $tableOld->getPositionOfPlayer($toks[0]) . " (" . $player1Old->getRoundedStrength() . ") " . "to #" . $table->getPositionOfPlayer($toks[0]) . " (" . $player1->getRoundedStrength() . ")\n";
    echo $player2->getName() . ' => ' . 'from #' . $tableOld->getPositionOfPlayer($toks[1]) . " (" . $player2Old->getRoundedStrength() . ") " . "to #" . $table->getPositionOfPlayer($toks[1]) . " (" . $player2->getRoundedStrength() . ")\n";
    echo $player3->getName() . ' => ' . 'from #' . $tableOld->getPositionOfPlayer($toks[3]) . " (" . $player3Old->getRoundedStrength() . ") " . "to #" . $table->getPositionOfPlayer($toks[3]) . " (" . $player3->getRoundedStrength() . ")\n";
    echo $player4->getName() . ' => ' . 'from #' . $tableOld->getPositionOfPlayer($toks[4]) . " (" . $player4Old->getRoundedStrength() . ") " . "to #" . $table->getPositionOfPlayer($toks[4]) . " (" . $player4->getRoundedStrength() . ")\n";
    $table->saveToFile();
    $showHelp = false;
}
// Display help message
if ($showHelp) {
    echo "How it works:\n" . "Current table: foos\n" . "Chances of winning: foos Samuel Coffey\n" . "Log a game: foos Samuel 2 Coffey 0\n";
}
function printFoosTable($players)
{
    $maxNameLength = 8;
    $numPlayers = count($players);
    $numRows = ceil(sqrt(2 * $numPlayers + 0.25) - 0.5);
    $numSlotsLastRow = $numRows;
    $lastRowWidth = $numSlotsLastRow * ($maxNameLength + 6 + 1) - 1;
    $numPerLine = 1;
    while (count($players) > 0) {