{"id":8608,"date":"2023-12-05T15:39:56","date_gmt":"2023-12-05T14:39:56","guid":{"rendered":"https:\/\/retrofixer.it\/?page_id=8608"},"modified":"2023-12-06T14:58:59","modified_gmt":"2023-12-06T13:58:59","slug":"andevture","status":"publish","type":"page","link":"https:\/\/retrofixer.it\/en\/andevture\/","title":{"rendered":"Adventure"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"8608\" class=\"elementor elementor-8608\" data-elementor-post-type=\"page\">\n\t\t\t\t<div class=\"elementor-element elementor-element-ebab01c e-con-full e-flex e-con e-parent\" data-id=\"ebab01c\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-3a475ff elementor-widget elementor-widget-html\" data-id=\"3a475ff\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div id=\"adv-border\">\n<div id=\"adv-container\">\n<div id=\"adv-image\">\n\n<\/div>\n<div id=\"adv-text\">\n  <main><\/main>\n<\/div>\n<div id=\"adv-command\">\n    <!--form onsubmit=\"return false\"-->\n    <input type=\"text\" id=\"icommand\" name=\"icommand\" style=\"text-transform:uppercase\" onkeyup=\"getInput(this.value);\">\n    <!--\/form-->\n<\/div>\n<\/div>\n<\/div>\n\n<script>\nlet main = document.querySelector(\"main\");\nlet input = document.querySelector(\"input\");\n\nfunction print(text) {\n  \/\/ to print some text we first create a new paragraph tag, like having a <p><\/p> in HTML\n  var p = document.createElement(\"p\");\n  \/\/ Then we put our text inside the new p element\n  p.innerHTML = text;\n  \/\/ We add our p element to the document as the last thing in the html body\n  main.appendChild(p);\n  \/\/ The player may have scrolled the page, so make sure we scroll to make the new text visible\n  p.scrollIntoView();\n}\n\n\/\/\n\/\/ Simple dungeon game\n\/\/\n\nvar character = { inventory: [], location: \"west room\" };\n\nvar dungeon = {\n  \"west room\": {\n    short_description: \"west room\",\n    long_description:\n      \"the west end of a sloping east-west passage of barren rock.\",\n    contents: [\"pail of water\", \"dragon tooth\"],\n    exits: { east: \"centre room\" }\n  },\n  \"east room\": {\n    short_description: \"east room\",\n    long_description:\n      \"a room of finished stone with high arched ceiling and soaring columns.\",\n    contents: [],\n    exits: { west: \"centre room\" }\n  },\n  \"centre room\": {\n    short_description: \"centre room\",\n    long_description:\n      \"the very heart of the dungeon, a windowless chamber lit only by the eerie light of glowing fungi high above. A rope hangs down from a room above.\",\n    contents: [\"golden key\", \"spiral hourglass\"],\n    exits: { east: \"east room\", west: \"west room\", up: \"attic room\" }\n  },\n  \"attic room\": {\n    short_description: \"attic room\",\n    long_description:\n      \"the attic. It looks like it hasn't been entered in years. This place is filled with cobwebs, and a dirty window overlooks the roof, but is painted shut.\",\n    contents: [\"crowbar\", \"spear\"],\n    exits: {\n      down: \"centre room\",\n      east: \"closet\"\n    }\n  },\n  roof: {\n    short_description: \"roof\",\n    long_description:\n      \"the long, sloping roof. There is a gargoyle nearby watching you.\",\n    contents: [],\n    exits: {\n      east: \"attic room\",\n      in: \"attic room\"\n    }\n  },\n  closet: {\n    short_description: \"closet\",\n    long_description: \"a dark, musty closet, which makes you want to sneeze.\",\n    contents: [\"wire coathanger\"],\n    exits: {\n      west: \"attic room\"\n    }\n  },\n  lab: {\n    short_description: \"secret laboratory\",\n    long_description:\n      \"a secret lab filled with bubbling vials and the static discharge of Jacob's ladders and Van de Graff generators\",\n    contents: [\"batteries\"],\n    exits: {\n      up: \"closet\"\n    }\n  }\n};\n\nconst help = `Try typing a direction, like \"east\" or \"up'. You if you are in a room with items, you can type \"take <li><span class=\"icon\"><i class=\"icon-picture\" aria-hidden=\"true\"><\/i><\/span><p><\/p><\/li>\n\" or even \"take all\" to pick up everything in the room. To see the long description of a room, including items and exits, type \"look.\" You can type \"inventory\" to see what you are carrying, \"quit\" to exit the game, and \"help\" to see these instructions again.\n\nMany commands also work with abbreviations: \"invent\" or even \"i\" work for \"inventory\". Don't be afraid to try things out to see if they work.\n`;\n\nfunction command_split(str) {\n  var parts = str.split(\/\\s+\/); \/\/ splits string into an array of words, taking out all whitespace\n  var command = parts.shift(); \/\/ command is the first word in the array, which is removed from the array\n  var object = parts.join(\" \"); \/\/ the rest of the words joined together.  If there are no other words, this will be an empty string\n  return [command, object];\n}\n\nvar room, command, verb, obj;\n\nfunction remove(array, item) {\n  var idx = array.indexOf(item);\n  if (idx > -1) {\n    array.splice(idx, 1);\n  }\n}\n\nfunction long_direction(short) {\n  let key = short[0];\n  return {\n    n: \"north\",\n    s: \"south\",\n    e: \"east\",\n    w: \"west\",\n    u: \"up\",\n    d: \"down\",\n    i: \"in\", \/\/ we don't actually use this short form, because 'inventory'\n    o: \"out\"\n  }[key];\n}\n\nfunction move_to_room(room_name) {\n  character.location = room_name;\n  room = dungeon[room_name];\n  describe(room);\n}\n\nfunction move(verb) {\n  let direction = long_direction(verb); \/\/ fix up abbreviations\n  \/\/ special cases for movement\n  if (direction === \"east\" && room.short_description === \"closet\") {\n    print(\"Moving futher back in the dark closet, you find stairs going down\");\n    move_to_room(\"lab\");\n  } else if (room.exits[direction]) {\n    \/\/ general case for move\n    move_to_room(room.exits[direction]);\n  } else {\n    print(\"You cannot go that way\");\n  }\n}\n\nfunction printInventory() {\n  print(\"You are carrying:\");\n  character.inventory.forEach(function(item) {\n    print(\"&nbsp;&nbsp;&nbsp;&nbsp;\" + item);\n  });\n}\n\nfunction describe(room, force) {\n  if (force || !room.visited) {\n    print(\"You are in \" + room.long_description);\n    room.visited = true;\n  } else {\n    print(room.short_description);\n  }\n  var exits = Object.keys(room.exits);\n  if (exits.length > 1) {\n    var last_exit = exits.pop();\n    print(\"There are exits to the \" + exits.join(\", \") + \" and \" + last_exit);\n  } else {\n    print(\"There is an exit to the \" + exits[0]);\n  }\n  room.contents.forEach(function(item) {\n    print(\"There is a \" + item + \" here\");\n  });\n}\n\nfunction take_item(obj) {\n  if (obj === \"all\") {\n    if (room.contents) {\n      \/\/ this part: [:] makes a copy of the list so removing items works\n      while (room.contents.length) {\n        let item = room.contents.pop();\n        print(\"You pick up the \" + item);\n        character.inventory.push(item);\n      }\n    } else {\n      print(\"There is nothing to take!\");\n    }\n  } else {\n    let found = false;\n    room.contents.forEach(function(item) {\n      if (item.includes(obj)) {\n        \/\/ does the word in obj match any part of the text of item?\n        found = true;\n        print(\"You pick up the \" + item);\n        character.inventory.push(item);\n        remove(room.contents, item);\n      }\n    });\n    if (!found) {\n      print(\"There is no \" + obj + \" here.\");\n    }\n  }\n}\n\nfunction item_from(arr, obj) {\n  for (let idx in arr) {\n    let thing = arr[idx];\n    console.log(\"is a %s a %s?\", thing, obj);\n    if (thing.includes(obj)) {\n      return thing;\n    }\n  }\n  return null;\n}\n\nfunction use_item(obj) {\n  let item = item_from(character.inventory, obj);\n  if (!item) {\n    print(\"You aren't carrying a \" + obj);\n    return;\n  }\n  \/\/ Now we can use the item if it is the right object and we are in the right room\n  \/\/ special cases\n  if (item === \"crowbar\" && character.location === \"attic room\") {\n    print(\"You swing the crowbar, smashing open the window!\");\n    \/\/ Modify the exits from the attic\n    dungeon[\"attic room\"].exits.out = \"roof\";\n    dungeon[\"attic room\"].exits.west = \"roof\";\n  }else{\n    print('The ' + item + ' does nothing here.');\n  }\n}\n\nfunction drop_item(obj) {\n  let item;\n  if (obj === \"all\") {\n    if (character.inventory) {\n      while (character.inventory.length) {\n        item = character.inventory.pop();\n        print(\"You dropped the \" + item);\n        room.contents.push(item);\n      }\n    } else {\n      print(\"You aren't carrying anything\");\n    }\n  } else {\n    let found = false;\n    character.inventory.forEach(function(item) {\n      if (item.includes(obj)) {\n        \/\/ does the word in obj match any part of the text of item?\n        found = true;\n        print(\"You drop the \" + item + \".\");\n        room.contents.push(item);\n        remove(character.inventory, item);\n      }\n    });\n    if (!found) {\n      print(\"You aren't carrying a \" + obj + \".\");\n    }\n  }\n}\n\nroom = dungeon[character.location];\ndescribe(room);\n\nfunction getOneCommand(text) {\n  room = dungeon[character.location];\n  command = command_split(text.toLowerCase());\n  verb = command[0];\n  obj = command[1];\n  console.log(\"verb: \" + verb + \", object: \" + obj);\n  if (\n    [\n      \"east\",\n      \"west\",\n      \"north\",\n      \"south\",\n      \"up\",\n      \"down\",\n      \"in\",\n      \"out\",\n      \"e\",\n      \"w\",\n      \"n\",\n      \"s\",\n      \"u\",\n      \"d\"\n    ].includes(verb)\n  ) {\n    move(verb);\n  } else if ([\"inventory\", \"in\", \"i\"].includes(verb)) {\n    printInventory();\n  } else if ([\"look\", \"examine\", \"describe\", \"l\"].includes(verb)) {\n    describe(room, true);\n  } else if ([\"take\", \"pickup\", \"t\"].includes(verb)) {\n    take_item(obj);\n  } else if ([\"use\", \"try\", \"apply\"].includes(verb)) {\n    use_item(obj);\n  } else if ([\"drop\", \"throw\", \"release\"].includes(verb)) {\n    drop_item(obj);\n  }\n}\n\nfunction getInput(evt) {\n   \/\/ alert(evt);\n  if (evt === \"I\") {\n    let text = input.value;\n    input.value = \"\";\n    getOneCommand(text);\n  }\n}\n\n\/\/input.addEventListener(\"keyup\", getInput, false);\n\/\/document.getElementById(\"icommand\").addEventListener(\"keyup\", getInput(\"a\"));\n<\/script>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"elementor_header_footer","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-8608","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/pages\/8608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/comments?post=8608"}],"version-history":[{"count":99,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/pages\/8608\/revisions"}],"predecessor-version":[{"id":8713,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/pages\/8608\/revisions\/8713"}],"wp:attachment":[{"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/media?parent=8608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/categories?post=8608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/tags?post=8608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}