public function __invoke()
 {
     $input = $this->loadInput("Day14/Puzzle1");
     $parser = new InstructionsParser();
     $herd = $parser->parse($input);
     $race = new Race($herd);
     $duration = 2503;
     $winner = $race->pointsWinnerAfter($duration);
     $this->write("Winner: " . $winner->name() . " with " . $winner->points() . " points");
 }
 public function __invoke()
 {
     $input = $this->loadInput("Day14/Puzzle1");
     $parser = new InstructionsParser();
     $herd = $parser->parse($input);
     $race = new Race($herd);
     $duration = 2503;
     $winner = $race->winnerAfter($duration);
     $this->write("Winner: " . $winner->name() . ", who has flown " . $winner->distanceAfter($duration));
 }
Esempio n. 3
0
 function test_addData_raceCheck()
 {
     Initial::addData();
     $race = Race::getAll();
     $result = new Race("Good all around, well balanced, adventurer.  Easy to role play and fits most roles well.", "Human", 1);
     $this->assertEquals($race[0], $result);
 }
Esempio n. 4
0
 protected function tick()
 {
     parent::tick();
     foreach ($this->leaders() as $leader) {
         $this->standings[$leader] += 1;
     }
 }
Esempio n. 5
0
 protected function tearDown()
 {
     CharClass::deleteAll();
     Character::deleteAll();
     Race::deleteAll();
     Skill::deleteAll();
     Stat::deleteAll();
     Description::deleteAll();
     Background::deleteAll();
 }
Esempio n. 6
0
 static function find($search_id)
 {
     $found_race = null;
     $races = Race::getAll();
     foreach ($races as $race) {
         $race_id = $race->getId();
         if ($race_id == $search_id) {
             $found_race = $race;
         }
     }
     return $found_race;
 }
Esempio n. 7
0
 public function raceget($page)
 {
     if (Race::all()->count() > ($page - 1) * 20) {
         $race = Race::take(20)->skip(($page - 1) * 20)->orderBy("id", "desc")->get();
         for ($i = 0; $i < count($race); $i++) {
             $export[] = array("title" => urlencode(trim($race[$i]->web_main_top_title)), "day" => urlencode(trim($race[$i]->web_main_top_day)), "writer" => urlencode(trim($race[$i]->web_main_where)), "body" => urlencode(base64_encode($race[$i]->web_main_data)), "file" => urlencode(trim($race[$i]->web_main_link)), "image" => urlencode(trim($race[$i]->web_main_file)), "link" => urlencode(trim($race[$i]->web_main_outside_link)));
         }
         return urldecode(json_encode($export));
     } else {
         $export[] = array("title" => " ", "day" => " ", "writer" => " ", "body" => " ", "file" => " ", "image" => " ", "link" => " ");
         return urldecode(json_encode($export));
     }
 }
Esempio n. 8
0
 /**
  * Creates new race based on params.
  * @param string $name
  * @return Race
  */
 public static function create($name)
 {
     if (empty(Races::$available[$name])) {
         return null;
     }
     $data = Races::$available[$name];
     $race = new Race();
     $race->setName($data['name']);
     $race->setTradeContracts($data['trades']);
     $race->setSpecials($data['specials']);
     $race->setTechnologies($data['technologies']);
     $race->setUnits($data['units']);
     return $race;
 }
Esempio n. 9
0
    if ($test()) {
        echo " [x] ";
    } else {
        echo " [ ] ";
    }
    echo $string;
    echo "\n";
}
test('Max snelheid van een auto is het aantal PK * 2', function () {
    $ferrari = new Car(new Engine(115));
    return $ferrari->maxSpeed() === 230;
});
test('Autorace', function () {
    $ferrari = new Car(new Engine(300));
    $corsa = new Car(new Engine(80));
    $race = new Race($ferrari, $corsa);
    return $race->determineWinner() === $ferrari;
});
class Race
{
    private $car1, $car2;
    public function __construct(Car $car1, Car $car2)
    {
        $this->car1 = $car1;
        $this->car2 = $car2;
    }
    public function determineWinner()
    {
        if ($this->car1->maxSpeed() > $this->car2->maxSpeed()) {
            return $this->car1;
        }
Esempio n. 10
0
 public function getPersonal()
 {
     $data['races'] = Race::all();
     return View::make('website.provider.personal')->with($data);
 }
Esempio n. 11
0
switch (strtoupper($action)) {
    case 'ADD':
        break;
    case 'SAVE':
        if (isset($_REQUEST['btn_submit']) && $_REQUEST['btn_submit'] == 'save') {
            $objRace = new Race();
            $objRace->setRace($_REQUEST);
            $objComm->redirect('index.php?model=' . $model);
        }
        break;
    case 'VIEW':
    case 'EDIT':
        if (isset($_REQUEST['btn_submit']) && $_REQUEST['btn_submit'] == 'Update') {
            $objRace = new Race();
            $objRace->setRace($_REQUEST);
            $objComm->redirect('index.php?model=' . $model . '&action=edit&id=' . $_REQUEST['pk_id']);
        } else {
            $objRace = new Race();
            $datum = $objRace->getRace($_REQUEST['id'], $action);
        }
        break;
    case 'DELETE':
        $objRace = new Race();
        $objRace->delRace($_REQUEST['id']);
        $objComm->redirect('index.php?model=' . $model);
        break;
    default:
        $objRace = new Race();
        $data = $objRace->getAllRace();
        break;
}
Esempio n. 12
0
File: app.php Progetto: Camolot/dnd
$app->post('/class', function () use($app) {
    $_SESSION['race'] = $_POST['race_id'];
    return $app['twig']->render('class.html.twig', array('classes' => CharClass::getAll()));
});
//class page
//carry race id and class id to background page
$app->post('/background', function () use($app) {
    $_SESSION['class'] = $_POST['class_id'];
    return $app['twig']->render('background.html.twig', array('backgrounds' => Background::getAll()));
});
//background page
//carry race id, class id, background id to stats page
$app->post('/stats', function () use($app) {
    $_SESSION['background'] = $_POST['background_id'];
    $race_id = $_SESSION['race'];
    $race_find = Race::find($race_id);
    $race = getName($race_find);
    $class_id = $_SESSION['class'];
    $class_find = CharClass::find($class_id);
    $classname = getName($class_find);
    $stats = statRoll();
    $assigned_stats = assignRolls($six_rolls, $classname, $race);
    return $app['twig']->render('stats.html.twig', array('stat' => Stat::getAll()));
});
//stats page
//carry race id, class id, background id, stats id to skills page
$app->post('/bio', function () use($app) {
    $_SESSION['str'] = $_POST['str_id'];
    $_SESSION['dex'] = $_POST['dex_id'];
    $_SESSION['con'] = $_POST['con_id'];
    $_SESSION['int'] = $_POST['int_id'];
Esempio n. 13
0
<?php

include 'header.php';
$race = new Race($reindeer, 2503);
$race->readySetGo();
echo max($race->results());
Esempio n. 14
0
 function GenerateRace()
 {
     //This is pretty terrible but it matches the DB for now
     $human = Race::loadRace(1);
     $dwarf = Race::loadRace(2);
     $elf = Race::loadRace(3);
     $halfling = Race::loadRace(4);
     $races = array($human, $dwarf, $elf, $halfling);
     $newRace = $races[rand(0, 3)];
     return $newRace;
 }
Esempio n. 15
0
this.Units = new function() {
	var U = function(a, d) {
		this.attack = a;
		this.defence = d;
	};

	var RU = function(u1, u2, u3) {
		this[1] = u1;
		this[2] = u2;
		this[3] = u3;
	};

<?php 
$units_data = DataTable::constructFromCsvFile(new CsvFile('data/units.csv'));
foreach (Race::values() as $race) {
    $units = $units_data->get(array('race_english' => $race));
    $first = true;
    echo "\t" . 'this[\'' . $race . '\'] = new RU(';
    foreach ($units as $unit_array) {
        if (!$first) {
            echo ', ';
        }
        $unit = Unit::constructFromArray($unit_array);
        echo 'new U(' . $unit->getAttack() . ',' . $unit->getDefence() . ')';
        $first = false;
    }
    echo ');' . PHP_EOL;
}
?>
};
Esempio n. 16
0
<?php

$lines = ['Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds.', 'Dancer can fly 16 km/s for 11 seconds, but then must rest for 162 seconds.'];
$lines = file('14.txt');
$race = new Race();
// Add reindeers to race
foreach ($lines as $line) {
    preg_match('/(.*) can fly ([0-9]+) km\\/s for ([0-9]+) seconds, but then must rest for ([0-9]+) seconds\\./', $line, $matches);
    $race->addReindeer(new Reindeer($matches[1], $matches[2], $matches[3], $matches[4]));
}
$race->startRace(2503);
$winner = $race->getLeaders()[0];
echo array_sum($race->getPoints());
foreach ($race->getReindeers() as $reindeer) {
    printf("%s: %d km, %d points\n", $reindeer->getName(), $reindeer->getDistanceCovered(), $race->getPointsForReindeer($reindeer));
}
echo sprintf('Part 1 answer: %s', $winner->getDistanceCovered()) . PHP_EOL;
echo sprintf('Part 2 answer: %s', max($race->getPoints())) . PHP_EOL;
class Race
{
    /** @var Reindeer[] */
    protected $reindeers = [];
    /** @var array */
    protected $points = [];
    /**
     * @param Reindeer $reindeer
     */
    public function addReindeer(Reindeer $reindeer)
    {
        $this->reindeers[] = $reindeer;
    }
Esempio n. 17
0
    $_SESSION['eye_color'] = $_POST['eye_color'];
    $_SESSION['hair_color'] = $_POST['hair_color'];
    $_SESSION['skin_tone'] = $_POST['skin_tone'];
    $_SESSION['alignment'] = $_POST['alignment'];
    $_SESSION['other'] = $_POST['other'];
    $found_race = Race::find($_SESSION['race']);
    $found_race->getName();
    $found_class = CharClass::find($_SESSION['class']);
    $found_class->getName();
    $found_background = Background::find($_SESSION['background']);
    $found_background->getName();
    return $app['twig']->render('summary.html.twig', array('race' => $found_race, 'class' => $found_class, 'background' => $found_background, 'str' => $_SESSION['str'], 'dex' => $_SESSION['dex'], 'con' => $_SESSION['con'], 'wis' => $_SESSION['wis'], 'int' => $_SESSION['int'], 'cha' => $_SESSION['cha'], 'skills' => $_SESSION['skill'], 'name' => $_SESSION['name'], 'age' => $_SESSION['age'], 'gender' => $_SESSION['gender'], 'height' => $_SESSION['height'], 'eye_color' => $_SESSION['eye_color'], 'hair_color' => $_SESSION['hair_color'], 'skin_tone' => $_SESSION['skin_tone'], 'alignment' => $_SESSION['alignment'], 'other' => $_SESSION['other'], 'races' => Race::getAll(), 'classes' => CharClass::getAll(), 'backgrounds' => Background::getAll()));
});
//return to race page and save to database
$app->get('/summary', function () use($app) {
    Finalize::run();
    return $app['twig']->render('race.html.twig');
});
//print page
//render print page
$app->get('/print', function () use($app) {
    $character = Finalize::run();
    $found_race = Race::find($_SESSION['race']);
    $found_race->getName();
    $found_class = CharClass::find($_SESSION['class']);
    $found_class->getName();
    $found_background = Background::find($_SESSION['background']);
    $found_background->getName();
    return $app['twig']->render('print.html.twig', array("character" => $character, 'race' => $found_race, 'class' => $found_class, 'background' => $found_background, 'str' => $_SESSION['str'], 'dex' => $_SESSION['dex'], 'con' => $_SESSION['con'], 'wis' => $_SESSION['wis'], 'int' => $_SESSION['int'], 'cha' => $_SESSION['cha'], 'skills' => $_SESSION['skill'], 'name' => $_SESSION['name'], 'age' => $_SESSION['age'], 'gender' => $_SESSION['gender'], 'height' => $_SESSION['height'], 'eye_color' => $_SESSION['eye_color'], 'hair_color' => $_SESSION['hair_color'], 'skin_tone' => $_SESSION['skin_tone'], 'alignment' => $_SESSION['alignment'], 'other' => $_SESSION['other'], 'races' => Race::getAll(), 'classes' => CharClass::getAll(), 'backgrounds' => Background::getAll()));
});
return $app;
Esempio n. 18
0
 public function getGoods($use_dynamic_RR_prices = true)
 {
     /**
      * Returns array containing buyable stuff for teams in their coach corner.
      *
      *  Setting $use_dynamic_RR_prices forces non-doubled RR prices.
      **/
     // Setup correct $rules for when calling $race->getGoods() which uses the $rules['max_*'] entries.
     global $rules;
     setupGlobalVars(T_SETUP_GLOBAL_VARS__LOAD_LEAGUE_SETTINGS, array('lid' => $this->f_lid));
     // Load correct $rules for league.
     $race = new Race($this->f_race_id);
     return $race->getGoods($use_dynamic_RR_prices ? $this->doubleRRprice() : false);
 }
Esempio n. 19
0
 function GenerateRace()
 {
     //@TODO:Load all StarterRaces from race table and pick a random one.
     $human = Race::loadRace(1);
     $dwarf = Race::loadRace(2);
     $elf = Race::loadRace(3);
     $halfling = Race::loadRace(4);
     $races = array($human, $human, $dwarf, $elf, $halfling);
     $newRace = $races[rand(0, 4)];
     return $newRace;
 }
Esempio n. 20
0
 static function addData()
 {
     // SKILLS:
     $skill1 = new Skill("Acrobatics", "Balancing and tumbling", 1);
     $skill2 = new Skill("Animal Handling", "Using or interacting with domesticated animals.", 2);
     $skill3 = new Skill("Arcana", "Magic related lore and knowledge.", 3);
     $skill4 = new Skill("Athletics", "Climbing, jumping, and swimming.", 4);
     $skill5 = new Skill("Deception", "Hide the truth.", 5);
     $skill6 = new Skill("History", "Recall historical events.", 6);
     $skill7 = new Skill("Insight", "Determine a creature's true intentions.", 7);
     $skill8 = new Skill("Intimidation", "Influence by using threats.", 8);
     $skill9 = new Skill("Investigation", "Look for clues and find hidden things.", 9);
     $skill10 = new Skill("Medicine", "Stabilize the dying or diagnose a disease.", 10);
     $skill11 = new Skill("Nature", "Recall weather, plant, or animal lore.", 11);
     $skill12 = new Skill("Perception", "See, hear, or smell the presence or something.", 12);
     $skill13 = new Skill("Performance", "Ability in dancing, singing, or storytelling.", 13);
     $skill14 = new Skill("Persuasion", "Influence by using goodwill.", 14);
     $skill15 = new Skill("Religion", "Recall religious lore.", 15);
     $skill16 = new Skill("Sleight of Hand", "Concealing items or stealing things.", 16);
     $skill17 = new Skill("Stealth", "Sneaking or hiding.", 17);
     $skill18 = new Skill("Survival", "Track and hunt, avoid hazards, or predict weather.", 18);
     $skill1->save();
     $skill2->save();
     $skill3->save();
     $skill4->save();
     $skill5->save();
     $skill6->save();
     $skill7->save();
     $skill8->save();
     $skill9->save();
     $skill10->save();
     $skill11->save();
     $skill12->save();
     $skill13->save();
     $skill14->save();
     $skill15->save();
     $skill16->save();
     $skill17->save();
     $skill18->save();
     // RACES:
     $race1 = new Race("Good all around, well balanced, adventurer.  Easy to role play and fits most roles well.", "Human", 1);
     $race2 = new Race("Tough and wise. Good clerics. Bearded and can live to over 400. A bit more open than mountain dwarves.", "Hill Dwarf", 2);
     $race3 = new Race("Strong and tough. Good fighters. Bearded and can live to over 400. Likes to keep to their own.", "Mountain Dwarf", 3);
     $race4 = new Race("Fast and intelligent. Good fighters, rogues or wizards. Bronze skin. Has air of superiority.", "High Elf", 4);
     $race5 = new Race("Fast and wise. Good clerics and fighters. Copper/green skin. Very in tune with nature.", "Wood Elf", 5);
     $race6 = new Race("Fast and charismatic. Good rogues. Easily overlooked. Wanderers. Around 3 feet tall.", "Lightfoot Halfling", 6);
     $race7 = new Race("Tough and fast. Good fighters or rogues. Strong natured and boisterous.", "Stout Halfling", 7);
     $race1->save();
     $race2->save();
     $race3->save();
     $race4->save();
     $race5->save();
     $race6->save();
     $race7->save();
     // CLASSES:
     $class1 = new CharClass("Cleric", "Wise and charismatic. Typically a healer who wields divine power in the service of their diety.", 1);
     $class2 = new CharClass("Fighter", "Strong and tough or fast and tough. Master of combat and knowledgable in weapons and armor.", 2);
     $class3 = new CharClass("Rogue", "Fast and intelligent. Highly skilled and commonly duplicitous. Commonly a seeker of treasures.", 3);
     $class4 = new CharClass("Wizard", "Intelligent and wise. Weaves magic spells that manipulate reality using long studied arcane knowledge.", 4);
     $class1->save();
     $class2->save();
     $class3->save();
     $class4->save();
     // BACKGROUNDS:
     $background1 = new Background("Hermit", "Medicine and religion. Your life has been lonely and you have a secret knowledge.", 1);
     $background2 = new Background("Noble", "History and persuasion. Your life has been luxurious and you benefit from your position of privilege.", 2);
     $background3 = new Background("Soldier", "Athletics and intimidation. Your life has been touched by war and you are recognized by your military rank.", 3);
     $background4 = new Background("Urchin", "Sleight of Hand and Stealth. Your life has been impoverished and you are intimately familiar with city workings.", 4);
     $background1->save();
     $background2->save();
     $background3->save();
     $background4->save();
 }
Esempio n. 21
0
 function testSave()
 {
     //Arrange
     $description = "Average Joe";
     $name = "Human";
     $id = 1;
     $test_race = new Race($description, $name, $id);
     //Act
     $test_race->save();
     //Assert
     $result = Race::getAll();
     $this->assertEquals($test_race, $result[0]);
 }
Esempio n. 22
0
 public function importGame()
 {
     $this->Session->delete('ajaxProgress');
     $jsonMessage = array();
     if (!empty($this->request->query['slug'])) {
         App::uses('Game', 'Model');
         $GameModel = new Game();
         $slug = $this->request->query['slug'];
         $this->Session->write('ajaxProgress', 10);
         App::uses('RaidheadSource', 'Model/Datasource');
         $RaidHead = new RaidheadSource();
         $game = $RaidHead->get($slug);
         // Check API error
         if ($game['error']) {
             $jsonMessage['type'] = 'important';
             switch ($game['error']) {
                 case 401:
                     $jsonMessage['msg'] = __('Import failed : Game not found');
                     break;
                 default:
                     $jsonMessage['msg'] = __('Import failed : An error occur while importing the game');
             }
             return json_encode($jsonMessage);
         }
         $this->Session->write('ajaxProgress', 30);
         $toSave = array();
         $toSave['title'] = $game['game']['title'];
         $toSave['slug'] = $game['game']['short'];
         $toSave['logo'] = $game['game']['icon_64'];
         $toSave['import_slug'] = $game['game']['short'];
         $toSave['import_modified'] = $game['lastupdate'];
         if (!($gameId = $GameModel->__add($toSave))) {
             $jsonMessage['type'] = 'important';
             $jsonMessage['msg'] = __('Save failed : An error occur while saving the game');
             return json_encode($jsonMessage);
         }
         $this->Session->write('ajaxProgress', 50);
         // Dungeons
         if ($game['game']['has_dungeon'] && !empty($game['dungeons'])) {
             App::uses('Dungeon', 'Model');
             $DungeonModel = new Dungeon();
             App::uses('RaidsSize', 'Model');
             $RaidsSizeModel = new RaidsSize();
             foreach ($game['dungeons'] as $dungeonSlug => $dungeon) {
                 $toSaveDungeons = array();
                 $toSaveDungeons['game_id'] = $gameId;
                 $toSaveDungeons['title'] = $dungeon['title'];
                 $toSaveDungeons['slug'] = $dungeonSlug;
                 $toSaveDungeons['raidssize_id'] = $RaidsSizeModel->__add($dungeon['max_players']);
                 if (!empty($dungeon['level_min'])) {
                     $toSaveDungeons['level_required'] = $dungeon['level_min'];
                 }
                 $DungeonModel->__add($toSaveDungeons, array('game_id' => $gameId));
             }
         }
         $this->Session->write('ajaxProgress', 65);
         // Races
         if ($game['game']['has_race'] && !empty($game['races'])) {
             App::uses('Race', 'Model');
             $RaceModel = new Race();
             foreach ($game['races'] as $raceSlug => $race) {
                 $toSaveRaces = array();
                 $toSaveRaces['game_id'] = $gameId;
                 $toSaveRaces['title'] = $race['title'];
                 $toSaveRaces['slug'] = $raceSlug;
                 $RaceModel->__add($toSaveRaces, array('game_id' => $gameId));
             }
         }
         $this->Session->write('ajaxProgress', 80);
         // Classes
         if ($game['game']['has_classe'] && !empty($game['classes'])) {
             App::uses('Classe', 'Model');
             $ClasseModel = new Classe();
             foreach ($game['classes'] as $classeSlug => $classe) {
                 $toSaveClasses = array();
                 $toSaveClasses['game_id'] = $gameId;
                 $toSaveClasses['title'] = $classe['title'];
                 $toSaveClasses['slug'] = $classeSlug;
                 if (!empty($classe['icon_64'])) {
                     $toSaveClasses['icon'] = $classe['icon_64'];
                 }
                 $defaultColor = '#000000';
                 $color = !empty($classe['color']) ? $classe['color'] : $defaultColor;
                 $color = strlen($color) < 6 ? $defaultColor : $color;
                 $toSaveClasses['color'] = $color;
                 $ClasseModel->__add($toSaveClasses, array('game_id' => $gameId));
             }
         }
         $this->Session->write('ajaxProgress', 100);
         $jsonMessage['type'] = 'success';
         $jsonMessage['msg'] = __('Game imported successfully, you are now redirected to games list');
     } else {
         $jsonMessage['type'] = 'important';
         $jsonMessage['msg'] = __('Import failed : An error occur while importing the game');
     }
     return json_encode($jsonMessage);
 }
Esempio n. 23
0
$res = $db->query($getClassQuery);
//execute query
$ClassTableData = "['Class', 'Population'],";
while ($obj = $res->fetchObject()) {
    $HeroClass = HeroClass::loadHeroClass($obj->Class);
    $ClassTableData .= "['" . $HeroClass->Name . "', " . $obj->count . "],";
}
$ClassTableData = rtrim($ClassTableData, ",");
$smarty->assign("ClassTableData", $ClassTableData);
//get Race count
$getRaceQuery = "SELECT Race,COUNT(*) as count FROM Hero Where OwnerID <> 146 AND CurrentHP > 0 GROUP BY Race ORDER BY count DESC;";
$res = $db->query($getRaceQuery);
//execute query
$RaceTableData = "['Race', 'Population'],";
while ($obj = $res->fetchObject()) {
    $HeroRace = Race::loadRace($obj->Race);
    $RaceTableData .= "['" . $HeroRace->Name . "', " . $obj->count . "],";
}
$RaceTableData = rtrim($RaceTableData, ",");
$smarty->assign("RaceTableData", $RaceTableData);
//Get Level Count
$getLevelQuery = "SELECT Level,COUNT(*) as count FROM Hero Where OwnerID <> 146 AND CurrentHP > 0 GROUP BY Level ORDER BY Level ASC;";
$res = $db->query($getLevelQuery);
//execute query
$LevelTableData = "";
$i = 1;
$obj = $res->fetchObject();
while ($i <= 50) {
    if ($obj != false) {
        if ($obj->Level == $i) {
            $LevelTableData .= "[" . $obj->Level . ", " . $obj->count . "],";