Can we give points for every correct answer?
namespace eval GuessNumber {
bind pub - !randomnumber [namespace current]::StartGame
bind pub - !guess [namespace current]::Guess
proc StartGame {nick host hand chan text} {
variable number
set number [RandomNumber 1 50]
puthelp "PRIVMSG $chan :\00307\002\037(\037\002\00304$nick has started The Number Guessing Game.\00307\037\002)"
puthelp "PRIVMSG $chan :\00307\002\037(\037\002\00304The Number Range is From:\002 1 \002To:\002 50 \002\00307\037\002)"
puthelp "PRIVMSG $chan :\00307\002\037(\037\002\00304To Guess What Number Type: !guess <number>\002\00307\037\002)"
}
proc Guess {nick uhost hand chan text} {
namespace upvar [namespace current] number no
if {[scan $text {%d} value] != 1} {
puthelp "PRIVMSG $chan :Sorry, that's not a valid number."
return
}
CheckNumber $chan $nick $value
}
proc RandomNumber {min max} {
return [expr {int(rand() * ($max - $min + 1)) + $min}]
}
proc CheckNumber {chan nick value} {
variable number
if {![info exists number] } {
puthelp "PRIVMSG $chan :Sorry, there's nothing to guess cos game hasn't been started yet."
return
}
if {$value == $number} {
puthelp "PRIVMSG $chan :Congragulations, $nick, You Have Won!"
unset number
} elseif {$value > $number} {
puthelp "PRIVMSG $chan :This Is Bigger than the correct Number"
} else {
puthelp "PRIVMSG $chan :This is Smaller than the correct Number"
}
}
}