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