Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* draw the map on canvas */
- Draw.init();
- Draw.canvasdraw(document.getElementById("Canvas1"));
- /* draws the player on start location */
- Draw.drawmove(document.getElementById("Canvas1"),agent.currPos.x,agent.currPos.y)
- var game = setInterval(gameLoop, 1000);
- /* create a new agent */
- function gameLoop(){
- if(steps > MAX_STEPS) {
- console.log("--------------------------------------");
- console.log("I couldn't find the gold :(");
- console.log("--------------------------------------");
- clearInterval(game);
- }
- /* move */
- agent.move();
- Draw.drawmove(document.getElementById("Canvas1"),"forward",agent.currPos.x,agent.currPos.y);
- Map.gatherAdjacentInfo(agent);
- /* see if the agent is still alive */
- if(Map.tiles[agent.currPos.x][agent.currPos.y].hasPit) {
- console.log("--------------------------------------");
- console.log("Aaaahhhh!");
- console.log("--------------------------------------");
- clearInterval(game);
- }
- if(Map.tiles[agent.currPos.x][agent.currPos.y].hasWumpus) {
- console.log("--------------------------------");
- console.log("Noo! The agent has been eaten by the Wumpus!");
- console.log("--------------------------------------");
- clearInterval(game);
- }
- /*-----------------------------------*/
- steps++;
- /* going back to the start */
- if(agent.hasGold) {
- console.log("--------------------------------------");
- console.log("Going back to the start...");
- console.log("--------------------------------------");
- while(SearchTree.closedList.length > 0) {
- if(agent.currPos.x == 3 && agent.currPos.y == 0) clearInterval(game);
- else {
- agent.goBack();
- Draw.drawmove(document.getElementById("Canvas1"),"backward",agent.currPos.x,agent.currPos.y);
- }
- }
- console.log("--------------------------------------");
- console.log("Woohoo!! I am rich!!");
- console.log("--------------------------------------");
- clearInterval(game);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement