GAME: Mastermind

By QuickStep on Nov 23, 2004

another text based single player game. Just type /mastermind to start. You can configure some variables (colors, lenght of code) and also change the allowed characters (you can also use letters instead of numbers.)

;You have full right to take this code/reproduce it, and you do not need my permission for it

alias mastermind {
  %mastermind.enabled = 0

  ;------- Editable values -------
  %mastermind.codelen = 6
  %mastermind.inputmin = 1
  %mastermind.inputmax = 6
  %mastermind.goodcolor = 00,03
  %mastermind.badcolor = 00,04
  %mastermind.inwordcolor = 00,12
  ;-------------------------------

  set %mastermind.dot
  var %r, %w = 1 | while %w <= %mastermind.codelen {
    %r = $+(%r,$rand(%mastermind.inputmin,%mastermind.inputmax))
    %mastermind.dot = $+(%mastermind.dot,$chr(46)) | inc %w
  }
  %mastermind.code = $encode(%r) | %mastermind.lines = 1
  var %w = @mastermind | window %w | clear %w
  echo %w Welcome to mastermind! Enter a number between %mastermind.inputmin and %mastermind.inputmax
  mastermind_start
}

alias -l mastermind_start { echo @mastermind %mastermind.dot | set %mastermind.input | %mastermind.enabled = 1 }
alias -l mastermind_end {
  %mastermind.enabled = 2 | var %w = @mastermind | echo %w That is correct! $+($chr(40),$calc(%mastermind.lines - 1),$chr(32),tries,$chr(41)) Press any key to try again...
}
on *:keydown:@mastermind:*:{
  if (%mastermind.enabled = 2) { mastermind | halt } | if (%mastermind.enabled = 0) || ($keychar < %mastermind.inputmin) || ($keychar > %mastermind.inputmax) return
  %mastermind.input = $+(%mastermind.input,$keychar)
  var %c = rline @mastermind $calc(%mastermind.lines + 1)
  if ($len(%mastermind.input) = %mastermind.codelen) {
    %c $mastermind_check(%mastermind.input) | inc %mastermind.lines | if (%mastermind.good = %mastermind.codelen) mastermind_end | else mastermind_start
  }
  else %c $+(%mastermind.input,$left(%mastermind.dot,$calc(%mastermind.codelen - $len(%mastermind.input))))
}

alias -l mastermind_check {
  if ($hget(mastermind) = $null) hmake mastermind 20 | set %mastermind.good
  var %u = $$1, %r = $decode(%mastermind.code), %w = 1 | while %w <= $len(%r) {
    if ($mid(%r,%w,1) = $mid(%u,%w,1)) { hadd mastermind $+(r,%w) | hadd mastermind $+(u,%w) $+($chr(3),%mastermind.goodcolor,$mid(%r,%w,1)) | inc %mastermind.good }
    else { hadd mastermind $+(r,%w) $mid(%r,%w,1) | hadd mastermind $+(u,%w) }
    inc %w
  }
  var %w = 1 | while %w <= $len(%r) {
    if $hget(mastermind,$+(u,%w)) { inc %w | continue }
    var %q = 1 | while %q <= $len(%r) {
      if ($hget(mastermind,$+(r,%q)) = $mid(%u,%w,1)) {
        hadd mastermind $+(r,%q) | hadd mastermind $+(u,%w) $+($chr(3),%mastermind.inwordcolor,$mid(%u,%w,1))
        break
      }
      inc %q
    }
    inc %w
  }
  var %w = 1 | while %w <= $len(%r) {
    if ($hget(mastermind,$+(u,%w)) = $null) hadd mastermind $+(u,%w) $+($chr(3),%mastermind.badcolor,$mid(%u,%w,1))
    inc %w
  }
  var %input, %w = 1 | while %w <= $len(%r) { %input = $+(%input,$hget(mastermind,$+(u,%w))) | inc %w }
  return %input
}

Comments

Sign in to comment.
big_boya   -  Dec 20, 2008

so whats the pourose of this? idk even how to win

 Respond  
nobody   -  Nov 26, 2004

I like.. I like..

 Respond  
sarkar112   -  Nov 24, 2004

i agree with darth

 Respond  
DarthReven   -  Nov 23, 2004

Interesting...not my forte for single player games but nice

 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.