// script.C -- written 3/16/96 by Max Hailperin // // This is the user interface of the Photon game, written as a TCL script. // It is a big long character array compiled into the program, rather than // a text file read in, because although this makes it clumsier to make changes, // on the other hand it means that the program is a self-contained unit // (aside from dynamically loaded shared libraries). // // Things to think about one day: // - reconsidering the above decision // - adding a mechanism for starting the game over // - adding an explicit mechanism for pausing, other than iconification // - adding a more clear-cut way to quit // - adding on-line help, plus an info panel // - adding a win condition, so that when you get 20 targets the game is over char photonScript[] = "wm resizable . off off\n" "set timestep 50\n" "set score 0\n" "set time 0\n" "canvas .c -height 12c -width 12c\n" "pack .c -side top\n" "frame .f \n" "pack .f -side bottom -fill x\n" "button .f.b -text Start -command startgame\n" "pack .f.b -side left\n" "scale .f.s -label slowness -length 4c -from 10 -to 200 -orient horizontal " "-variable timestep\n" "pack .f.s -side left\n" "frame .f.score\n" "pack .f.score -side left\n" "label .f.score.label -text Score\n" "pack .f.score.label -side top\n" "label .f.score.value -textvariable score\n" "pack .f.score.value -side bottom\n" "frame .f.time\n" "pack .f.time -side left\n" "label .f.time.label -text Time\n" "pack .f.time.label -side top\n" "label .f.time.value -textvariable time\n" "pack .f.time.value -side bottom\n" "frame .f.f\n" "pack .f.f -side right\n" "label .f.f.t -text {Keyboard commands}\n" "pack .f.f.t -side top\n" "label .f.f.b -text {j: \\ k: erase l: /}\n" "pack .f.f.b -side bottom\n" "photon game .c\n" "set currentcommand none\n" "proc startgame {} {.f.b configure -state disabled\n" " gamestep}\n" "proc gamestep {} {global currentcommand timestep score time\n" " if {[string compare [wm state .] normal] == 0} " " {incr time\n" " incr score [game $currentcommand]}\n" " set currentcommand none\n" " after $timestep gamestep}\n" "focus .c\n" "bind .c j {global currentcommand\n" " set currentcommand neg}\n" "bind .c k {global currentcommand\n" " set currentcommand erase}\n" "bind .c l {global currentcommand\n" " set currentcommand pos}\n" ;