Java Reference
In-Depth Information
209 if ((cell[ 0 ][j] == token)
210 && (cell[ 1 ][j] == token)
211 && (cell[ 2 ][j] == token)) {
212
return true ;
213 }
214
215 /** Check major diagonal */
216 if ((cell[ 0 ][ 0 ] == token)
217 && (cell[ 1 ][ 1 ] == token)
218 && (cell[ 2 ][ 2 ] == token)) {
219
return true ;
220 }
221
222 /** Check subdiagonal */
223 if ((cell[ 0 ][ 2 ] == token)
224 && (cell[ 1 ][ 1 ] == token)
225 && (cell[ 2 ][ 0 ] == token)) {
226
return true ;
227 }
228
229
/** All checked, but no winner */
230
return false ;
231 }
232 }
233 }
L ISTING 31.10
TicTacToeClient.java
1 import java.io.*;
2 import java.net.*;
3 import java.util.Date;
4 import javafx.application.Application;
5 import javafx.application.Platform;
6 import javafx.scene.Scene;
7 import javafx.scene.control.Label;
8 import javafx.scene.control.ScrollPane;
9 import javafx.scene.control.TextArea;
10 import javafx.scene.layout.BorderPane;
11 import javafx.scene.layout.GridPane;
12 import javafx.scene.layout.Pane;
13 import javafx.scene.paint.Color;
14 import javafx.scene.shape.Ellipse;
15 import javafx.scene.shape.Line;
16 import javafx.stage.Stage;
17
18 public class TicTacToeClient extends Application
19
implements TicTacToeConstants {
20
// Indicate whether the player has the turn
21
private boolean myTurn = false ;
22
23
// Indicate the token for the player
24
private char myToken = ' ' ;
25
26
// Indicate the token for the other player
27
private char otherToken = ' ' ;
28
29
// Create and initialize cells
30
private Cell[][] cell = new Cell[ 3 ][ 3 ];
31
 
 
Search WWH ::




Custom Search