Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <title>The Pack</title>
  3. <img src="" width="300" height="267">
  4. <p id="output"></p>
  5. <input id="input" type="text" placeholder="Enter your action...">
  6. <button>enter</button>
  7. <script>
  8.     //Map
  9.  
  10.     var map = [];
  11.     map[0] = "River.Good place to carch salmon.";
  12.     map[1] = "Village.Beware people don't like to see wolfs near them,";
  13.     map[2] = "Elks.Our main food source.";
  14.     map[3] = "Bear den . Our greatest enemy watch your self.";
  15.     map[4] =  "Den.Home sweet Home";
  16.     map[5] = "Path leading to home ";
  17.     map[6] = "Oak tree";
  18.     map[7] = "Hunting cottge.Beware hunters are near";
  19.         map[8] = "Deer carcus";
  20.  
  21.     var image = [];
  22.     image[1] = "river.png";
  23.     image[2] = "town.png";
  24.     image[3] = "elk.png";
  25.     image[4] = "bear.png";
  26.     image[5] = "den.png";
  27.     image[6] = "path.png";
  28.     image[7] = "oak.png";
  29.     image[8] = "carcus.png";
  30.  
  31.     //Player's start location
  32.  
  33.     var mapLocation = 4;
  34.  
  35.     //Game Message diplayer
  36.  
  37.     var gameMessage = "";
  38.     var playerInput = "";
  39.    
  40.     //actions player can do
  41.     var actionsKnown = ["south","north","east","west"];
  42.     var action = "";
  43.  
  44.     //output and input element
  45.     var output = document.querySelector("#output");
  46.     var input = document.querySelector("#input");
  47.  
  48.     //image
  49.  
  50.     var image = document.querySelector("img");
  51.    
  52.     //button
  53.     var button = document.querySelector("button");
  54.     button.style.cursor = "pointer";    
  55.     button.addEventListener("click",clickHandler,false);
  56.     //rendering game
  57.  
  58.     render();
  59.  
  60.     function clickHandler()
  61.     {
  62.         play();
  63.     }
  64.  
  65.     function play()
  66.     {
  67.         playerInput = input.value;
  68.         playerInput.toLowerCase();
  69.  
  70.         //reseting previous gameplayes
  71.  
  72.         action = "";
  73.         gameMessage = "";
  74.    
  75.         for (i=0; i<actionsKnown.length;i++)
  76.         {
  77.             if(playerInput.indexOf(actionsKnown[i])!==-1)
  78.             {
  79.                 action = actionsKnown[i];
  80.                 console.log("player action is"+action);
  81.                 break;
  82.             }
  83.         }
  84.     switch(action)
  85.     {
  86.         case "north":
  87.             mapLocation -= 3;
  88.             break;
  89.        
  90.         case "south":
  91.             mapLocation += 3;
  92.             break;
  93.  
  94.         case "east":
  95.             mapLocation +=1;
  96.             break;
  97.        
  98.         case "west":
  99.             mapLocation -= 1;
  100.             break;
  101.  
  102.         default:
  103.             gameMessage = "what the heck is that";
  104.     }
  105.     render();
  106. }
  107.  
  108.     function render()
  109.     {
  110.         output.innerHTML = map[mapLocation];
  111.         image.src = "D:/Game Development/Games/The Pack/images/"+image[mapLocation];
  112.         //Display the game message
  113.         output.innerHTML += "<br><em>" + gameMessage + "</em>";
  114.  
  115.     }
  116.  
  117.  
  118. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement