; Simon 1.0
; by Eric^^ <EricN@accesswave.ca>
;
; http://accesswave.ca/~ericn/
;
; /simon

on *:start:{
  if ($version < 5.91) { echo $colour(info) -s *** Simon requires mIRC 5.91. Unloading... | .unload -rs $script }
  if (!%simon.speed) set %simon.speed 1
  if (!%simon.sound) set %simon.speed 1
}

alias simon {
  if ($window(@simon)) halt
  if ($hget(simon,status)) hfree simon
  hmake simon 20
  hadd simon status start
  window -aCfdpk0 +L @simon -1 -1 400 250
  drawdot -r @simon 0 1000 0 0
  drawrect -er @simon 1052688 5 5 5 390 200
  drawline -r @simon 1052688 6 200 10 200 200
  drawline -r @simon 1052688 6 10 100 390 100
  drawfill -sr @simon 24576 0 50 50
  drawfill -sr @simon 45232 0 250 50
  drawfill -sr @simon 112 0 50 150
  drawfill -sr @simon 6291456 0 250 150
  simon.status 9,1Hi. Right click to start :)
}
alias simon.sound {
  if (%simon.sound) {
    if ($1 == click) splay $scriptdirclick.wav
    if ($1 == lose) splay $scriptdirlose.wav
  }
}
alias simon.restore {
  if (!$window(@simon)) halt
  drawfill -sr @simon 24576 61440 50 50
  drawfill -sr @simon 45232 61680 250 50
  drawfill -sr @simon 112 240 50 150
  drawfill -sr @simon 6291456 15728640 250 150
}
alias simon.color {
  ;  simon.restore 
  if (!$window(@simon)) halt
  if ($1 == green) drawfill -sr @simon 61440 24576 50 50
  if ($1 == yellow) drawfill -sr @simon 61680 45232 250 50
  if ($1 == red) drawfill -sr @simon 240 112 50 150
  if ($1 == blue) drawfill -sr @simon 15728640 6291456 250 150
}
alias simon.temp {
  simon.color $1
  .timertemp -m 1 150 simon.restore
}
alias simon.click {
  simon.restore
  var %dot = $getdot(@simon,$1,$2)
  if (%dot == 24576) var %click = green
  if (%dot == 45232) var %click = yellow
  if (%dot == 112) var %click = red
  if (%dot == 6291456) var %click = blue
  if (!%click) halt
  simon.temp %click
  hadd simon play $hget(simon,play) %click | simon.sound click 
  if ($gettok($hget(simon,level),1- $+ $numtok($hget(simon,play),32),32) != $hget(simon,play)) { hadd simon status game over | simon.status 8,1           You lose        | simon.sound lose }
  if ($hget(simon,play) == $hget(simon,level)) { hadd simon beat level | .timerwait 1 2 simon.level $calc($gettok($hget(simon,status),2,32) +1) | simon.status 8,1         Good job         }
}
alias simon.close window -c @simon | .timersimon* off | hfree simon
alias simon.status if ($window(@simon)) drawtext -p @simon 0 Tahoma 13 140 220 $1-
alias simon.level {
  if (!$window(@simon)) halt
  if ($1 == 1) hdel simon level
  var %l = $iif($1 isnum,$1,$gettok($hget(simon,status),2,32))
  simon.status 11,1     Level %l $+ ... 4wait                
  hadd simon status loading
  hdel simon play
  if ($1 == repeat) goto repeat
  var %r = $rand(1,4)
  if (%r == 1) var %color = green
  if (%r == 2) var %color = yellow
  if (%r == 3) var %color = red
  if (%r == 4) var %color = blue
  hadd simon level $hget(simon,level) %color
  :repeat
  var %a = 1,%t = 0
  while ($gettok($hget(simon,level),%a,32)) {
    .timersimon. $+ %a -m 1 %t simon.color $gettok($hget(simon,level),%a,32)
    .timersimon. $+ %a $+ restore -m 1 $calc(%t + 200) simon.restore 
    inc %a
    inc %t $calc(1000 - (%simon.speed * 100))
  }
  .timersimon. $+ %a -m 1 %t hadd simon status playing %l
  .timersimon. $+ %a $+ restore -m 1 %t simon.restore 
  .timersimon. $+ %a $+ text -m 1 %t simon.status 11,1     Level %l $+ ... 9play                

  ; Bad memory? Just cheat... :P
  ; echo -a >> CHEAT: $hget(simon,level)

}
menu @simon {
  sclick:if ($gettok($hget(simon,status),1,32) == playing) simon.click $mouse.x $mouse.y
  dclick:if ($gettok($hget(simon,status),1,32) == playing) simon.click $mouse.x $mouse.y
  leave:if ($gettok($hget(simon,status),1,32) == playing) simon.restore
  $iif($hget(simon,status) == start,Start,New game):simon.level 1
  Options
  .$iif(%simon.sound,Sounds [on],Sounds [off]):if (%simon.sound) set %simon.sound 0 | else set %simon.sound 1
  .$iif(%simon.speed,Speed $+([,%simon.speed,]),Speed [1]):var %speed = $?="Enter a speed (1 = slowest, 5 = fastest)" | set %simon.speed $iif(%speed isnum 1-5,%speed,1)
  -
  $iif(play isin $hget(simon,status),Repeat):simon.level repeat
  -
  Exit:simon.close
}
