Permalink
Browse files

here's a bunch of code, bros

  • Loading branch information...
1 parent 6f51df4 commit 16fb821905c4375c80d5011ccbb0c92b4aa37943 @rickyrobinett committed Sep 23, 2011
Showing with 331 additions and 0 deletions.
  1. +102 −0 css/styles.css
  2. +11 −0 endgame.php
  3. +19 −0 gather.php
  4. +8 −0 getmove.php
  5. BIN images/controls.png
  6. BIN images/logo.png
  7. +24 −0 includes/memcache.php
  8. +121 −0 index.php
  9. +37 −0 move.php
  10. +9 −0 start.xml
View
@@ -0,0 +1,102 @@
+/* General Styles
+=================================*/
+* {
+ margin: 0px;
+ padding: 0px;
+ margin: 0 auto;
+}
+
+body {
+ background: #000000;
+ font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
+ font-size: 12px;
+
+ margin: 0 auto;
+}
+
+.clear {
+ clear: both;
+}
+
+
+/* Layout
+=================================*/
+
+#wrapper {
+ width: 750px;
+ margin-top:-17px;
+}
+
+#wrapper img.logo {
+ display: block;
+ margin-top: 30px;
+ margin-left: 52px;
+ margin-right: auto;
+ z-index:1
+}
+
+#main_box {
+ margin-top: 45px;
+}
+
+#main_box h1 {
+ color: #f7ff1c;
+ font-size: 18px;
+ font-weight: normal;
+ line-height: 18px;
+ margin: 0px 0px 10px 65px;
+}
+
+#main_box .highlight {
+ background-color: #f7ff1c;
+ color: #000000;
+ font-weight: bold;
+ padding: 0px 3px
+}
+
+
+#game_wrapper {
+ /*width: 495px;*/
+ height: 400px;
+ border: 1px #23d200 solid;
+ margin-left: 65px;
+ float: left;
+}
+
+#sidebar {
+ width: 170px;
+ float:right
+}
+
+#sidebar p {
+ font-size: 14px;
+ font-weight: bold;
+ color: #f7ff1c;
+ text-align:center;
+ margin-bottom: 15px;
+}
+
+#sidebar p.small {
+ font-size: 12px;
+ font-weight: normal;
+ color: #f7ff1c;
+ text-align:center;
+ margin-top: 5px;
+}
+
+#footer_wrapper {
+ margin: 30px 0px;
+}
+
+#footer_wrapper p {
+ width: 650px;
+ font-size: 12px;
+ color: #7c7878;
+ padding-left:30px;
+}
+
+#footer_wrapper a {
+ color: #7c7878;
+}
+
+
View
@@ -0,0 +1,11 @@
+<?php
+ require_once("includes/memcache.php");
+ $memcache = new RR_Memcache();
+ $callKey = $_REQUEST['callKey'];
+
+ $memcache->set($callKey,"stop");
+ echo '<?xml version="1.0" encoding="UTF-8"?>'
+?>
+<Response>
+ <Hangup />
+</Response>
View
@@ -0,0 +1,19 @@
+<?php
+ if(isset($_REQUEST['Digits'])){
+ $callKey = $_REQUEST['Digits'];
+ } else {
+ $callKey = $_REQUEST['callKey'];
+ }
+echo '<?xml version="1.0" encoding="UTF-8"?>'
+?>
+<Response>
+ <Gather action="/move.php?callKey=<?php echo $callKey; ?>" method="GET" numDigits="1" timeout="30">
+ <Say>
+ Which direction would you like to move?
+ </Say>
+ </Gather>
+ <Say>You were too slow. A dragon ate you.</Say>
+ <Redirect method="POST">
+ /endgame.php?callKey=<?php echo $callKey; ?>
+ </Redirect>
+</Response>
View
@@ -0,0 +1,8 @@
+<?php
+ require_once("includes/memcache.php");
+ $memcache = new RR_Memcache();
+ $callKey = $_REQUEST['callKey'];
+
+ $aResponse = array("move"=>$memcache->get($callKey));
+ echo json_encode($aResponse);
+?>
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,24 @@
+<?php
+
+class RR_Memcache{
+ static public $host = "127.0.0.1";
+ static public $memc;
+
+ public function __construct(){
+ // let's make this a singleton
+ if(isset($memc)){
+ return $this;
+ }
+
+ self::$memc = new Memcache;
+ self::$memc->addServer(self::$host);
+ }
+
+ public function set($key,$value){
+ self::$memc->set($key,$value,2);
+ }
+
+ public function get($key){
+ return self::$memc->get($key);
+ }
+}
View
121 index.php
@@ -0,0 +1,121 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<?php
+ $callKey = rand(1000,9999);
+ $rows = 20;
+ $cols = 24;
+?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta name="DESCRIPTION" content="" />
+ <title>Twilio Snake!</title>
+ <link href="css/styles.css" rel="stylesheet" type="text/css"/>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
+ <script>
+ var pos = {};
+ pos[0] = 0;
+ pos[1] = 0;
+ var pastMoves = [];
+ pastMoves[0] = '0-0';
+
+ function getMove(){
+ $.ajax({
+ type: "GET",
+ url: "getmove.php",
+ data: "callKey=<?php echo $callKey; ?>",
+ dataType: "json",
+ success: function(data) {
+ doMove(data.move);
+ }/*,
+ complete: function(msg) {
+ setTimeout("getMove()","500");
+ }*/
+ });
+ }
+
+ function pauseGame(){
+ // do some work here
+ }
+
+ function isValidMove(nextPos){
+ // check for previous moves
+ if($.inArray(nextPos[0]+'-'+nextPos[1],pastMoves)!=-1){
+ return false;
+ }
+
+ // check for out of bounds
+ if(nextPos[0] < 0 || nextPos[0] > <?php echo $rows; ?> || nextPos[1] < 0 || nextPos[1] > <?php echo $cols; ?>){
+ return false;
+ }
+
+ return true;
+ }
+
+ function doMove(direction){
+ switch(direction){
+ case "up":
+ pos[0] = pos[0]-1;
+ break;
+ case "down":
+ pos[0] = pos[0]+1;
+ break;
+ case "left":
+ pos[1] = pos[1]-1;
+ break;
+ case "right":
+ pos[1] = pos[1]+1;
+ break;
+ default:
+ setTimeout("getMove()","500");
+ return false;
+ break;
+ }
+ if(!isValidMove(pos)){
+ alert("you died");
+ return false;
+ }
+ pastMoves[pastMoves.length] = pos[0]+'-'+pos[1];
+ setTimeout("getMove()","500");
+
+ $("#pos"+pos[0]+"-"+pos[1]).css("background-color","#FF0000");
+
+ return true;
+ }
+
+ $(document).ready(function(){
+ setTimeout("getMove()","1000"); /* kick off the short polling in 1 second */
+ $("#pos0-0").css("background-color","#FF0000");
+ });
+ </script>
+
+ </head>
+ <body>
+ <div id="water_bg"></div>
+ <div id="wrapper">
+ <img src="images/logo.png" width="513" height="116" alt="Twilio Snake!" class="logo" />
+ <div id="main_box">
+ <h1>Call <span class="highlight">(718) 412-8151</span> and enter game code <span class="highlight"><?php echo $callKey; ?></span> to play!</h1>
+ <div id="game_wrapper">
+ <?php
+ for($r=0;$r < $rows;$r++) {
+ if($r!=0){
+ echo "<br style='clear:both;'>";
+ }
+ for($c=0;$c < $cols;$c++) {
+ echo "<div class='square' style='width:20px;height:20px;float:left;' id='pos".$r."-".$c."'></div>";
+ }
+ }
+ ?>
+ </div>
+ <div id="sidebar">
+ <p>Phone Keypad Controls</p>
+ <img src="images/controls.png" width="160" height="152" alt="" class="controls" />
+ <p class="small">Pause = any other key</p>
+ </div>
+ </div>
+ <br class="clear" />
+ </div>
+ <div id="footer_wrapper">
+ <p>Created by <a href="http://rickyrobinett.com" target="_blank">Ricky Robinett</a></p>
+ </div>
+ </body>
+</html>
View
@@ -0,0 +1,37 @@
+<?php
+require_once("includes/memcache.php");
+// do some quick setup
+$memcache = new RR_Memcache();
+$callKey = $_REQUEST['callKey'];
+
+echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+echo "<Response><Say>";
+
+ switch($_REQUEST['Digits']){
+ case 2:
+ echo "up";
+ $memcache->set($callKey,"up");
+ break;
+ case 4:
+ echo "left";
+ $memcache->set($callKey,"left");
+ break;
+ case 6:
+ echo "right";
+ $memcache->set($callKey,"right");
+ break;
+ case 8:
+ echo "down";
+ $memcache->set($callKey,"down");
+ break;
+ default:
+ echo "pause";
+ $memcache->set($callKey,"pause");
+ break;
+ }
+ echo '</Say>'
+?>
+ <Redirect method="POST">
+ /gather.php?callKey=<?php echo $callKey; ?>
+ </Redirect>
+</Response>
View
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Response>
+ <Gather action="/gather.php" method="GET" numDigits="4">
+ <Say>
+ Welcome to Twilio Snake! Please enter your game code.
+ </Say>
+ </Gather>
+ <Say>We didn't receive any input. Goodbye!</Say>
+</Response>

0 comments on commit 16fb821

Please sign in to comment.