Jump to content
chain

Dialog HangMan

Recommended Posts

  • Administrators

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
    }
  }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...