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.
;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
}
}
}
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.
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
I forgot about this snippet. I surprised it's still working.