Web design seattle - 1128 Networking: Streams-Based Sockets and Datagrams Chapter 22
1128 Networking: Streams-Based Sockets and Datagrams Chapter 22 93 94 // appends the argument to text in displayTextBox 95 public void Display( string message ) 96 { 97 displayTextBox.Text += message + “rn”; 98 } 99 100 // determine if a move is valid 101 public bool ValidMove( int location, int player ) 102 { 103 // prevent another thread from making a move 104 lock ( this ) 105 { 106 // while it is not the current player’s turn, wait 107 while ( player != currentPlayer ) 108 Monitor.Wait( this ); 109 110 // if the desired square is not occupied 111 if ( !IsOccupied( location ) ) 112 { 113 // set the board to contain the current player’s mark 114 board[ location ] = ( byte ) ( currentPlayer == 0 ? 115 ‘X’ : ‘O’ ); 116 117 // set the currentPlayer to be the other player 118 currentPlayer = ( currentPlayer + 1 ) % 2; 119 120 // notify the other player of the move 121 players[ currentPlayer ].OtherPlayerMoved( location ); 122 123 // alert the other player it’s time to move 124 Monitor.Pulse( this ); 125 126 return true; 127 } 128 else 129 return false; 130 } 131 } // end method ValidMove 132 133 // determines whether the specified square is occupied 134 public bool IsOccupied( int location ) 135 { 136 if ( board[ location ] == ‘X’ || board[ location ] == ‘O’ ) 137 return true; 138 else 139 return false; 140 } 141 142 // determines if the game is over 143 public bool GameOver() 144 { Fig. 22.5 Fig. 22.FiFig. 22.5g. 22.5Server side of client/server Tic-Tac-Toe program. (Part 3 of 6.) Fig. 22.5
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services