Advertisement
omnilynx

Amot'l Paa

Feb 10th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head><title>Amot'l Paa</title></head>
  3. <body>
  4. <script src="http://davidbau.com/encode/seedrandom-min.js"></script> <!-- because Math.random() is stupid -->
  5. <script type="text/javascript">
  6.     var SESSION_SEED = Math.random();
  7.     Player = new Object();
  8.     Player.x = 0;
  9.     Player.y = 0;
  10.    
  11.     function respondToUser() {
  12.         setMessage("");
  13.        
  14.         var input = document.getElementById("input");
  15.         switch (input.value.trim().toLowerCase()) {
  16.             case "n": case "north":
  17.                 movePlayer(0,1);
  18.                 break;
  19.             case "s": case "south":
  20.                 movePlayer(0,-1);
  21.                 break;
  22.             case "e": case "east":
  23.                 movePlayer(1,0);
  24.                 break;
  25.             case "w": case "west":
  26.                 movePlayer(-1,0);
  27.                 break;
  28.             default:
  29.                 setMessage("You can't do that!");
  30.         }
  31.        
  32.         input.value = "";
  33.         return false;
  34.     }
  35.    
  36.     function setMessage(text) {
  37.         var message = document.getElementById("message");
  38.         if (text.trim().length > 0) {
  39.                 message.style.display = "";
  40.                 message.innerHTML = text;
  41.         } else {
  42.                 message.style.display = "none";
  43.         }
  44.     }
  45.    
  46.     function movePlayer(x, y) {
  47.         if (shallPass(Player.x+x/2,Player.y+y/2)) {
  48.             Player.x += x;
  49.             Player.y += y;
  50.         } else {
  51.             setMessage("You can't go that way!");
  52.         }
  53.        
  54.         describeLocation();
  55.         showCommands();
  56.     }
  57.    
  58.     function seedLocationSet(x,y,set) {
  59.         set = (typeof set == "undefined")? 0 : set;
  60.         Math.seedrandom(SESSION_SEED);
  61.         Math.seedrandom(Math.random() + x);
  62.         Math.seedrandom(Math.random() + y);
  63.         Math.seedrandom(Math.random() + set);
  64.     }
  65.    
  66.     function shallPass(x, y) {
  67.         if (Math.round(x/2)==0 && Math.round(y/2)==0) { return true; }
  68.         seedLocationSet(x, y)
  69.         return (Math.random() > 0.4);
  70.     }
  71.    
  72.     function getLocationFeature(size, set) {
  73.         var bozoX = 0;
  74.         var bozoY = 0;
  75.         for (var i = size; i > 0.25; i = i/2) {
  76.             seedLocationSet(Math.round(Player.x/i), Math.round(Player.y/i), set);
  77.             bozoX += Math.random()*i - i/2;
  78.             bozoY += Math.random()*i - i/2;
  79.         }
  80.         seedLocationSet(Math.round((Player.x+bozoX)/size), Math.round((Player.y+bozoY)/size), set)
  81.         return Math.random();
  82.     }
  83.    
  84.     function describeLocation() {
  85.         var description = "(" + Player.x + "," + Player.y + ") You are standing ";
  86.         if (Player.x == 0 && Player.y == 0) {
  87.             description += "in a dark, featureless room with four exits.";
  88.         } else {
  89.             var setting = getLocationFeature(5, 'setting');
  90.             var outside = false;
  91.             if (setting >= 0 && setting < 0.2) {
  92.                 description += "in a dark, featureless room. ";
  93.             } else if (setting >= 0.2 && setting < 0.4) {
  94.                 description += "on a dirt path surrounded by hedges. ";
  95.                 outside = true;
  96.             } else if (setting >= 0.4 && setting < 0.5) {
  97.                 description += "in the middle of a small bright clearing. ";
  98.                 outside = true;
  99.             }  else if (setting >= 0.5 && setting < 0.9) {
  100.                 description += "in a thick, tangled wood. ";
  101.             } else if (setting >= 0.9 && setting < 1) {
  102.                 description += "in a strange, foggy pocket dimension. ";
  103.             }
  104.            
  105.             if (outside) {
  106.                 var weather = getLocationFeature(15, 'weather');
  107.                 if (weather >= 0 && weather < .4) {
  108.                     description += "There are a few clouds in the sky. You can't tell if it's early morning or late evening. ";
  109.                 } else if (weather >= 0.4 && weather < .6) {
  110.                     description += "Roiling clouds lower in the sky. ";
  111.                 } else if (weather >= 0.6 && weather < .7) {
  112.                     description += "The sky is a bright, clear blue. ";
  113.                 } else if (weather >= 0.7 && weather < .9) {
  114.                     description += "A panoply of stars glitters above you. ";
  115.                 }
  116.             }
  117.            
  118.             var item = getLocationFeature(1, 'item');
  119.             if (item >= 0 && item < 0.1) {
  120.                 description += "There is a pile of useless stones on the ground. ";
  121.             } else if (item >= 0.1 && item < 0.2) {
  122.                 description += "Beside you is a large gold statue. It is too heavy to lift.";
  123.             }
  124.         }
  125.        
  126.         document.getElementById("description").innerHTML = description;
  127.     }
  128.    
  129.     function showCommands() {
  130.         var commands = "";
  131.        
  132.         if (shallPass(Player.x,Player.y+0.5)) {
  133.             commands += "(n)orth, ";
  134.         }
  135.         if (shallPass(Player.x,Player.y-0.5)) {
  136.             commands += "(s)outh, ";
  137.         }
  138.         if (shallPass(Player.x+0.5,Player.y)) {
  139.             commands += "(e)ast, ";
  140.         }
  141.         if (shallPass(Player.x-0.5,Player.y)) {
  142.             commands += "(w)est, ";
  143.         }
  144.        
  145.         if (commands.length > 1) { commands = commands.substring(0,commands.length - 2); }
  146.        
  147.         document.getElementById("commands").innerHTML = commands;
  148.     }
  149. </script>
  150.  
  151. <div id="description"><span style="color:Green;">~ Welcome to Amot'l Paa! ~</span><br>
  152.  
  153. You are standing in a dark, featureless room with four exits.</div>
  154.  
  155. <div style="color:Blue;">Commands are: <span id="commands">(0,0) (n)orth, (s)outh, (e)ast, (w)est</span></div>
  156. <div id="message" style="color:Red;display:none;"></div>
  157. <form onsubmit="return respondToUser();">
  158. <input type="text" name="input" id="input" /> <input type="submit" value="Submit" />
  159. </form>
  160. </body>
  161. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement