Advertisement
Guest User

Untitled

a guest
Jan 24th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     /* draw the map on canvas */
  3.     Draw.init();
  4.     Draw.canvasdraw(document.getElementById("Canvas1"));
  5.  
  6.     /* draws the player on start location */
  7.     Draw.drawmove(document.getElementById("Canvas1"),agent.currPos.x,agent.currPos.y)
  8.  
  9.     var game = setInterval(gameLoop, 1000);
  10.     /* create a new agent */
  11.     function gameLoop(){
  12.         if(steps > MAX_STEPS) {
  13.             console.log("--------------------------------------");
  14.             console.log("I couldn't find the gold :(");
  15.             console.log("--------------------------------------");
  16.             clearInterval(game);
  17.         }
  18.  
  19.         /* move */
  20.         agent.move();
  21.         Draw.drawmove(document.getElementById("Canvas1"),"forward",agent.currPos.x,agent.currPos.y);
  22.         Map.gatherAdjacentInfo(agent);
  23.  
  24.         /* see if the agent is still alive */
  25.         if(Map.tiles[agent.currPos.x][agent.currPos.y].hasPit) {
  26.             console.log("--------------------------------------");
  27.             console.log("Aaaahhhh!");
  28.             console.log("--------------------------------------");
  29.             clearInterval(game);
  30.         }
  31.  
  32.         if(Map.tiles[agent.currPos.x][agent.currPos.y].hasWumpus) {
  33.             console.log("--------------------------------");
  34.             console.log("Noo! The agent has been eaten by the Wumpus!");
  35.             console.log("--------------------------------------");
  36.             clearInterval(game);
  37.         }
  38.         /*-----------------------------------*/
  39.         steps++;
  40.  
  41.         /* going back to the start */
  42.         if(agent.hasGold) {
  43.             console.log("--------------------------------------");
  44.             console.log("Going back to the start...");
  45.             console.log("--------------------------------------");
  46.  
  47.             while(SearchTree.closedList.length > 0) {
  48.                 if(agent.currPos.x == 3 && agent.currPos.y == 0) clearInterval(game);
  49.                 else {
  50.                     agent.goBack();
  51.                     Draw.drawmove(document.getElementById("Canvas1"),"backward",agent.currPos.x,agent.currPos.y);
  52.                 }
  53.             }
  54.  
  55.             console.log("--------------------------------------");
  56.             console.log("Woohoo!! I am rich!!");
  57.             console.log("--------------------------------------");
  58.             clearInterval(game);
  59.         }
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement