public static function sandbox() { // Testaa koodiasi täällä $Sven = new Hero(array('name' => 's', 'primaryattribute' => 'jäbäys', 'damagetype' => 'Physical', 'primaryrole' => 'core', 'attacktype' => 'Melee')); $errors = $Sven->errors(); Kint::dump($errors); }
function testFightEnemies() { $hero = new Hero('Batman'); $result = $hero->fight(array('Joker', 'Bane')); $this->assertEquals(true, $result); $this->expectOutputString('Batman defeated: Joker, Bane!' . PHP_EOL); }
function lamtech_preprocess_node(&$vars) { // kpr($vars); if (isset($vars['content']['field_category']) && count($vars['content']['field_category'])) { $vars['category'] = $vars['content']['field_category'][0]; unset($vars['content']['field_category']); } $helper = NULL; switch ($vars['type']) { case 'cta': require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'lamtech') . '/tpl/anb/cta/CTA.php'; $helper = new CTA(); $helper->preprocess($vars); break; case 'features_intro': require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'lamtech') . '/tpl/anb/fi/FeaturesIntro.php'; $helper = new FeaturesIntro(); $helper->preprocess($vars); break; case 'gallery': require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'lamtech') . '/tpl/anb/gallery/Gallery.php'; $helper = new Gallery(); $helper->preprocess($vars); break; case 'testimonials': require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'lamtech') . '/tpl/anb/testimonials/Testimonials.php'; $helper = new Testimonials(); $helper->preprocess($vars); break; case 'hero': require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'lamtech') . '/tpl/anb/hero/Hero.php'; $helper = new Hero(); $helper->preprocess($vars); break; case 'team': require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'lamtech') . '/tpl/anb/team/Team.php'; $helper = new Team(); $helper->preprocess($vars); break; case 'statistic': require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'lamtech') . '/tpl/anb/statistic/Statistic.php'; $helper = new Statistic(); $helper->preprocess($vars); break; case 'contact_info': require_once DRUPAL_ROOT . '/' . drupal_get_path('theme', 'lamtech') . '/tpl/anb/contact-info/ContactInfo.php'; $helper = new ContactInfo(); $helper->preprocess($vars); break; case 'advanced_page': unset($vars['content']['field_hide_title']); break; } // kpr($vars); }
public static function destroy($id) { self::check_logged_in(); $hero = new Hero(array('id' => $id)); $yhteys = new Yhteys(array('hero_id' => $id)); $draftids = Yhteys::findDraftID($id); $yhteys->destroy(); while ($draftids != NULL) { $draft = new Draft(array('id' => $draftids->draft_id)); $draft->destroy(); $draftids = Yhteys::findDraftID($id); } $hero->destroy(); Redirect::to('/hero', array('message' => 'Hero on poistettu onnistuneesti!')); }
private function getHeroData(Hero $heroInformation, $heroLevel) { $data = array(); $information = new Information(); //set everything base on display with respect to hero $information->set('name', $heroInformation->getName() . '(Level ' . DotaResourceData::HERO_LEVEL_START . ')'); $information->set('agi', $heroInformation->getBasicAgility()); $information->set('str', $heroInformation->getBasicStrength()); $information->set('int', $heroInformation->getBasicIntelligence()); $information->set('minDamage', $heroInformation->getMinDamage()); $information->set('maxDamage', $heroInformation->getMaxDamage()); $information->set('hp', $heroInformation->getHp()); $information->set('mana', $heroInformation->getMana()); $data[] = $information; if ($heroLevel > 1) { $data[] = DotaResourceCalculator::getInstance()->getCalculatedHeroStats($heroInformation, $heroLevel); } return $data; }
function loadHero($ID) { //check ID is not blank and exists and such $db = DB::GetConn(); $id_con = $db->quoteInto("ID = ?", $ID); $getQuery = "SELECT * FROM `Hero` WHERE {$id_con} limit 1;"; $res = $db->query($getQuery); $obj = $res->fetchObject(); $returnHero = Hero::loadHeroFromObject($obj); $returnHero->checkFightCooldown(); return $returnHero; }
public function index() { $this->uses("hero"); $dd = new Hero(); $lis = Hero::consultaNomeColunas(); //$obs = array(); //foreach ($lis as $key => $ob) //$obs[$ob['id']] = $ob; //$dd->setId(2); //$dd->setPalavra("ABCD"); //$this->set("echo", Hero::htmlTable()); $this->set("infos", $lis); //$this->set("errors", $dd->getErrors()); }
public static function store() { self::check_logged_in(); $user_logged_in = self::get_user_logged_in(); $params = $_POST; $attributes = array('name' => $params['name'], 'laatija_id' => $user_logged_in->id, 'hero1' => $params['hero1'], 'hero2' => $params['hero2'], 'hero3' => $params['hero3'], 'hero4' => $params['hero4'], 'hero5' => $params['hero5'], 'vaikeus' => $params['vaikeus'], 'suunnitelma' => $params['suunnitelma']); $draft = new Draft($attributes); $errors = $draft->errors(); if (count($errors) == 0) { $draft->save(); Redirect::to('/drafts' . $draft->id, array('message' => 'Drafti on lisätty arkistoon!')); } else { $heroes = Hero::all(); View::make('drafts/new.html', array('errors' => $errors, 'attributes' => $attributes, 'heroes' => $heroes)); } }
<?php include_once "bootstrap.php"; /*********Generate Hero*********/ include_once "hero/hero.php"; $testHero = new Hero(); $testHero->GenerateHero(1); // $_REQUEST["level"]); //generate lvl1 Hero $testHero->GiveToUser($currentUID); //save adventurer $testHero->SaveHero(); /***********end generate Hero *********/ //header("Location: index.php"); ?> <a href="home.php">Return</a>
public function gerarNovoDuelo($params) { $this->uses('Hero'); $rand = rand(0, 1); $mode = 0; $oficial = 1; switch ($mode) { case 0: //Sem Restrição $heroId1 = (int) Hero::select('id', array(), 'rand()', NULL, 1)[0]['id']; $heroId2 = (int) Hero::select('id', array(), 'rand()', NULL, 1)[0]['id']; break; case 1: //Sentinel x Scourge $heroId1 = (int) Hero::select('id', array('filiacao' => $rand ? 'SENTINEL' : 'SCOURGE'), 'rand()', NULL, 1)[0]['id']; $heroId2 = (int) Hero::select('id', array('filiacao' => $rand ? 'SCOURGE' : 'SENTINEL'), 'rand()', NULL, 1)[0]['id']; break; case 2: //Sentinel x Scourge | para apenas os que não jogaram X vezes como jogador/oponente | X = 1 $count = (int) Hero::nativeQuery("SELECT count(*) as n FROM hero WHERE id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") AND id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ")")[0]->n; if ($count < 2) { return json_encode(NULL); } $heroId1 = Hero::nativeQuery("SELECT id FROM hero WHERE filiacao = '" . ($rand ? 'SENTINEL' : 'SCOURGE') . "' AND (id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") AND id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ")) ORDER BY rand() LIMIT 1"); $heroId2 = Hero::nativeQuery("SELECT id FROM hero WHERE filiacao = '" . ($rand ? 'SCOURGE' : 'SENTINEL') . "' AND (id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") AND id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ")) ORDER BY rand() LIMIT 1"); $heroId1 = $heroId1 ? (int) $heroId1[0]->id : NULL; $heroId2 = $heroId2 ? (int) $heroId2[0]->id : NULL; break; case 3: // para apenas os que jogaram X vezes como jogador/oponente | X = 1 $count = (int) Hero::nativeQuery("SELECT count(*) as n FROM hero WHERE id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") AND id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ")")[0]->n; if ($count < 2) { return json_encode(NULL); } $heroId1 = Hero::nativeQuery("SELECT id FROM hero WHERE id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") AND id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") ORDER BY rand() LIMIT 1"); $heroId1 = $heroId1 ? (int) $heroId1[0]->id : NULL; $heroId2 = Hero::nativeQuery("SELECT id FROM hero WHERE id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") AND id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") AND id <> {$heroId1} ORDER BY rand() LIMIT 1"); $heroId2 = $heroId2 ? (int) $heroId2[0]->id : NULL; break; case 4: // Sentinel x Scourge | para apenas os que jogaram como jogador jogarão como oponente e vice-versa $heroId1 = Hero::nativeQuery("SELECT id FROM hero WHERE filiacao = '" . ($rand ? 'SENTINEL' : 'SCOURGE') . "' AND id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") ORDER BY rand() LIMIT 1"); $heroId2 = Hero::nativeQuery("SELECT id FROM hero WHERE filiacao = '" . ($rand ? 'SCOURGE' : 'SENTINEL') . "' AND id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") ORDER BY rand() LIMIT 1"); $heroId1 = $heroId1 ? (int) $heroId1[0]->id : NULL; $heroId2 = $heroId2 ? (int) $heroId2[0]->id : NULL; break; case 5: // para apenas os que jogaram como jogador jogarão como oponente e vice-versa $heroId1 = Hero::nativeQuery("SELECT id FROM hero WHERE id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") ORDER BY rand() LIMIT 1"); $heroId1 = $heroId1 ? (int) $heroId1[0]->id : NULL; $heroId2 = Hero::nativeQuery("SELECT id FROM hero WHERE id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") AND id <> {$heroId1} ORDER BY rand() LIMIT 1"); $heroId2 = $heroId2 ? (int) $heroId2[0]->id : NULL; break; case 6: // Sentinel (jogador) x Scourge (oponente) | para apenas os que jogaram como jogador jogarão como oponente e vice-versa $heroId1 = Hero::nativeQuery("SELECT id FROM hero WHERE filiacao = 'SENTINEL' AND id NOT IN (SELECT jogador FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") ORDER BY rand() LIMIT 1"); $heroId2 = Hero::nativeQuery("SELECT id FROM hero WHERE filiacao = 'SCOURGE' AND id NOT IN (SELECT oponente FROM duelo" . ($oficial === NULL ? "" : " WHERE oficial = {$oficial}") . ") ORDER BY rand() LIMIT 1"); $heroId1 = $heroId1 ? (int) $heroId1[0]->id : NULL; $heroId2 = $heroId2 ? (int) $heroId2[0]->id : NULL; break; } //$hero1 = Hero::load($heroIds[ rand(0, count($heroIds)-1) ]); //$hero2 = Hero::load($heroIds[ rand(0, count($heroIds)-1) ]); $hero1 = Hero::load($heroId1); $hero2 = Hero::load($heroId2); if (!$hero1 || !$hero2) { return json_encode(NULL); } return json_encode(array($hero1, $hero2)); }
<?php include_once "bootstrap.php"; /*********Generate Hero*********/ include_once "hero/heroController.php"; $heroController = new heroController(); include_once "user/userController.php"; $userController = new userController(); $user = new User(); $user = $user->load($currentUID); $newHeroCost = $heroController->getCostForNextHero($currentUID); if ($user->canAfford($newHeroCost)) { $user->gold -= $newHeroCost; $user->Save(); $Hero = new Hero(); $Hero->GenerateHero(1); // $_REQUEST["level"]); //generate lvl1 Hero $Hero->GiveToUser($currentUID); $Hero->generateStartingWeapon(); //@TODO move this into hero controller so it can follow the correct process (create, give, weapon, ect) //save hero $Hero->SaveHero(); /***********end generate Hero *********/ //check for referer bonus if ($newHeroCost > 0 && $user->refererID != 0) { $refererUser = new User(); $refererUser = $refererUser->load($user->refererID); $recruitmentBonus = ceil($newHeroCost / 10); $refererUser->credit($recruitmentBonus); $userController->sendMessage($refererUser->ID, $user->ID, "Recruitment Bonus of " . $recruitmentBonus . " gp", $user->username . " hired a new hero, earning you " . $recruitmentBonus . "gp"); }
} class Monster extends Levensvorm { public function receiveAttack($ap) { $this->hp = $this->hp - $ap; } } test('A hero starts with 100HP.', function () { return (new Hero())->hp() === 100; }); test('A monster starts with 100HP.', function () { return (new Monster())->hp() === 100; }); test('Levensvormen vallen elkaar aan', function () { $hero = new Hero(); $monster = new Monster(); $hero->bewapen(new Wapen(10)); $hero->attack($monster); return $monster->hp() === 90; }); class Levensvorm { protected $hp = 100; public function hp() { return $this->hp; } } class Wapen {
function showAllForUser($id) { $db = DB::GetConn(); $getQuery = "SELECT `ID` FROM `Hero` WHERE `OwnerID` = {$id};"; $res = $db->query($getQuery); //execute query echo "<table style='width: 100%;'>\n\t\t\t<tr>\n\t\t\t<td>Name</td>\n\t\t\t<!--<td>OwnerID</td>\n\t\t\t<td>PartyID</td>-->\n\t\t\t<td>Race</td>\n\t\t\t<td>Class</td>\n\t\t\t<td>HP</td>\n\t\t\t<td>Level</td>\n\t\t\t<td>XP</td>\n\t\t\t<td>Str</td>\n\t\t\t<td>Dex</td>\n\t\t\t<td>Con</td>\n\t\t\t<td>Int</td>\n\t\t\t<td>Wis</td>\n\t\t\t<td>Cha</td>\n\t\t\t<td>Weapon</td>\n\t\t\t<td>Level UP</td>\n\t\t\t<td>Revive</td>\n\t\t\t<td>Fight</td>\n\t\t\t</tr>"; $totalHeros = 0; while ($obj = $res->fetchObject()) { $Hero = new Hero(); $this->outputInTable($Hero->loadHero($obj->ID)); $totalHeros++; } echo "Showing " . $totalHeros . " results.<br />"; echo "</table>"; return $totalHeros; }
public function defend($damage) { return parent::defend($damage); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Hero $value A Hero object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(Hero $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
<?php include_once "bootstrap.php"; /*********Generate Hero*********/ include_once "hero/heroController.php"; $heroController = new heroController(); include_once "user/user.php"; $user = new User(); $user = $user->load($currentUID); $newHeroCost = $heroController->getCostForNextHero($currentUID); if ($user->canAfford($newHeroCost)) { $user->gold -= $newHeroCost; $user->Save(); $Hero = new Hero(); $Hero->GenerateHero($_REQUEST["level"]); //generate lvl Hero $Hero->GiveToUser($currentUID); $Hero->generateStartingWeapon(); //@TODO move this into hero controller so it can follow the correct process (create, give, weapon, ect) //save hero $Hero->SaveHero(); /***********end generate Hero *********/ header("Location: viewHero.php?ID=" . $Hero->ID); } else { header("Location: home.php"); //@TODO error message for cant afford }
public function fight($monsters) { //Attacks every living thing in an array if ($this->isAlive()) { foreach ($monsters as $monster) { while ($monster->isAlive() && $this->isAlive()) { $this->attack($monster); } } } } } $rat = new LivingThing("Rat", 5); $goblin = new LivingThing("Goblin", 30); $ogre = new LivingThing("Ogre", 80); $hero = new Hero("Batman", 100); $monsters = array($rat, $goblin, $ogre); echo "<h3>A hero emerges!</h3>"; echo "<p>The noble {$hero->getName()} has vowed to defeat the monsters and save the realm.</p>"; echo "<p>Will they be victorious?</p>"; $hero->fight($monsters); if ($hero->isAlive()) { echo "<p>The hero {$hero->getName()} prevailed!</p>"; } else { echo "<p>{$hero->getName()} was bested by the monsters. We are doomed.</p>"; } ?> </p> </body>
/** * @covers {className}::{origMethodName} * @todo Implement testGetInfo(). */ public function testGetInfo() { // Remove the following lines when you implement this test. $this->assertNotEmpty($this->object->getInfo()); }
public function table() { $this->set("heroList", Hero::all2()); }
function getTop10ByKills() { $db = DB::GetConn(); $getQuery = "SELECT * FROM `Hero` ORDER BY `Hero`.`Kills` DESC LIMIT 10;"; $res = $db->query($getQuery); //execute query $returnHeroes = array(); while ($obj = $res->fetchObject()) { array_push($returnHeroes, Hero::loadHeroFromObject($obj)); } return $returnHeroes; }
/** * Declares an association between this object and a Hero object. * * @param Hero $v * @return HeroSkill The current object (for fluent API support) * @throws PropelException */ public function setHero(Hero $v = null) { if ($v === null) { $this->setHeroId(NULL); } else { $this->setHeroId($v->getId()); } $this->aHero = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Hero object, it will not be re-added. if ($v !== null) { $v->addHeroSkill($this); } return $this; }