home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / ObjectTcl-1.1 / examples / TicTacToe / ttt < prev   
Encoding:
Text File  |  1995-06-30  |  1.6 KB  |  76 lines

  1. source Player.tcl
  2. source Game.tcl
  3.  
  4. otcl oserver init
  5.  
  6. puts -nonewline "Please enter your name: "
  7. gets stdin name
  8.  
  9. if {$name == ""} {
  10.    puts "Goodbye..."
  11.    exit
  12. }
  13.  
  14. puts -nonewline "$name, please enter the address of the player server: "
  15. gets stdin playerServerAddress
  16. if {$playerServerAddress == ""} {
  17.    puts "Goodbye ..."
  18.    exit
  19. }
  20.  
  21. otcl remoteClass PlayerServer $playerServerAddress
  22.  
  23.  
  24. set me [otclNew Player $name]
  25.  
  26. set playerList {}
  27.  
  28. proc quitProc {} {
  29.    global me
  30.    PlayerServer playerNotAvailable $me
  31.    exit
  32. }
  33.  
  34. proc selectedProc {} {
  35.  
  36.    global me
  37.    global playerList
  38.  
  39.    foreach o  [.clist.list curselection] {
  40.       set game [[lindex [lindex $playerList $o] 1] challenge $me]
  41.       [otclNew Game X $me] setOpponent $game
  42.    }
  43.  
  44.    destroy .clist
  45.    .challenge configure -state active
  46. }
  47.  
  48. proc challengeProc {} {
  49.  
  50.    global playerList 
  51.    set playerList [PlayerServer giveAvailablePlayers]
  52.  
  53.    toplevel .clist
  54.    wm title .clist "Players"
  55.    listbox .clist.list -relief raised -borderwidth 2 \
  56.            -yscrollcommand ".clist.scroll set"  
  57.    button .clist.challenge -text "Challenge" -command "selectedProc"
  58.    scrollbar .clist.scroll -command ".clist.list yview"
  59.    pack .clist.challenge -side top -fill x
  60.    pack .clist.scroll -side right -fill y
  61.    pack .clist.list
  62.  
  63.    foreach p $playerList {
  64.       .clist.list insert end [lindex $p 0]
  65.    }
  66.  
  67.    .challenge configure -state disabled
  68. }
  69.  
  70. # Construct main window
  71. button .challenge -text "Challenge ..." -command challengeProc
  72. button .quit -text "Quit" -command quitProc
  73. pack .challenge .quit -fill x
  74. wm title . "TicTacToe: $name"
  75. wm protocol . WM_DELETE_WINDOW {quitProc}
  76.