dialog rps { title "Rock, Paper, Scissors" size -1 -1 120 100 option dbu text "Wins: ",1,5 15 40 10 text "Ties: ",2,5 25 40 10 text "Losses: ",3,5 35 40 10 text "*** Type in either R for Rock, P for Paper or S for scissors. And then click Play. ***",4, 3 50 120 30 edit "",5,5 70 50 10 button "Play",6, 60 70 50 10 } On *:Dialog:rps:*:*: { if ($devent == init) { did -a $dname 1 $did($dname,1) $iif($hget(rps,win),$hget(rps,win),0) did -a $dname 2 $did($dname,2) $iif($hget(rps,draw),$hget(rps,draw),0) did -a $dname 3 $did($dname,3) $iif($hget(rps,lose),$hget(rps,lose),0) if (%rps.guess) did -a $dname 5 %rps.guess } if ($devent == sclick) { var %x = $did(5) if ($did == 6) && (%x == r) || (%x == p) || (%x == s) { { .timer 1 1 did -ra $dname 6 1 ... .timer 1 2 did -ra $dname 6 2 ... .timer 1 3 did -ra $dname 6 3 ... .timer 1 4 did -ra $dname 6 Shoot! if (%x == r) .timer 1 4 rps r if (%x == p) .timer 1 4 rps p if (%x == s) .timer 1 4 rps s .timer 1 5 did -ra $dname 6 Play set %rps.guess %x } } } } menu menubar { Rock Paper Scissors .Erase Data:{ if ($input(Are you sure you want to erase you score?,y,Confirm Deletion) == $true) { if ($hget(rps)) hfree rps .remove rps.dat } } .Unload: unload -rs $script } alias rps { if (!$1) dialog -dm rps rps if (r == $1) || (p == $1) || (s == $1) { if (!$hget(rps)) hmake rps 10 var %rps1 = $rand(1,3) var %rps2 = $iif(r == $1,Rock,$iif($1 == p,Paper,Scissors)) var %rps3 = $iif(%rps1 == 1,Rock,$iif(%rps1 == 2,Paper,Scissors)) set %rps.guess $1 ;Rock variants if (%rps2 == Rock) && (%rps3 == Scissors) goto win if (%rps2 == Rock) && (%rps3 == Rock) goto draw if (%rps2 == Rock) && (%rps3 == Paper) goto lose ;Paper variants if (%rps2 == Paper) && (%rps3 == Rock) goto win if (%rps2 == Paper) && (%rps3 == Paper) goto draw if (%rps2 == Paper) && (%rps3 == Scissors) goto lose ;Scissors variants if (%rps2 == Scissors) && (%rps3 == Paper) goto win if (%rps2 == Scissors) && (%rps3 == Scissors) goto draw if (%rps2 == Scissors) && (%rps3 == Rock) goto lose ;Dual decision :win echo -a You won this dual your %rps2 beats your opponents %rps3 hinc rps win update.rps halt :lose echo -a You lost this dual your opponents %rps3 beats your %rps2 hinc rps lose update.rps halt :draw echo -a It's a draw your %rps2 can't beat your opponents %rps3 hinc rps draw update.rps halt hsave -o rps rps.dat } if ($1 == stats) echo -a Wins: $iif($hget(rps,win),$hget(rps,win),0) $& Draws: $iif($hget(rps,draw),$hget(rps,draw),0) $& Losses: $iif($hget(rps,lose),$hget(rps,lose),0) } On *:Exit: { if ($hget(rps)) hsave -o rps rps.dat } On *:Start: { inc %rps.startup if (%rps.startup == 1) { echo -a You have just loaded Rock Paper Scissors. Type /rps to play. } hmake rps 10 if ($isfile(rps.dat)) hload -o rps rps.dat } alias update.rps { if ($dialog(rps)) { did -ra rps 1 Wins: $iif($hget(rps,win),$hget(rps,win),0) did -ra rps 2 Ties: $iif($hget(rps,draw),$hget(rps,draw),0) did -ra rps 3 Losses: $iif($hget(rps,lose),$hget(rps,lose),0) } }