mIRC Home    About    Download    Register    News    Help

Print Thread
help making a hangman... #18637
09/04/03 07:32 PM
09/04/03 07:32 PM
Joined: Mar 2003
Posts: 6
B
Bungle Offline OP
Nutrimatic drinks dispenser
Bungle  Offline OP
Nutrimatic drinks dispenser
B

Joined: Mar 2003
Posts: 6
i am currently trying to make a hangman game on my bot, but i can't seem to code it to allow words where the same letter appears twice (eg: online), and have to use words like "remote" which only have 1 occurance of a letter. I have it so it scans the word for the posistion of where that letter appears, but i'm not sure how to make allow it to change ----- to the correctly guessed letters which appear more than once.
I hope i explained well,
- Bungle

Re: help making a hangman... #18638
09/04/03 07:58 PM
09/04/03 07:58 PM
Joined: Jan 2003
Posts: 3,012
New Hampshire, USA
KingTomato Offline
Hoopy frood
KingTomato  Offline
Hoopy frood

Joined: Jan 2003
Posts: 3,012
New Hampshire, USA
Well, assuming when the game begins you save the correct answer to %hm.answer and the "guessed" answer to %hm.guessed ad the letters already picked in %hm.picked you can use soemthing like...

Code:
on 1:TEXT:*:#: {
  ; its just one letter
  if ($len($1-) == 1) {
    if ($1 isin $picked) { /msg $chan The letter $1 was already said. }
    else {
      /set %hm.picked $addtok(%hm.picked, $1, 44)
      /hm.guess $chan $1
    }
  }
}

; Here are our fake vars for now to give some idea as to how it would work
; %hm.answer online
; %hm.guessed ---i-e
; %hm.picket aei

; Syntax: /hm.guess Channel Letter
alias hm.guess {
  ; unset the temporary guessed var
  /unset %temp

  ; cycle through each letter individually
  /set %a 1
  while (%a <= $len(%hm.answer)) {
    if ($mid(%hm.guessed, %a, 1) == -) {
      if ($mid(%hm.answer, %a, 1) == $2) { /set %temp $+(%temp,$2) }
      else { /set %temp $+(%temp,-) }
    }
    else if ($mid(%hm.guessed, %a, 1) == $chr(32)) { /set %temp $+(%temp,.) }
    else { /set %temp $+(%temp,$mid(%hm.guessed, %a, 1)) }

    ; increase loop var (-u0 means kill the variable after executing it)
    /inc -u0 %a
  }

  ; Now, replace the guessed with the temp variable (also convert all the .'s to spaces)
  /set %hm.guessed $replace(%temp, ., $chr(32))
  /unset %temp

  ; announce result to the users
  /msg $1 Current Word: %hm.guessed
}


now, all this does is goies through every letter looking for a match. When it find one, it replaces the - with the letter in the "guessed" variable. You might want to check the variable after each time hm.guess is executed to see if any more -'s exist. If nomore are in the frase, then you can assume the user has guessed the word. >:D

*Edited: Few errors >:\


-KingTomato
Re: help making a hangman... #18639
12/04/03 09:24 PM
12/04/03 09:24 PM
Joined: Jan 2003
Posts: 87
T
Tat Offline
Babel fish
Tat  Offline
Babel fish
T

Joined: Jan 2003
Posts: 87
Code:
alias hc1 { return 03 }
alias hc2 { return 12 }
on *:Text:!*:#:{ do.hang $1- }
on *:Input:#:{ if ((.* iswm $1) || (!* iswm $1)) { do.hang ! $+ $right($1-,-1) } }
alias do.hang {
  if (($1 == !hangman) && (!$hget(hangman))) {
    hmake hangman 10
    hadd hangman word $read(hangman.txt)
    hadd hangman chan $chan
    hadd hangman man $iif($2 ison $chan, $2, $nick($chan, $rand(1,$nick($chan,0))))
    hmsg $msg.hang.start
  }
  if (!$hget(hangman)) { return }
  if ($1 == !hang) {
    if (($2 !isalpha) || ($len($2) != 1)) {
      hmsg $hc1 $+ You gotta pick a letter moron.
      return 
    }
    elseif ($hget(hangman,Picked. $+ $2)) {
      hmsg $hc1 $+ Idiot... Try picking a letter that somebody else hasn't picked.
      return
    }
    else {
      hadd hangman Picked. $+ $2 1
      if ($2 isin $hget(hangman,word)) { 
        hmsg $msg.hang.right
        hang.checkwin
      }
      else { 
        var %hang.part = $hang.part
        hmsg $msg.hang.wrong(%hang.part)
      }
    }
  }
}
alias hang.part {
  hadd hangman wrong $calc($hget(hangman, wrong) + 1)
  if ($hang.partname($hget(hangman, wrong)) == hanging) {
    hmsg $msg.hang.dead
    hfree hangman
    halt
  }
  return $hang.partname($hget(hangman, wrong))
}
alias hang.checkwin {
  if ($hang.got != $hget(hangman,word)) { return }
  hmsg $msg.hang.save
  hfree hangman
  halt
}
alias hang.partname { return $gettok(a head;a neck;torso;arms;hands;legs;feet;hanging, $1, $asc(;)) }
alias hang.got {
  var %i = 1,%hang.got = $hget(hangman, word)
  unset %hang.left
  while (%i <= 26) {
    if (!$hget(hangman, Picked. $+ $chr($calc(96 + %i)))) { 
      %hang.got = $replace(%hang.got, $chr($calc(96 + %i)), @) 
      set -u120 %hang.left %hang.left $+ $chr($calc(96 + %i)) 
    }
    inc %i
  }
  return %hang.got
}
alias hmsg { msg $$hget(hangman,chan) $1- }
alias msg.hang.clue { return $hc1 $+ Current clue: $hc2 $+ $hang.got $hc1 $+ Letters remaining: $hc2 $+ %hang.left }
alias msg.hang.save { return $hc2 $+ $hget(hangman,man) $+ $hc1 is saved! You're the best channelmates a person could want. }
alias msg.hang.dead { return $hc2 $+ $hget(hangman,man) $+ $hc1 is DEAD! You all suck. Word: $hc2 $+ $hget(hangman,word) }
alias msg.hang.wrong { return $hc1 $+ Smooth gimp! One step closer to dead. You just got $hc2 $+ $hget(hangman, man) $+ $hc1 $+ : $+ $hc2 $1 $+ $hc1 $+ ! $msg.hang.clue }
alias msg.hang.right { return $hc1 $+ Well done, $hc2 $+ $nick $+ $hc1 $+ ! You picked a winning letter. $msg.hang.clue }
alias msg.hang.start { return $hc1 $+ Get ready for some hangman... We are hanging $hc2 $+ $hget(hangman,man) $+ $hc1 $+ , unless you can prevent it. $hc2 $+ !hang <letter> $+ $hc1 to guess a letter. $msg.hang.clue }