Ejemplo n.º 1
0
<?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));
});
Ejemplo n.º 2
0
<?php

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) {
Ejemplo n.º 3
0
<?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');
Ejemplo n.º 4
0
<?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;
Ejemplo n.º 5
0
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) {
    $_SESSION['list_of_pets'][0]->setMood($_SESSION['list_of_pets'][0]->getMood() + 5);
    return $app['twig']->render('pets.html.twig', array('pets' => Tamagotchi::getAll()));
});
return $app;
Ejemplo n.º 6
0
<?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;
Ejemplo n.º 7
0
// special case: show canvas
if (!$start) {
    echo '<fb:iframe src="http://YOURURL/bigfatpig/?start=1" frameborder=0 width=760 height=600></fb:iframe>';
    exit;
}
// get facebook user id, initialize action
$_GET[pet] = $user;
$path = split("/", $_SERVER['HTTP_REFERER']);
$path[4] = split("\\?", $path[5]);
$action = $path[4][0];
/* get friends which use the app
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.') AND is_app_user = 1';
$_friends = $facebook->api_client->fql_query($fql);
*/
/***************** start the app ********************************************************************************/
$tamagotchi = new Tamagotchi($_GET[pet]);
if ($action == "restart") {
    $tamagotchi->restart($_GET[pet]);
}
$smarty->assign('PETID', $_GET[pet]);
$smarty->display('header.tpl');
if ($tamagotchi->error == "noaccount") {
    $smarty->display('noaccount.tpl');
    exit;
}
$tamagotchi->Calculate();
if ($action == "shower") {
    $showered = $tamagotchi->actionShower();
    $smarty->assign('ACTIONDONE', 'showered');
    $smarty->assign('ACTIONPOINTS', $showered);
    $facebook->api_client->notifications_send($_GET[pet], 'Taken a shower. Yeah.', 'user_to_user');
Ejemplo n.º 8
0
<?php

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()));
});