Hangman (Quest style)

K.V.

Anyone want to test this out?

http://textadventures.co.uk/games/view/hvusvk64lugv2x5hon3exg/pick-a-letter


You can enter CUSTOMIZE to clear the list of solutions, and/or add your own.

Pick A will ask if there's an 'A'. (Caps don't matter.)

SOLVE #text# (#text# being your answer) will try to solve.


>CLICK HERE TO VIEW THE GAME'S CODE
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Pick a Letter">
    <gameid>2ddaf7bb-f696-4170-a5ce-df1f5dc569ce</gameid>
    <version>0.0.1</version>
    <firstpublished>2017</firstpublished>
    <description>This is just a silly game I pieced together from bits and pieces of code I found online.</description>
    <turnoffcompass />
    <turnoffinventory />
    <commandpane />
    <feature_advancedscripts />
    <attr name="autodescription_youarein" type="int">0</attr>
    <enablehyperlinks type="boolean">false</enablehyperlinks>
    <missedOne type="int">0</missedOne>
    <css><![CDATA[<style>svg {margin: 0 auto;border: 1px solid black;}line{stroke: black;stroke-width: 4;}#xEyes, #armL, #armR, #legL, #legR, #head, #body, #noose{display:none;}</style>]]></css>
    <turnoffplacesandobjects />
    <showhealth type="boolean">false</showhealth>
    <showscore type="boolean">false</showscore>
    <start type="script">
      game.choices = Split("xyzzy;quest;lamp;examine;look;go;jump;speak;ask;use;open;close;take;get;think;read;write;play;text;adventure;frotz", ";")
      foreach (cmd, ScopeCommands()) {
        if (not EndsWith(cmd.name, "_kv")) {
          cmd.patternBak = cmd.pattern
          cmd.pattern = null
        }
      }
      msg (Pick a Letter.svg)
      msg (game.css)
    </start>
    <inituserinterface type="script"><![CDATA[
      JS.setCommands ("Pick a letter;<br/>;Solve", "black")
      JS.eval ("var clearedOnce = false;clearScreen = function() {addText('<hr/>SCREEN CLEARED');$('#divOutput').append('<hr class=\"clearedAbove\" />');if (!clearedOnce){addText('<style>#divOutput > .clearedScreen { display: none; }</style>');}clearedOnce = true;$('#divOutput').children().addClass('clearedScreen');$('#divOutput').css('min-height', 0);createNewDiv('left');beginningOfCurrentTurnScrollPosition = 0;setTimeout(function () {$('html,body').scrollTop(0);}, 100);};")
      JS.eval ("HideOutputSection = function(name) {EndOutputSection(name);$(\".\" + name + \" a\").attr('onclick', '');setTimeout(function() {$(\".\" + name).hide(250, function () { $(this).remove(); }); $('#divOutput').animate({'min-height':0}, 250);}, 250);};")
    ]]></inituserinterface>
    <changedmissedOne type="script"><![CDATA[
      switch (game.missedOne) {
        case (1) {
          JS.addText ("<style>#head{display:block;}</style>")
        }
        case (2) {
          JS.addText ("<style>#body{display:block;}</style>")
        }
        case (3) {
          JS.addText ("<style>#armL{display:block;}</style>")
        }
        case (4) {
          JS.addText ("<style>#armR{display:block;}</style>")
        }
        case (5) {
          JS.addText ("<style>#legL{display:block;}</style>")
        }
        case (6) {
          JS.addText ("<style>#legR{display:block;}</style>")
        }
        case (7) {
          JS.addText ("<style>#noose, #xEyes{display:block;}</style>")
          JS.addText ("<style>#rEyes{display:none;}</style>")
          msg ("<h1>YOU HAVE LOST.</h1><center>(Press CTRL+R to restart.)</center>")
          finish
        }
      }
    ]]></changedmissedOne>
  </game>
  <object name="Pick a Letter">
    <inherit name="editor_room" />
    <descprefix type="string"></descprefix>
    <description type="string"></description>
    <svg><![CDATA[
<svg height="400" width="400">
  <g id="wholeBody">
    <g id="head">
    <circle cx="200" cy="80" r="20" stroke="black" stroke-width="4" fill="white"/>
      <g id="rEyes">
      <circle cx="193" cy="80" r="4"/>
      <circle cx="207" cy="80" r="4"/>
      </g>
      <g id="xEyes">
        <line x1="190" y1="78" x2="196" y2="84"/>
        <line x1="204" y1="78" x2="210" y2="84"/>
        <line x1="190" y1="84" x2="196" y2="78"/>
        <line x1="204" y1="84" x2="210" y2="78"/>
      </g>
    </g>
    <line id="body" x1="200" y1="100" x2="200" y2="150" />
    <line id="armL" x1="200" y1="120" x2="170" y2="140" />
    <line id="armR" x1="200" y1="120" x2="230" y2="140" />
    <line id="legL" x1="200" y1="150" x2="180" y2="190" />
    <line id="legR" x1="200" y1="150" x2="220" y2="190" />
  </g>
    <line x1="10" y1="250" x2="150" y2="250" />
    <line id="door1" x1="150" y1="250" x2="200" y2="250" />
    <line  id="door2" x1="200" y1="250" x2="250" y2="250" />
    <line x1="250" y1="250" x2="390" y2="250" />
    <line x1="100" y1="250" x2="100" y2="20" />
    <line x1="100" y1="20" x2="200" y2="20" />
    <line id="noose" x1="200" y1="20" x2="200" y2="60" />
  </svg>
                ]]></svg>
    <usedefaultprefix type="boolean">false</usedefaultprefix>
    <beforefirstenter type="script">
      HangUp
    </beforefirstenter>
    <onexit type="script">
    </onexit>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <turnscript>
    <enabled />
    <script>
      msg (Pick a Letter.svg)
      ShowRoomDescription
    </script>
  </turnscript>
  <command name="save_kv">
    <pattern type="string">^save$</pattern>
    <script>
      JS.eval ("if (webPlayer){saveGame();}else{ASLEvent('SaveFunction', '');};")
    </script>
  </command>
  <command name="print_kv">
    <pattern>print</pattern>
    <script>
      if (not game.showpanes) {
        JS.window.print ()
      }
      else {
        ask ("NOTE: THIS WILL NOT PRINT ANY CLEARED TEXT!\n(You can enter TRANSCRIPT to print all output.)\n\nWould you like to hide the panes?") {
          if (result) {
            JS.panesVisible (false)
            JS.eval ("window.print();alert(\"Printing is complete!\");panesVisible(true);")
          }
          else {
            JS.eval ("window.print();alert(\"Printing is complete!\");")
          }
        }
      }
    </script>
  </command>
  <command name="transcript_kv">
    <pattern>script;transcript;print transcript;print_transcript</pattern>
    <script>
      JS.eval ("var iframe = document.createElement('iframe');document.body.appendChild(iframe);iframe.contentWindow.document.write($('#divOutput').html());iframe.contentWindow.print();document.body.removeChild(iframe);")
    </script>
  </command>
  <command name="pick_letter_kv">
    <pattern>pick;letter;pick letter;pick a letter</pattern>
    <script>
      msg ("Which letter?")
      get input {
        GuessLetter (result)
      }
    </script>
  </command>
  <command name="solve_kv">
    <pattern>solve;answer</pattern>
    <script>
      msg ("What's the answer?")
      get input {
        SolveIt (result)
      }
    </script>
  </command>
  <command name="pick_letter_now_kv">
    <pattern>pick an #text#;pick a #text#;guess a #text#;guess an #text#;give me a #text#;give me an #text#;is there a #text#;is there an #text#;how about a #text#;how about an #text#;how about #text#;pick #text#;guess #text#</pattern>
    <script>
      GuessLetter (text)
    </script>
  </command>
  <command name="solve_text_kv">
    <pattern>solve #text#;the answer is #text#;the solution is #text#</pattern>
    <script>
      SolveIt (text)
    </script>
  </command>
  <command name="version_kv">
    <pattern>version</pattern>
    <script>
      msg (game.version)
    </script>
  </command>
  <command name="help_kv">
    <pattern>help;hint;wtf;wth</pattern>
    <script><![CDATA[
      msg ("<h3>Quick help:</h3>Pick a letter or solve.<br/><hr/><br/>You can press CTRL+R to restart.<br/><hr/>")
    ]]></script>
  </command>
  <command name="look_kv">
    <pattern>look;l;x</pattern>
    <script>
    </script>
  </command>
  <command name="customize_kv">
    <pattern>custom;customize</pattern>
    <script><![CDATA[
      Ask ("Would you like to clear the list of possible solutions first?") {
        if (result) {
          if (not HasAttribute(game, "choicesBak")) {
            game.choicesBak = game.choices
          }
          game.choices = NewStringList()
          msg ("Done.<br/>")
        }
        Ask ("Would you like to add a solution?") {
          if (result) {
            msg ("Please enter your ONE WORD solution (or else there will probably be errors).")
            get input {
              for (i, 0, LengthOf(result)) {
                if (result[i] = Asc(" ")) {
                  msg ("<br/>You must enter ONE WORD.  Please enter CUSTOMIZE to try again.<br/>")
                  return (false)
                }
              }
              list add (game.choices, result)
              msg ("Done.<br/><br/>Reloading.<br/>")
              HangUp
            }
          }
          else {
            if (ListCount(game.choices)=0) {
              game.choices = game.choicesBak
              msg ("There were no solutions.  The list was reset.")
            }
            else {
              msg ("Okay. Back to the game, then.")
            }
          }
        }
      }
      if (ListCount(game.choices)=0) {
        game.choices = game.choicesBak
        msg ("There were no solutions.  The list was reset.")
      }
    ]]></script>
  </command>
  <function name="FormatObjectList" parameters="preList, parent, preFinal, postList" type="string"><![CDATA[
    result = ""
    count = 0
    list = RemoveSceneryObjects(GetDirectChildren(parent))
    if (CheckDarkness()) {
      list = RemoveDarkObjects(list)
    }
    listLength = ListCount(list)
    foreach (item, list) {
      if (LengthOf(result) = 0) {
        result = preList + " "
      }
      result = result + GetDisplayNameLink(item, "object")
      if (CanSeeThrough(item)) {
        result = result + FormatObjectList(" (" + item.contentsprefix, item, preFinal, ")")
      }
      count = count + 1
      if (count = listLength - 1) {
        result = result + " &nbsp;"
      }
      else if (count < listLength) {
        result = result + "&nbsp;"
      }
      else {
        result = result + postList
      }
    }
    return (result)
  ]]></function>
  <function name="HangUp">
    game.answer = PickOneString(game.choices)
    game.shown = NewObjectList()
    game.guessed = NewStringList()
    for (i, 0, LengthOf(game.answer)-1) {
      letter = Chr(game.answer[i])
      // msg (letter)
      if (i = 0) {
        create ("secret_letter")
        letter = secret_letter
      }
      else {
        letter = CloneObject(secret_letter)
        letter.prototype = letter.name
      }
      letter.alias = "_ "
      letter.letter = Chr(game.answer[i])
      letter.usedefaultprefix = false
      MoveObject (letter, Pick a Letter)
      list add (game.shown, letter)
    }
    game.displayedString = ""
    foreach (letter, game.shown) {
      game.displayedString = game.displayedString + letter.alias
      // OutputTextNoBr (letter.alias)
    }
  </function>
  <function name="GuessLetter" parameters="result"><![CDATA[
    if (not LengthOf(result)=1) {
      msg ("<br/>Sorry.  You need to guess one letter at a time.  Please try again.<br/>")
      return (true)
    }
    got = 0
    if (not ListContains(game.guessed, LCase(result))) {
      list add (game.guessed, LCase(result))
    }
    else {
      msg ("<br/>You've already tried that one.<br/>")
      return (true)
    }
    foreach (obj, game.shown) {
      if (LCase(result) = LCase(obj.letter)) {
        got = got + 1
        obj.alias = obj.letter
      }
    }
    if (got = 1) {
      vrb = "is"
    }
    else {
      vrb = "are"
    }
    msg ("<br/>There "+vrb+" "+ToWords(got)+"!<br/>")
    if (got = 0) {
      game.missedOne = game.missedOne + 1
    }
  ]]></function>
  <function name="SolveIt" parameters="result"><![CDATA[
    if (LCase(result) = LCase(game.answer)) {
      msg ("Correct!<br/><br/><hr/><h1>YOU HAVE WON!</h1><center>(Press CTRL+R to restart.)</center>")
      finish
    }
    else {
      msg ("Incorrect.")
    }
  ]]></function>
  <function name="SaveFunction" parameters="param">
    request (RequestSave, "")
  </function>
</asl>

Cool. Like the image.

It might look better if the image floated outside of the text, so there was just one, but it was always there.

Also, when you do SOLVE, if you get it wrong, it should add to the hang man.


K.V.

Thanks, Pixie!

Both suggestions are good, too (of course).

I'm planning on adding a status pane that shows the letters you've tried so far.

I also need to make it show the answer when you lose, I think.


My big TODO is find the page with the SVG code I borrowed from and credit the author. (It was on CodePen or JSFiddle or something. I changed it up a little, combining it with bits of code from other sources, but it's pretty much that person's image.)


definitely cool game, more of these "simple" games are great for people to learn/study, and play too, to showcase what quest can do, as full text/rpg games take a long time to finish, having more simple games, is good avertisement of what quest can do, and also help people with learning various stuff from them.

How are your card games coming, KV, did you finish your poker game?


K.V.

Thanks, HK!

I'm going back to the poker stuff today or tomorrow. (I think I've learned enough about dictionaries to see what mrangel was doing now.)


SIDENOTE:

I was considering calling this game GUESS THE VERB, seeming how all the solutions are Quest commands, but I decided PICK A LETTER was much more straightforward.


K.V.

Pick a Letter has now been updated.


These are very hard words!


Pretty cool. Well done.


K.V.

Thanks, XM!


jm,

Give me some words, and I'll add them, ma'am.


Heh.

Pretty. Beautiful. Gorgeous. Dainty. Saintly.


Rhythm. Jazz.

See also:
https://www.ef.co.uk/english-resources/english-vocabulary/top-1000-words/


K.V.

I thought you guys said my words were hard? (Just kidding.)


I just added a HINT command, but it only provides a vague hint. (I will submit the update within 30 minutes.)


And remember:

You can enter CUSTOM to clear the list of possible solutions and/or add your own.

(I will add some words this evening, including the ones suggested here, but the update I'm about to put out has the option off adding whatever words you wish (including cusswords, if that floats your boat).)


The only solutions included now which aren't built-in Quest commands are:

  • think
  • read
  • write
  • text
  • adventure
  • frotz

...and I thought those fit in with the rest, so I dropped them in. That's why I originally wanted to title this game GUESS THE VERB.

...well, I originally thought of making a game where you had to play hangman to get access to verbs/commands, but that seemed a little daunting (for me and the player).


You need to be quite the IF geek to know "frotz".


K.V.

Yeah, I was just considering removing "frotz" while editing this earlier today, simply because it wasn't a built-in Quest command, but I didn't even consider how obscure those Enchanter games are in this day and age. I believe I shall remove it.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums