Dialog HangMan

By FordLawnmower on Jan 03, 2010

I saw RagBot's Pcwin Hangman and I decided it would be a decent challenge to make a Hangman game in a dialog. It was actually a little harder than I thought it would be.

Easy to use:
Just load into remotes, Right click channel or status and select HangMan.
This will start a new game with the category stars.
To select a letter, just click the letter at the top. If you fill in all the blanks before you click 6 wrong letters, you win. If you click 6 wrong letters you lose.

To start a new game in the current category, click Play.
To start a new game with a new category, just change the category with the drop-down to the left.

Image

;Dialog HangMan by Ford_Lawnmower irc.mindforge.org #USA-Chat
menu Channel,Status { 
  HangMan
  .Play: dialog $iif($dialog(HangMan),-v,-md) HangMan HangMan
  .Reset: {
    if ($dialog(HangMan)) { dialog -x HangMan }
    var %count 0
    while (%count <= 6) { 
      if ($isfile($+(HangMan\,%count,.gif))) { 
        .remove $+(HangMan\,%count,.gif) 
      }
      inc %count 
    }
    dialog -md HangMan HangMan
  }
}
alias -l HangMan {
  if ($sock(HangMan)) { sockclose HangMan }
  sockopen HangMan $+($1,.hangmania.com) 80
  sockmark HangMan $+($1,.hangmania.com)
}
On *:sockopen:HangMan: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET / HTTP/1.0
    sockwrite -n $sockname Host: $sock($sockname).mark
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:HangMan: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    var %HangMan | sockread %HangMan
    if ($regex(%HangMan,/new Array\((.*)\)\;/i)) {
      set %HangMan.Key $replace($remove($regml(1),$chr(39)),$chr(32),$chr(1),$chr(44),$chr(32))
      set %HangMan.Word $regsubex(%HangMan.Key,/\w/g,_)
      set %HangMan.Count 0
      if ($dialog(HangMan)) {
        did -e hangman 1-26 
        did -a HangMan 29 %HangMan.Word
        if ($isfile(Hangman\0.gif)) { did -g Hangman 30 Hangman\0.gif }
        else { .timer 1 3 did -g Hangman 30 Hangman\0.gif }
      }
      sockclose $sockname
      return 
    }
  }
}
alias -l repchar { return $+($left($3-,$calc($1 - 1)),$2,$mid($3-,$+($calc($1 + 1),-))) }
alias -l CheckStrings {
  var %string1 $1, %string2 $2, %length $len($1)
  while (%length) {
    if ($mid($1,%length,1) == $3) {
      %string2 = $repchar(%length,$v1,%string2)
    }
    dec %length
  }
  if ($2 != %string2) { return %string2 }
}
alias -l GetIcons {
  var %count 0
  while (%count <= 6) {
    .timer 1 $calc(%count * 2) gethangpict www.justhangman.com $+(/images/hangman_,%count,.gif) Hangman $+(%count,.gif)
    inc %count
  }
}
alias -l GetHangPict {
  if (!$isfile($qt($+($3,\,$4)))) {
    var %sockname $+(GetHangPict,$ticks,$r(1,$ticks))
    if (!$isdir($qt($3))) { mkdir $qt($3) }
    sockopen %sockname $1 80
    sockmark %sockname $1-
  }
}
On *:sockopen:GetHangPict*:{
  sockwrite -nt $sockname GET $gettok($sock($sockname).mark,2,32) HTTP/1.0
  sockwrite -n $sockname Host: $gettok($sock($sockname).mark,1,32) $+ $crlf $+ $crlf
}
On *:sockread:GetHangPict*:{
  if (!$gettok($sock($sockname).mark,5,32)) {
    var %GetPict | sockread %GetPict
    if (!%GetPict) { sockmark $sockname $addtok($sock($sockname).mark,1,32) }
  }
  else {
    sockread &GetPict
    bwrite -s $qt($+($gettok($sock($sockname).mark,3,32),\,$gettok($sock($sockname).mark,4,32))) -1 -1 &GetPict
  }
}
dialog HangMan {
  title "HangMan"
  size -1 -1 199 244
  option dbu
  button "A", 1, 24 8 8 10
  button "B", 2, 36 8 8 10
  button "C", 3, 48 8 8 10
  button "D", 4, 60 8 8 10
  button "E", 5, 72 8 8 10
  button "F", 6, 84 8 8 10
  button "G", 7, 96 8 8 10
  button "H", 8, 108 8 8 10
  button "I", 9, 120 8 8 10
  button "J", 10, 132 8 8 10
  button "K", 11, 144 8 8 10
  button "L", 12, 156 8 8 10
  button "M", 13, 168 8 8 10
  button "N", 14, 24 22 8 10
  button "O", 15, 36 22 8 10
  button "P", 16, 48 22 8 10
  button "Q", 17, 60 22 8 10
  button "R", 18, 72 22 8 10
  button "S", 19, 84 22 8 10
  button "T", 20, 96 22 8 10
  button "U", 21, 108 22 8 10
  button "V", 22, 120 22 8 10
  button "W", 23, 132 22 8 10
  button "X", 24, 144 22 8 10
  button "Y", 25, 156 22 8 10
  button "Z", 26, 168 22 8 10
  combo 27, 5 48 60 12, drop
  text "Category:", 28, 5 40 58 8
  text "", 29, 73 46 119 24
  icon 30, 6 71 186 153
  button "Play", 31, 98 230 37 12
  button "Close", 32, 148 230 37 12, Cancel
}
On *:dialog:HangMan:close:*: { unset %HangMan.* }
On *:dialog:HangMan:init:*: {
  GetIcons
  didtok $dname 27 32 Stars Movies Games Countries Animals
  did -c $dname 27 1
  HangMan Stars
}
On *:dialog:HangMan:Sclick:31,27: { HangMan $did($dname,27).seltext }
On *:dialog:HangMan:Sclick:1-26: {
  did -b $dname $did
  if ($CheckStrings(%HangMan.Key,%HangMan.Word,$did($dname,$did).text)) {
    set %HangMan.Word $v1
    did -a $dname 29 %HangMan.Word
    if (%HangMan.Word == %HangMan.Key) { 
      did -a $dname 29 %HangMan.Key -- Winner!!
      did -b $dname 1-26
    }
  }
  else {
    if ($calc($gettok($nopath($did($dname,30)),1,46) + 1) <= 6) { did -g $dname 30 $+(HangMan\,$v1,.gif) }
    if ($v1 == 6) { 
      did -a $dname 29 %HangMan.Key -- You Lost!!
      did -b $dname 1-26
    }
  }
}

Comments

Sign in to comment.
nutty   -  Feb 23, 2014

just tested in my 7.32 mirc works great... thank you... well done

FordLawnmower  -  Mar 12, 2014

I forgot about this snippet. I surprised it's still working.

nutty  -  Mar 13, 2014

i used it in the angel mirc i was creating... i ran out of games for the web pages.. so i used your code for hangman :) and of course left your name and all in it since you are creator of the code.. had some people on the site love your work on that code :)

Sign in to comment

blackvenomm666   -  Jun 14, 2011

ok yea it was just the bot. it works on my main mirc

 Respond  
blackvenomm666   -  Jun 14, 2011

i did but it didnt work idk why. i'll test it on a diff mirc other than my bot. maybe its just being retarded cause the bot is running a socket that goes off every 20 seconds

 Respond  
FordLawnmower   -  Jun 14, 2011

I still have this working blackvenomm666. Try clicking reset from the right click menu.

 Respond  
blackvenomm666   -  Jun 14, 2011

ford this has stopped working. i just got it today and tried it it doesnt make a hangman i can click all the letters until i win without it making a single part of the hangman pic

 Respond  
FordLawnmower   -  Apr 24, 2011

Thanks GrimReaper :)

 Respond  
GrimReaper   -  Apr 24, 2011

Very nice Ford, I like the use of the .gif file and the way that it is layed out. :)

Exceptional 10/10 from me and +like.

 Respond  
FordLawnmower   -  Apr 24, 2011

Thanks :)

 Respond  
blackvenomm666   -  Apr 24, 2011

nicely done ford

 Respond  
Sharky_Dude   -  Apr 24, 2011

Not a big fan of hangman but this Snippet is awesome. I rated you a perfect 10.

 Respond  
FordLawnmower   -  Jan 03, 2010

Thanks SnoooP :)

 Respond  
SnoooP   -  Jan 03, 2010

Done, works nicely now. =)

8/10 Nice dialog, I like how its set up, good work mate!

 Respond  
FordLawnmower   -  Jan 03, 2010

Something must have went wrong on your first run SnoooP.

Enter this from the command line

//var %count 0 | while (%count <= 6) { if ($isfile($+(HangMan\,%count,.gif))) { remove $+(HangMan\,%count,.gif) } | inc %count }

This will remove all the body parts so you can start over. Opening the dialog again should force the script to download them again. Hopefully they download correct the second time :)

I'll add this as a reset on the menu in a few minutes.

 Respond  
SnoooP   -  Jan 03, 2010

Also, I have now had a go with every catergory and it does the same thing each time. Lets me select every letter without me losing.

 Respond  
SnoooP   -  Jan 03, 2010

I get this message:

[23:27] * /sockwrite: 'GetHangPict24702531150744' not connected (line 66, script8.mrc)
-
[23:27] * /did: 'HangMan' error loading 'C:\Documents and Settings\brian\Application Data\mIRC\HangMan\3.gif' (line 135, script8.mrc)

:S
The problem I am having is, I had ago of this just now, I selected catergory movies, the eventual answer was the simpsons but...

I click 2 letters what were wrong, got the head and body, after that I clicked a correct letter, then I clicked a wrong letter and no body part appeared. I then decided to click every letter and got the answer.. 20 of the letters were wrong but it didn't give me any more body parts.

I tried again this time the winning answer was hitman, I just from the off clicked every button, abcdefghijklmnopqrst and eventually won, same thing happened, I only got the head and the body, nothing else. :S

 Respond  
RagBot   -  Jan 03, 2010

Good work! You also managed to find a socket for it, I wonder how I managed to miss it.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.