textFeaturesMain.js
1    "use strict"; 
2    var rooms; 
3    var player; 
4    var passcode = {}; 
5    startGame(); 
6     
7
function startGame() 8 { 9 //reset the global rooms and player objects 10 rooms = getRooms(); 11 player = getPlayer(); 12 rooms = randomizeRoomLayout(rooms); //optional feature 13 rooms = randomizeBrokenThings(rooms); //optional feature (requires randomizeItems) 14 randomizePlayerStart(rooms); //optional feature 15 randomizeItems(rooms); //optional feature 16 randomizePoints(rooms); //optional feature 17 passcode = getPasscode(rooms); //optional feature 18 randomizeExits(rooms); //optional feature (part of passcode feature) 19 20 //This explains the game to a new player 21 var text = "Welcome to the Room Adventure!"; 22 text += "You are " + player.name; 23 text += " and you are locked in a house"; 24 text += " where many things are broken."; 25 text += " Go from room to room"; 26 text += " to find the items you need"; 27 text += " to fix what's broken."; 28 text += " Earn points for fixing things."; 29 text += " There are " + player.itemsLeftToFix; 30 text += " things that need to be fixed."; 31 text += " Along the way, you will find pieces"; 32 text += " of a passcode. Find the exit, and"; 33 text += " enter the correct passcode to win!"; 34 text += " You start in the "; 35 text += player.currentRoom.name + "."; 36 text += " Good luck!"; 37 38 alert(text); 39 40 //move the player into their current room 41 //to display the description and start the game 42 moveToRoom(); 43 } 44
45
function getPlayer() 46 { 47 var player = 48 { 49 name: "Lica", 50 score: 0, 51 currentRoom: rooms["living room"], 52 inventory: [], 53 itemsLeftToFix: 10, 54 maxScore: 0, 55 pathTaken: [] 56 }; 57 return player; 58 } 59 60
61
function moveToRoom() 62 { 63 player.pathTaken.push(player.currentRoom); 64 65 textRoomDescription(); 66 showItemInRoom(); //update from isThereAnItem 67 showBrokenThing(); //update from fixBrokenThing 68 showScore(); 69 showInventory(); 70 71 //most of this is different 72 var direction = getDirection(); 73 74 if (!direction) 75 { 76 //player typed quit, don't do anything, exit game 77 } 78 else if (direction === "take") //take item 79 { 80 isThereAnItem(); 81 moveToRoom(); 82 } 83 else if (direction === "exit") //add this block 84 { 85 var guessPasscode = prompt("What's the passcode?"); 86 if (guessPasscode === passcode.exitCode) 87 { 88 alertGameWon(); 89 checkPlayAgain(); 90 } 91 else 92 { 93 alert("Sorry, that is not the correct passcode. You lose " + passcode.penalty + " points."); 94 player.score -= passcode.penalty; 95 moveToRoom(); 96 } 97 } 98 else if (direction.indexOf("use ") !== -1) //use item 99 { 100 var useItem = direction.substring(4); 101 fixBrokenThing(useItem); 102 moveToRoom(); 103 } 104 else //move player 105 { 106 player.currentRoom = rooms[direction]; 107 moveToRoom(); 108 } 109 } 110
111
function textRoomDescription() 112 { 113 var text = ""; 114 text += "You are in the "; 115 text += player.currentRoom.name + ". "; 116 text += player.currentRoom.description; 117 alert(text); 118 } 119
120
function showItemInRoom() 121 { 122 if (player.currentRoom.itemFound) 123 { 124 alert("You see something useful in here."); 125 } 126 } 127
128
function isThereAnItem() 129 { 130 var item = player.currentRoom.itemFound; 131 if (item) 132 { 133 alert("You found the " + item + "!"); 134 player.inventory.push(item); 135 player.currentRoom.itemFound = null; 136 } 137 else 138 { 139 alert("There's nothing to take. You lose 5 points."); 140 player.score -= 5; 141 } 142 } 143
144
function showBrokenThing() 145 { 146 //helper variables to make the code easier to read 147 var brokenThing = player.currentRoom.brokenThing; 148 149 //test: Is there a broken thing? 150 if (brokenThing) 151 { 152 //get ready to announce there's a broken thing 153 var text = "There is a broken "; 154 text += brokenThing + " in this room. "; 155 alert(text); 156 } 157 } 158
159
function fixBrokenThing(fixWith) 160 { 161 //helper variable 162 var index = player.inventory.indexOf(fixWith); 163 var brokenThing = player.currentRoom.brokenThing; 164 var text = ""; 165 166 if (!brokenThing) 167 { 168 text += "There's nothing to fix in here! "; 169 text += "You lose 10 points. "; 170 player.score -= 10; 171 } 172 173 //test: if fixWith is NOT in inventory 174 else if (index === -1) 175 { 176 text += "You're not carrying a " + fixWith + ". "; 177 text += "You lose 5 points."; 178 player.score -= 5; 179 180 } 181 else if (fixWith !== player.currentRoom.fixWith) 182 { 183 text += "The " + fixWith + " won't fix "; 184 text += "the " + brokenThing + ". "; 185 text += "You lose 15 points."; 186 player.score -= 15; 187 } 188 189 else //the item IS in the inventory 190 { 191 if (playerIsTired()) //optional feature 192 { 193 text += "You try to fix the " + brokenThing; 194 text += " but you feel fatigued and couldn't."; 195 text += " You lose 5 points. Try again. "; 196 player.score -= 5; 197 } 198 else 199 { 200 text += "You fixed the " + brokenThing; 201 text += " with the " + fixWith + "!"; 202 text += " You earn "; 203 text += player.currentRoom.points; 204 text += " points."; 205 206 player.currentRoom.brokenThing = null; 207 208 //Feature: Getting More Descriptive 209 if (player.currentRoom.altDescription) 210 { 211 player.currentRoom.description = 212 player.currentRoom.altDescription; 213 } 214 215 player.score += player.currentRoom.points; 216 player.itemsLeftToFix--; 217 player.inventory.splice(index, 1); 218 if (player.currentRoom.passcodeHint) 219 { 220 text += " You found a piece of the passcode! "; 221 text += player.currentRoom.passcodeHint; 222 player.inventory.push(player.currentRoom.passcodeHint); 223 } 224 } 225 } 226 alert(text); 227 } 228
229
//Feature: Making the Player Tired 230 function playerIsTired() 231 { 232 var items = player.inventory.length; 233 var fixes = player.itemsLeftToFix; 234 var steps = 0; 235 236 if (player.pathTaken) 237 { 238 steps = player.pathTaken.length; 239 } 240 var tiredness = items + steps - fixes; 241 var effort = Math.min(tiredness, 25); 242 var threshold = Math.floor(Math.random() * effort); 243 244 return threshold > 15; 245 } 246
247
function showScore() 248 { 249 player.score = Math.max(0, player.score); 250 var text = "Score: " + player.score; 251 252 //if there is a maxScore tally, then show it 253 if (player.maxScore > 0) 254 { 255 text += " / Max: " + player.maxScore; 256 } 257 258 alert(text); 259 } 260
261
function showInventory() 262 { 263 var text = "Inventory: "; 264 265 var length = player.inventory.length; 266 267 for (var i = 0; i < length; i++) 268 { 269 text += "["; 270 text += player.inventory[i]; 271 text += "] "; 272 } 273 274 alert(text); 275 } 276
277
function checkGameOver() 278 { 279 return player.itemsLeftToFix === 0; 280 } 281
282
function alertGameWon() 283 { 284 var text = "Congratulations, " + player.name +"! "; 285 text += "You entered the correct passcode "; 286 text += "and escaped the house! "; 287 288 text += "You earn " + passcode.reward + " points! "; 289 player.score += passcode.reward; 290 291 text += "You finished the game with a score of "; 292 text += player.score + " points! "; 293 text += "Play again soon!"; 294 295 var path = "Here's how you traversed the house: "; 296 var steps = player.pathTaken.length; 297 for (var i = 0; i < steps; i++) 298 { 299 var room = player.pathTaken[i]; 300 path += room.name; 301 if (i < steps - 1) 302 { 303 path += " --> "; 304 } 305 } 306 307 text += " ***** " + path + " ***** "; 308 309 alert(text); 310 } 311
312
function checkPlayAgain() 313 { 314 var text = "Would you like to play again? "; 315 text += "Click OK to replay. "; 316 text += "Click CANCEL to end. "; 317 318 var again = confirm(text); 319 if (again) 320 { 321 startGame(); 322 } 323 } 324
325
function getDirection() 326 { 327 var text = "Take an item from the room using [take]. "; 328 text += "Use an item in the room with [use item], "; 329 text += "such as 'use batteries'. "; 330 text += "You can also move to a new room. "; 331 332 var direction; 333 334 while (!direction) 335 { 336 text += "There are exits: "; 337 for (var exit in player.currentRoom.exits) 338 { 339 text += "[" + exit + "]"; 340 } 341 342 if (player.currentRoom.exitHouse) 343 { 344 text += "[ exit house ]"; 345 } 346 347 direction = prompt(text); 348 349 if (direction.indexOf("use ") !== -1) 350 { 351 return direction; 352 } 353 354 direction = direction.toLowerCase(); 355 356 if (player.currentRoom.exitHouse && direction.indexOf("exit") !== -1) 357 { 358 return "exit"; 359 } 360 361 if (direction.indexOf("take") !== -1) 362 { 363 return "take"; 364 } 365 366 367 368 var exitTo = player.currentRoom.exits[direction]; 369 370 if (rooms[exitTo]) 371 { 372 //we CAN go this way, send back the exitTo 373 return exitTo; 374 } 375 else if (direction === "quit") 376 { 377 break; 378 } 379 text = "You can't go " + direction + ". "; 380 text += "Please try again. "; 381 text += "Use compass points like north."; 382 direction = null; 383 } 384 } 385
386
//Feature: Randomizing the Player's Start Room 387 function randomizePlayerStart(availableRooms) 388 { 389 //create an array of available rooms 390 var roomsArray = []; //this starts empty 391 for (var roomName in availableRooms) 392 { 393 var roomToAdd = availableRooms[roomName]; 394 roomsArray.push(roomToAdd); 395 } 396 397 //randomly pick one room and assign the player to it 398 var length = roomsArray.length; 399 var index = Math.floor(Math.random() * length); 400 player.currentRoom = roomsArray[index]; 401 } 402
403
//Feature: Randomizing the Item Locations 404 function randomizeItems(availableRooms) 405 { 406 player.itemsLeftToFix = 0; 407 408 //we need to make a list of fixWith items, start empty 409 var items = []; 410 411 //loop through all the rooms that are available 412 for (var roomName in availableRooms) 413 { 414 //helper variable for code clarity 415 var room = availableRooms[roomName]; 416 417 //if you ever set a room without something broken 418 //then skip the code and jump to the top of the loop 419 if (!room.brokenThing) 420 { 421 room.fixWith = null; 422 continue; 423 } 424 player.itemsLeftToFix++; 425 426 //add the fixWith item from each room 427 //to the new items array 428 items.push(room.fixWith); 429 } 430 431 //now loop again through the available rooms 432 for (var roomName in availableRooms) 433 { 434 //if there are no items left to place, clear other default items 435 if (items.length === 0) 436 { 437 availableRooms[roomName].itemFound = null; 438 continue; 439 } 440 441 //pick a random fixWith item from the items array the items array will shrink each time through loop 442 var index = Math.floor(Math.random() * items.length); 443 444 //set the random item to the current room 445 //the loop is in 446 availableRooms[roomName].itemFound = items[index]; 447 448 //remove the fixWith item from the items array 449 //so we don't put it into two places at once 450 items.splice(index, 1); 451 } 452 } 453
454
//Feature: Randomizing the Point Values 455 function randomizePoints(availableRooms) 456 { 457 //we need to tally the total point value 458 var maxScore = 0; 459 460 //loop through all the rooms that are available 461 for (var roomName in availableRooms) 462 { 463 //helper variable for code clarity 464 var room = availableRooms[roomName]; 465 466 //helper variable that gets the point value for item 467 var base = room.points; 468 469 //get a random number from 0 to base point value 470 //add that to the base point value 471 var value = Math.floor(Math.random() * base) + base; 472 473 //set the room's point value to the new value 474 room.points = value; 475 476 //add these new points to the total point tally 477 maxScore += value; 478 } 479 480 //let the player carry the total point value 481 //just like the player carries the score 482 player.maxScore = maxScore; 483 484 return availableRooms; 485 } 486
487
//Feature: Randomizing Broken Things 488 function randomizeBrokenThings(availableRooms) 489 { 490 for (var roomName in availableRooms) 491 { 492 var room = availableRooms[roomName]; 493 494 //helper object: make sure default set can be used 495 var original = 496 { 497 brokenThing: room.brokenThing, 498 fixWith: room.fixWith, 499 points: room.points, 500 altDescription: room.altDescription 501 }; 502 503 var brokenThings = [original]; //put default on list 504 505 if (room.brokenArray) 506 { 507 brokenThings = brokenThings.concat(room.brokenArray); 508 } 509 510 var brokenLength = brokenThings.length; 511 512 //pick a random thing 513 var index = Math.floor(Math.random() * brokenLength); 514 var chosenThing = brokenThings[index]; 515 516 room.brokenThing = chosenThing.brokenThing; 517 room.fixWith = chosenThing.fixWith; 518 room.points = chosenThing.points; 519 room.altDescription = chosenThing.altDescription; 520 } 521 return availableRooms; 522 } 523
524
//Feature: Create Passcode Ending 525 function getPasscode(availableRooms) 526 { 527 //reset the global password object 528 passcode = 529 { 530 reward: 100, 531 penalty: 25, 532 exitCode: "", //full unlock code 533 codes: [], //pieces of the code 534 rooms: [] //list of rooms with passcode pieces 535 }; 536 537 var numberOfCodes = 3; 538 var digitsPerCode = 3; 539 540 //create a set of hints 541 var clues = ["apples", "berries", "cherries", "dragon fruits", "emu berries", "forest strawberries", 542 "golden apples", "honeydews", "ilamas", "junglesop", "kumquats", "lemons", "mandarins", "nectarines", 543 "olives", "papaya", "quince", "rangpurs", "strawberries", "tomato", "vanilla", "watermelon", 544 "youngberry", "zucchini"]; 545 546 var hints = []; 547 for (var i = 0; i < numberOfCodes; i++) 548 { 549 var index = 550 Math.floor(Math.random() * clues.length); 551 hints.push(clues[index]); 552 clues.splice(index, 1); 553 } 554 hints.sort(); //alphabetize the list 555 556 //get the codes we need 557 for (var i = 0; i < numberOfCodes; i++) 558 { 559 var code = ""; 560 for (var j = 0; j < digitsPerCode; j++) 561 { 562 code += Math.floor(Math.random() * 10).toString(); 563 } 564 var hint = "{ " + code + " " + hints[i] + " }"; 565 passcode.codes.push(hint); 566 passcode.exitCode += code; 567 } 568 569 //create an array of available rooms 570 var roomsArray = []; 571 for (var roomName in availableRooms) 572 { 573 var roomToAdd = availableRooms[roomName]; 574 if (roomToAdd.brokenThing) 575 { 576 roomsArray.push(roomToAdd); 577 } 578 } 579 580 //put codes into rooms 581 for (var i = 0; i < passcode.codes.length; i++) 582 { 583 var index = Math.floor(Math.random() * roomsArray.length); 584 roomsArray[index].passcodeHint = passcode.codes[i]; 585 passcode.rooms.push(roomsArray[index]); 586 roomsArray.splice(index, 1); 587 } 588 return passcode; 589 } 590
591
//Feature: Randomizing Exits for Passcode 592 function randomizeExits(availableRooms) 593 { 594 //needed variables for the function 595 //rooms we do and do not want to have exits 596 var roomsToInclude = ["living room"]; 597 var roomsToExclude = ["bathroom", "hallway", "den"]; 598 var exits = 2; 599 600 //convert the rooms object into an array 601 var roomsArray = []; 602 for (var roomName in availableRooms) 603 { 604 roomsArray.push(availableRooms[roomName]); 605 } 606 607 //make sure we have enough rooms for exits desired 608 var roomsPossible = 609 roomsArray.length - roomsToExclude.length; 610 var numberOfExits = Math.min(exits, roomsPossible); 611 612 //make sure the rooms we want exits for have them 613 for (var i = 0; i < roomsToInclude.length; i++) 614 { 615 for (var j = 0; j < roomsArray.length; j++) 616 { 617 if (roomsArray[j].name === roomsToInclude[i]) 618 { 619 roomsArray[j].exitHouse = true; 620 numberOfExits--; 621 break; 622 } 623 } 624 } 625 626 //if we have exits left to add, add them 627 while (numberOfExits > 0) 628 { 629 var index = 630 Math.floor(Math.random() * roomsArray.length); 631 var checkExclude = roomsArray[index].name; 632 633 //if the room is on the exclude list, skip it 634 if (roomsToExclude.indexOf(checkExclude) !== -1) 635 { 636 continue; 637 } 638 639 roomsArray[index].exitHouse = true; 640 roomsArray.splice(index, 1); 641 numberOfExits--; 642 } 643 } 644
645
//Feature: Randomizing the Room Layout 646 function randomizeRoomLayout(availableRooms) 647 { 648 //optional: randomly return the original layout 649 if (Math.random() < 0.05) //5% chance 650 { 651 return availableRooms; 652 } 653 654 //create the roomsArray 655 var roomsArray = []; 656 for (var roomName in availableRooms) 657 { 658 //optional: randomly drop a room 659 if (Math.random() < 0.05) //5% chance 660 { 661 continue; 662 } 663 664 roomsArray.push(availableRooms[roomName]); 665 } 666 667 //determine the number of rooms per row 668 var minimum = 3; 669 var maximum = 6; 670 var range = Math.abs(maximum - minimum) + 1; 671 var roomsPerRow = 672 Math.floor(Math.random() * range) + minimum; 673 674 //determine the number of rows of rooms 675 var totalRooms = roomsArray.length; 676 var numberRows = Math.floor(totalRooms / roomsPerRow); 677 numberRows = Math.max(numberRows, 2); 678 679 //initialize two-dimensional 'rows' array 680 var rows = []; 681 for (var i = 0; i < numberRows; i++) 682 { 683 rows[i] = []; //creates an empty array on each row 684 } 685 686 //shuffle rooms into the rows 687 for (var i = 0; i < totalRooms; i++) 688 { 689 var r = Math.floor(Math.random() * roomsArray.length); 690 var row = i % numberRows; //alternate between rows 691 692 rows[row].push(roomsArray[r]); //add room to row 693 roomsArray[r].exits = {}; //erase existing exits 694 roomsArray.splice(r, 1); //remove room from list 695 } 696 697 //minimum number of rooms per row is needed to figure 698 //out how many north/south connections to make later 699 var minRoomsPerRow = totalRooms; 700 701 //connect rooms east-through-west across each row 702 for (var i = 0; i < rows.length; i++) // pick a row 703 { 704 var row = rows[i]; //select current row in the loop 705 706 //only keep the smallest number of rooms per row 707 minRoomsPerRow = 708 Math.min(minRoomsPerRow, row.length); 709 710 for (var j = 0; j < row.length; j++) // pick a room 711 { 712 if (j === 0) //west wall of house: no west exit 713 { 714 //row[j] is current room 715 //row[j + 1] is room to the right 716 row[j].exits.east = row[j + 1].name; 717 } 718 else if (j === row.length - 1) //east wall of house 719 { 720 //row[j – 1] is room to the left 721 row[j].exits.west = row[j - 1].name; 722 } 723 else //room is an inner room 724 { 725 //add neighboring room to the left and right 726 row[j].exits.west = row[j - 1].name; //left room 727 row[j].exits.east = row[j + 1].name; //right room 728 } //close else block 729 } //close j loop 730 } 731 732 //choose number of north/south connections 733 //use Math.ceil() to ensure at least 1 connection 734 var connections = Math.ceil(minRoomsPerRow / 2); 735 736 //connect north and south at random along each row pair 737 for (var i = 0; i < rows.length - 1; i++) 738 { 739 for (var j = 0; j < connections; j++) 740 { 741 var index = Math.floor(Math.random() * minRoomsPerRow); 742 743 //at random, make a diagonal connection instead if possible 744 var southeast = rows[i + i][index + 1]; 745 var southwest; 746 if (index > 0) 747 { 748 southwest = rows[i + i][index - 1]; 749 } 750 var connection = Math.floor(Math.random() * 5); 751 752 if (connection === 0 && southwest) 753 { 754 rows[i][index].exits.southwest = southwest.name; 755 southwest.exits.northeast = rows[i][index].name; 756 } 757 else if (connection === 1 && southeast) 758 { 759 rows[i][index].exits.southeast = southeast.name; 760 southeast.exits.northwest = rows[i][index].name; 761 } 762 else 763 { 764 //rows[i] is top room, rows[i + 1] is bottom room 765 rows[i][index].exits.south = rows[i + 1][index].name; 766 rows[i + 1][index].exits.north = rows[i][index].name; 767 } 768 } 769 } 770 //create new 'rooms' object to return 771 var newRoomLayout = {}; 772 for (var i = 0; i < rows.length; i++) //loop the rows 773 { 774 var row = rows[i]; 775 for (var j = 0; j < row.length; j++) //loop the rooms 776 { 777 var room = row[j]; 778 newRoomLayout[room.name] = room; //look familiar? 779 } 780 } 781 return newRoomLayout; 782 } 783
784
function getRooms() 785 { 786 var livingRoom = 787 { 788 name: "living room", 789 brokenThing: "fireplace screen", 790 description: "The leather sofa and fireplace make this a great room for entertaining guests without the distractions of major electronics.", 791 altDescription: "A cozy room. The new fireplace screen keeps the ashes from ruining the floor and burning your guests.", 792 fixWith: "new wire", 793 points: 25, 794 itemFound: "batteries", 795 exits: 796 { 797 north: "dining room", 798 east: "hallway", 799 up: "staircase" 800 }, 801 brokenArray: 802 [ 803 { 804 brokenThing: "sofa", 805 fixWith: "repair kit", 806 points: 30, 807 altDescription: "The fireplace is great to watch now that you can sit comfortably on the sofa again." 808 }, 809 { 810 brokenThing: "lamp", 811 fixWith: "light bulb", 812 points: 15, 813 altDescription: "The room feels so much brighter with the lamp fixed, even without the fireplace aglow." 814 } 815 ], 816 image: 817 { 818 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/livingroom.jpg", 819 caption: "Photo by Outsite Co", 820 link: "https://unsplash.com/photos/R-LK3sqLiBw", 821 linkInfo: "Courtesy: unsplash.com" 822 } 823 }; 824 825 var diningRoom = 826 { 827 name: "dining room", 828 description: "With an expandable table that seats up to ten people, this room is calling out for a party.", 829 altDescription: "It's a lot brighter in here now that the chandelier is lit. Let's eat!", 830 brokenThing: "chandelier", 831 fixWith: "light bulb", 832 points: 15, 833 itemFound: "new wire", 834 exits: 835 { 836 south: "living room", 837 east: "kitchen" 838 }, 839 brokenArray: 840 [ 841 { 842 brokenThing: "plate", 843 fixWith: "new plate", 844 points: 5, 845 altDescription: "The room is a great place to gather for meals, especially with a good set of plates." 846 }, 847 { 848 brokenThing: "chair", 849 fixWith: "folding chair", 850 points: 25, 851 altDescription: "Though not as comfortable as a regular chair, the folding chair lets you sit with family and friends instead of standing for your meals." 852 } 853 ], 854 image: 855 { 856 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/diningroom.jpg", 857 caption: "Photo by Erick Lee Hodge", 858 link: "https://unsplash.com/photos/el_V6z_h5nA", 859 linkInfo: "Courtesy: unsplash.com" 860 } 861 }; 862 863 var kitchen = 864 { 865 name: "kitchen", 866 description: "It needs a little attention, but the kitchen has everything you need to have a snack or host a huge party.", 867 altDescription: "With the faucet fixed, this kitchen is begging to be cooked in.", 868 brokenThing: "faucet", 869 fixWith: "wrench", 870 points: 35, 871 itemFound: "package with color ink", 872 exits: 873 { 874 south: "hallway", 875 west: "dining room", 876 east: "pantry" 877 }, 878 brokenArray: 879 [ 880 { 881 brokenThing: "cabinet", 882 fixWith: "cabinet handle", 883 points: 20, 884 altDescription: "The beautiful kitchen is begging for a great chef to get to work, now that the cabinet is fixed and you can reach the mixing bowls." 885 }, 886 { 887 brokenThing: "refrigerator's ice maker", 888 fixWith: "water filter", 889 points: 35, 890 altDescription: "The refrigerator is the perfect accent to the kitchen. With the new water filter, the ice maker no longer jams and the cubes don't have that funky flavor anymore." 891 } 892 ], 893 image: 894 { 895 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/kitchen.jpg", 896 caption: "Photo by Paul", 897 link: "https://unsplash.com/photos/w2DsS-ZAP4U", 898 linkInfo: "Courtesy: unsplash.com" 899 } 900 }; 901 902 var hallway = 903 { 904 name: "hallway", 905 description: "The hallway helps make the house feel grand, though the old carpet curls up and it's easy to trip over.", 906 altDescription: "With the carpet fixed, you no long trip as you walk this corridor.", 907 brokenThing: "rug", 908 fixWith: "special carpet tape", 909 points: 45, 910 itemFound: "light bulb", 911 exits: 912 { 913 north: "kitchen", 914 east: "office", 915 south: "basement", 916 west: "living room", 917 northeast: "bathroom", 918 southeast: "den" 919 }, 920 brokenArray: 921 [ 922 { 923 brokenThing: "light switch", 924 fixWith: "screwdriver", 925 points: 10, 926 altDescription: "Now that the light switch is reattached to the wall, it's a lot easier to walk the hallway without stumbling." 927 }, 928 { 929 brokenThing: "fire alarm", 930 fixWith: "batteries", 931 points: 35, 932 altDescription: "The hallway feels much more serene now that the fire alarm is working again. There's nothing quite like peace of mind." 933 } 934 ], 935 image: 936 { 937 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/hallway.jpg", 938 caption: "Photo by runnyrem", 939 link: "https://unsplash.com/photos/LfqmND-hym8", 940 linkInfo: "Courtesy: unsplash.com" 941 } 942 }; 943 944 var bathroom = 945 { 946 name: "bathroom", 947 description: "You take pride in your pristine bathroom. It's a relaxing place to take care of necessities.", 948 altDescription: "Though you miss the fun house effect, the bathroom is much more serene with the new mirror.", 949 brokenThing: "mirror", 950 fixWith: "new mirror", 951 points: 20, 952 itemFound: "screwdriver", 953 exits: 954 { 955 southwest: "hallway" 956 }, 957 brokenArray: 958 [ 959 { 960 brokenThing: "toothbrush", 961 fixWith: "new toothbrush", 962 points: 10, 963 altDescription: "The bathroom feels cleaner now that you can brush your teeth properly again. Don't forget to floss!" 964 }, 965 { 966 brokenThing: "soap dispenser", 967 fixWith: "new soap dispenser", 968 points: 20, 969 altDescription: "The gleaming bathroom is even nicer now that you can properly wash your hands again." 970 } 971 ], 972 image: 973 { 974 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/bathroom.jpg", 975 caption: "Photo by Logan Ripley", 976 link: "https://unsplash.com/photos/w8UQkjQ_bS4", 977 linkInfo: "Courtesy: unsplash.com" 978 } 979 }; 980 981 var office = 982 { 983 name: "office", 984 description: "This place is a mess. It's a wonder you ever get any work done in here.", 985 altDescription: "The messy desk is still a mess, but at least you can print up more color pictures of your cats.", 986 brokenThing: "color printer", 987 fixWith: "package with color ink", 988 points: 40, 989 itemFound: "garbage bag", 990 exits: 991 { 992 west: "hallway" 993 }, 994 brokenArray: 995 [ 996 { 997 brokenThing: "ceiling fan light", 998 fixWith: "light bulb", 999 points: 25, 1000 altDescription: "The room may still be a mess but with the light fixed, at least you see everything again." 1001 }, 1002 { 1003 brokenThing: "air conditioner", 1004 fixWith: "clean air filter", 1005 points: 20, 1006 altDescription: "Winter, Spring, Summer, or Fall, you do your best work when the air conditioner filters the air. Ahh, it's great in here." 1007 } 1008 ], 1009 image: 1010 { 1011 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/office.jpg", 1012 caption: "Photo by Annie Spratt", 1013 link: "https://unsplash.com/photos/FSFfEQkd1sc", 1014 linkInfo: "Courtesy: unsplash.com" 1015 } 1016 }; 1017 1018 var basement = 1019 { 1020 name: "basement", 1021 description: "You hide your eyes behind your hands so you don't have to see everything that's out of place down here.", 1022 altDescription: "It's hard to see amidst the clutter, but at least the door isn't squeaky and creepy any more.", 1023 brokenThing: "door hinge", 1024 fixWith: "screwdriver", 1025 points: 30, 1026 itemFound: "catnip", 1027 exits: 1028 { 1029 north: "hallway" 1030 }, 1031 brokenArray: 1032 [ 1033 { 1034 brokenThing: "bicycle tire", 1035 fixWith: "repair kit", 1036 points: 30, 1037 altDescription: "The fireplace is great to watch now that you can sit comfortably on the sofa again." 1038 }, 1039 { 1040 brokenThing: "shelving unit", 1041 fixWith: "nut and bolt", 1042 points: 35, 1043 altDescription: "The basement feels more organized now that the shelving unit is fixed and some of the stuff on the floor has been put away." 1044 } 1045 ], 1046 image: 1047 { 1048 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/basement.jpg", 1049 caption: "Photo by S W", 1050 link: "https://unsplash.com/photos/mNWsZDYUCFs", 1051 linkInfo: "Courtesy: unsplash.com" 1052 } 1053 }; 1054 1055 var den = 1056 { 1057 name: "den", 1058 description: "The den is a comfortable spot to watch TV and catch up on the latest movies.", 1059 altDescription: "The TV and surround sound are much more enjoyable now that the remote control is working.", 1060 brokenThing: "TV remote", 1061 fixWith: "batteries", 1062 points: 10, 1063 itemFound: "wrench", 1064 exits: 1065 { 1066 northwest: "hallway", 1067 south: "cat den" 1068 }, 1069 brokenArray: 1070 [ 1071 { 1072 brokenThing: "window", 1073 fixWith: "pane of glass", 1074 points: 30, 1075 altDescription: "The den is comfortable now that the window is fixed and you can control the temperature again." 1076 }, 1077 { 1078 brokenThing: "massage chair", 1079 fixWith: "extension cord", 1080 points: 20, 1081 altDescription: "The den is a haven where you can watch movies in style, eating popcorn, and enjoying a massage with the Massage-o-Matic 9000." 1082 } 1083 ], 1084 image: 1085 { 1086 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/den.jpg", 1087 caption: "Photo by Daniel Barnes", 1088 link: "https://unsplash.com/photos/z0VlomRXxE8", 1089 linkInfo: "Courtesy: unsplash.com" 1090 } 1091 }; 1092 1093 var catDen = 1094 { 1095 name: "cat den", 1096 description: "An offshoot of another room, the cat den is a place the cats come to play, nap, and meow merrily.", 1097 altDescription: "The cats are rolling around with the catnip one minute, then crashing in a napping heap the next. This spot is a little place of heaven.", 1098 brokenThing: "cat toy", 1099 fixWith: "catnip", 1100 points: 100, 1101 itemFound: "new mirror", 1102 exits: 1103 { 1104 north: "den" 1105 }, 1106 brokenArray: 1107 [ 1108 { 1109 brokenThing: "cat tower", 1110 fixWith: "sisal", 1111 points: 50, 1112 altDescription: "The cats love this room and claw at the sisal every time they walk past it. So much better than ruining the furniture." 1113 }, 1114 { 1115 brokenThing: "treat dispenser", 1116 fixWith: "plastic tray", 1117 points: 15, 1118 altDescription: "Happy cats mean happy houses. The automatic treat dispenser works again and Merlin, Monty, and Shadow can get a little snack throughout the day again when needed." 1119 } 1120 ], 1121 image: 1122 { 1123 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/catden.jpg", 1124 caption: "Photo by Jonathan Fink", 1125 link: "https://unsplash.com/photos/Sa1z1pEzjPI", 1126 linkInfo: "Courtesy: unsplash.com" 1127 } 1128 }; 1129 1130 var pantry = 1131 { 1132 name: "pantry", 1133 description: "You have all shelves organized so you can find the food supplies you need.", 1134 altDescription: "With the spaghetti cleaned up, the shelves look perfect once again.", 1135 brokenThing: "box of spaghetti", 1136 fixWith: "garbage bag", 1137 points: 15, 1138 itemFound: "special carpet tape", 1139 exits: 1140 { 1141 west: "kitchen" 1142 }, 1143 brokenArray: 1144 [ 1145 { 1146 brokenThing: "jar of sauce", 1147 fixWith: "soap and sponge", 1148 points: 30, 1149 altDescription: "The pantry is clean again and there's no evidence of the spilled sauce on the shelves." 1150 }, 1151 { 1152 brokenThing: "spice rack", 1153 fixWith: "new spice rack", 1154 points: 20, 1155 altDescription: "The new spice rack sits perfectly among the boxes of pasta, the mason jars of sauce, and the 25 pound bag of rice." 1156 } 1157 ], 1158 image: 1159 { 1160 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/pantry.jpg", 1161 caption: "Photo by Annie Spratt", 1162 link: "https://unsplash.com/photos/SvBnIWiLbcQ", 1163 linkInfo: "Courtesy: unsplash.com" 1164 } 1165 }; 1166 1167 var smallHall = 1168 { 1169 name: "small hall", 1170 description: "It's a small landing that helps keep the other rooms separated.", 1171 altDescription: "You nailed down the loose plank and now it's quiet as ever.", 1172 brokenThing: "creaky floor", 1173 fixWith: "hammer and nail", 1174 points: 45, 1175 itemFound: "drawer handle", 1176 exits: 1177 { 1178 west: "bedroom", 1179 east: "exercise room", 1180 down: "staircase" 1181 }, 1182 brokenArray: 1183 [ 1184 { 1185 brokenThing: "shoelace", 1186 fixWith: "new laces", 1187 points: 10, 1188 altDescription: "With your laces fixed, the landing looks a little neater." 1189 }, 1190 { 1191 brokenThing: "stool leg", 1192 fixWith: "glue", 1193 points: 25, 1194 altDescription: "The glue really secured the stool leg. Now it doesn't wobble when you tie your shoes." 1195 } 1196 ], 1197 image: 1198 { 1199 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/smallhall.jpg", 1200 caption: "Photo by Christopher Burns", 1201 link: "https://unsplash.com/photos/56tCOHi5OzA", 1202 linkInfo: "Courtesy: unsplash.com" 1203 } 1204 }; 1205 1206 var exercise = 1207 { 1208 name: "exercise room", 1209 description: "It's a great place to work up a sweat and stay in shape.", 1210 altDescription: "With the spaghetti cleaned up, the shelves look perfect once again.", 1211 brokenThing: "scent in the air", 1212 fixWith: "air freshener", 1213 points: 35, 1214 itemFound: "hammer and nail", 1215 exits: 1216 { 1217 west: "small hall" 1218 }, 1219 brokenArray: 1220 [ 1221 { 1222 brokenThing: "exercise mat", 1223 fixWith: "sheet of foam", 1224 points: 20, 1225 altDescription: "The sheet of foam not only cushions your feet, it also reduces some of the noise." 1226 }, 1227 { 1228 brokenThing: "rowing machine", 1229 fixWith: "pull cord", 1230 points: 50, 1231 altDescription: "The rowing machine works again, thanks to the new cord. You've got to get ready for crew!" 1232 } 1233 ], 1234 image: 1235 { 1236 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/exercise.jpg", 1237 caption: "Photo by Jesper Aggergaard", 1238 link: "https://unsplash.com/photos/A97SnfANLeY", 1239 linkInfo: "Courtesy: unsplash.com" 1240 } 1241 }; 1242 1243 var bedroom = 1244 { 1245 name: "bedroom", 1246 description: "It's the most relaxing place you can imagine. And it's almost perfect.", 1247 altDescription: "Once you pull the covers, you drift off to the most wondrous of places now that the room is perfect.", 1248 brokenThing: "dresser drawer", 1249 fixWith: "drawer handle", 1250 points: 25, 1251 itemFound: "air freshener", 1252 exits: 1253 { 1254 east: "small hall" 1255 }, 1256 brokenArray: 1257 [ 1258 { 1259 brokenThing: "pillow", 1260 fixWith: "needle and thread", 1261 points: 20, 1262 altDescription: "The pillow is fixed and ready for you to rest your head and drift off to sleep." 1263 }, 1264 { 1265 brokenThing: "curtain", 1266 fixWith: "curtain rod", 1267 points: 35, 1268 altDescription: "Now you can pull the curtains closed easily and block out the street light so you can sleep deeply." 1269 } 1270 ], 1271 image: 1272 { 1273 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/bedroom.jpg", 1274 caption: "Photo by Michael D Beckwith", 1275 link: "https://unsplash.com/photos/XgOr3b5OOpc ", 1276 linkInfo: "Courtesy: unsplash.com" 1277 } 1278 }; 1279 1280 var staircase = 1281 { 1282 name: "staircase", 1283 description: "It's your favorite place to sit with a glass of iced tea. It's also convenient for getting up and downstairs.", 1284 altDescription: null, 1285 brokenThing: null, 1286 fixWith: null, 1287 points: 0, 1288 itemFound: null, 1289 exits: 1290 { 1291 down: "living room", 1292 up: "small hall" 1293 }, 1294 brokenArray: [], 1295 image: 1296 { 1297 src: "http://coding.stephenjwolf.com/roomadventure/roomimages/staircase.jpg", 1298 caption: "Photo by Won Young Park", 1299 link: "https://unsplash.com/photos/zn7rpVRDjIY", 1300 linkInfo: "Courtesy: unsplash.com" 1301 } 1302 }; 1303 1304 //****************************** 1305 //finish the getRooms() function 1306 //****************************** 1307 1308 var rooms = {}; 1309 rooms[livingRoom.name] = livingRoom; 1310 rooms[diningRoom.name] = diningRoom; 1311 rooms[kitchen.name] = kitchen; 1312 rooms[hallway.name] = hallway; 1313 rooms[bathroom.name] = bathroom; 1314 rooms[office.name] = office; 1315 rooms[basement.name] = basement; 1316 rooms[den.name] = den; 1317 rooms[catDen.name] = catDen; 1318 rooms[pantry.name] = pantry; 1319 rooms[smallHall.name] = smallHall; 1320 rooms[bedroom.name] = bedroom; 1321 rooms[exercise.name] = exercise; 1322 rooms[staircase.name] = staircase; 1323 1324 return rooms; 1325 } 1326