<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Tamagotchi.php"; session_start(); if (empty($_SESSION['tamagotchi_attributes'])) { $_SESSION['tamagotchi_attributes'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . "/../views")); $app->get("/", function () use($app) { return $app['twig']->render('tamagotchi.html.twig', array('attributes' => Tamagotchi::getAll())); }); $app->post("/name", function () use($app) { $new_tamagotchi = new Tamagotchi($_POST['name']); $new_tamagotchi->save(); return $app['twig']->render('create_name.html.twig'); }); $app->get("/food", function () use($app) { $current_tamagotchi = Tamagotchi::getAll(); $current_tamagotchi[0]->setFood(10); $food = $current_tamagotchi[0]->getFood(); $sleep = $current_tamagotchi[0]->getSleep(); $attention = $current_tamagotchi[0]->getAttention(); if ($sleep == 0 || $attention == 0) { return $app['twig']->render('dead.html.twig'); } else { $current_tamagotchi[0]->setFood($food + 1); $current_tamagotchi[0]->setSleep($sleep - 1); $current_tamagotchi[0]->setAttention($attention - 1); return $app['twig']->render('create_food.html.twig');
<?php require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../src/tamagotchi.php'; session_start(); if (empty($_SESSION['tamagotchi-status'])) { $_SESSION['tamagotchi-status'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get('/', function () use($app) { return $app['twig']->render('name.html.twig'); }); $app->post("/added", function () use($app) { $tammy = new Tamagotchi($_POST['name']); $tammy->save(); return $app['twig']->render('added.html.twig', array('tammy' => $tammy)); }); $app->get("/status", function () use($app) { $tammyList = Tamagotchi::getAll(); return $app['twig']->render('status.html.twig', array('tammyList' => $tammyList)); }); $app->post("/feed", function () use($app) { $tammyList = Tamagotchi::getAll(); foreach ($tammyList as $key => $tammy) { if ($tammy->getName() == $_POST['name']) { $tammy->feed(); } } return $app['twig']->render('status.html.twig', array('tammyList' => $tammyList)); });
require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Tamagotchi.php"; session_start(); if (empty($_SESSION['list_of_tamagotchis'])) { $_SESSION['list_of_tamagotchis'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //routes $app->get("/", function () use($app) { return $app['twig']->render('home.html.twig', array('tamagotchis' => Tamagotchi::getAll())); }); $app->post('/add_gotchi', function () use($app) { $agotchi = new Tamagotchi($_POST['name']); $agotchi->save(); return $app['twig']->render('home.html.twig', array('tamagotchis' => Tamagotchi::getAll())); }); $app->get('/age', function () use($app) { $tamagotchis = Tamagotchi::getAll(); foreach ($tamagotchis as $key => $tamagotchi) { $tamagotchi->age(); } return $app['twig']->render('home.html.twig', array('tamagotchis' => Tamagotchi::getAll())); }); $app->post('/delete_all', function () use($app) { Tamagotchi::deleteAll(); return $app['twig']->render('home.html.twig', array('tamagotchis' => Tamagotchi::getAll())); }); $app->post('/feed', function () use($app) { foreach ($_SESSION['list_of_tamagotchis'] as $key => $tamagotchi) {
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/tamagotchi.php"; session_start(); if (empty($_SESSION['tama_list'])) { $_SESSION['tama_list'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('tamagotchi_list.html.twig', array('tamagotchis' => Tamagotchi::getAll())); }); $app->get("/pass_time", function () use($app) { Tamagotchi::time(); return $app['twig']->render('tamagotchi_list.html.twig', array('tamagotchis' => Tamagotchi::getAll())); }); $app->get("/tamagotchi_form", function () use($app) { return $app['twig']->render('tamagotchi_form.html.twig'); }); $app->post("/", function () use($app) { $tamas = new Tamagotchi(10, 10, 10, $_POST['name']); $tamas->save(); return $app['twig']->render('tamagotchi_list.html.twig', array('tamagotchis' => Tamagotchi::getAll())); }); $app->post("/delete_tama", function () use($app) { Tamagotchi::deleteAll(); return $app['twig']->render('delete_tama.html.twig'); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Tamagotchi.php"; session_start(); if (empty($_SESSION['list_of_pets'])) { $_SESSION['list_of_pets'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('pets.html.twig', array('pets' => Tamagotchi::getAll())); }); $app->post("/pets", function () use($app) { $pet = new Tamagotchi($_POST['name']); $pet->save(); return $app['twig']->render('create_pet.html.twig', array('newpet' => $pet)); }); $app->post("/delete_pets", function () use($app) { Tamagotchi::deleteAll(); return $app['twig']->render('delete_pets.html.twig'); }); //find out how to change so these methods can work on more than the object keyed in array at 0 $app->post("/feeding", function () use($app) { $pet = Tamagotchi::getAll(); if (key($_POST) == "food") { $pet[0]->feed(); } return $app['twig']->render('pets.html.twig', array('pets' => Tamagotchi::getAll())); }); $app->post("/feelings", function () use($app) {
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Tamagotchi.php"; session_start(); if (empty($_SESSION['tamagotchis'])) { $_SESSION['tamagotchis'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('create_tamagotchi.html.twig', array('tamas' => Tamagotchi::getAll())); }); $app->post("/tamagotchis_page", function () use($app) { $tama = new Tamagotchi($_POST['name']); $tama->save(); return $app['twig']->render('tamagotchis_page.html.twig', array('newtama' => $tama)); }); $app->post("/add_food", function () use($app) { $tama->addFood(); return $app['twig']->render('tamagotchis_page.html.twig'); }); // $tama = new Tamagotchi($_POST['name']); // $tama->addFood(); // return $app['twig']->render('tamagotchis_page.html.twig', array('newtama' => $tama)); // // $app->post("/delete_tama", function() use ($app) { // Tamagotchi::deleteAll(); // return $app['twig']->render('delete_place.html.twig'); // }); return $app;
require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Tamagotchi.php"; session_start(); if (empty($_SESSION['state_of_tamagotchi'])) { $_SESSION['state_of_tamagotchi'] = array(); } $app = new Silex\Application(); $app['debug'] = true; $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('tamagotchi.html.twig', array('tamagotchi' => Tamagotchi::getAll())); }); $app->post("/tamagotchi", function () use($app) { $tamagotchi = new Tamagotchi($_POST['name']); $tamagotchi->save(); return $app['twig']->render('create_name.html.twig', array('newtamagotchi' => $tamagotchi)); }); $app->post("/kill_tamagotchi", function () use($app) { Tamagotchi::deleteAll(); return $app['twig']->render('kill_tamagotchi.html.twig'); }); $app->post("/feed_tamagotchi", function () use($app) { $_SESSION['state_of_tamagotchi'][0]->setFood($_SESSION['state_of_tamagotchi'][0]->getFood() + 10); /* Tamagotchi::setFood() = Tamagotchi::getFood() + 10; Tamagotchi::save(); */ return $app['twig']->render('tamagotchi.html.twig', array('tamagotchi' => Tamagotchi::getAll())); }); $app->post("/play_tamagotchi", function () use($app) {