crunch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 line
1.3 KiB

  1. let currentRoom = null;
  2. function updateDisplay() {
  3. document.getElementById("location").innerHTML = currentRoom.name;
  4. }
  5. function move(direction) {
  6. let target = currentRoom.exits[direction];
  7. if (target == null) {
  8. alert("Tried to move to an empty room!");
  9. return;
  10. } else {
  11. updateDisplay();
  12. }
  13. }
  14. window.addEventListener('load', function(event) {
  15. loadCompass();
  16. currentRoom = createWorld();
  17. updateDisplay();
  18. });
  19. function loadCompass() {
  20. document.getElementById("compass-north-west").addEventListener("click", function() {
  21. move(NORTH_WEST);
  22. });
  23. document.getElementById("compass-north").addEventListener("click", function() {
  24. move(NORTH);
  25. });
  26. document.getElementById("compass-north-east").addEventListener("click", function() {
  27. move(NORTH_EAST);
  28. });
  29. document.getElementById("compass-west").addEventListener("click", function() {
  30. move(WEST);
  31. });
  32. document.getElementById("compass-east").addEventListener("click", function() {
  33. move(EAST);
  34. });
  35. document.getElementById("compass-south-west").addEventListener("click", function() {
  36. move(SOUTH_WEST);
  37. });
  38. document.getElementById("compass-south").addEventListener("click", function() {
  39. move(SOUTH);
  40. });
  41. document.getElementById("compass-south-east").addEventListener("click", function() {
  42. move(SOUTH_EAST);
  43. });
  44. }