Course Hero Logo

TicTacToe 4 .java - package com.example.sssss /Quan Pham...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 2 out of 7 pages.

package com.example.sssss;//Quan Pham CSC 360//I add to the files change size, change winning size and check winning sizefunction besides new game, save as, load game and exit//I also put some alert when winning size is not fit with the sizeimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.input.KeyCombination;import javafx.scene.layout.BorderPane;import javafx.scene.layout.GridPane;import javafx.scene.layout.Pane;import javafx.scene.paint.Color;import javafx.scene.shape.Ellipse;import javafx.scene.shape.Line;import javafx.stage.FileChooser;import javafx.stage.Stage;import java.io.*;import java.util.Optional;public class TicTacToe extends Application {// Indicate which player has a turn, initially it is the X playerprivate char whoseTurn = 'X';// Size of the boardprotected int size = 3;// Required length to winprotected int winSize = 3;// Create and initialize cellprotected Cell[][] cell =new Cell[size][size];// Create and initialize a status labelprivate final Label lblStatus = new Label("X's turn to play");@Override // Override the start method in the Application classpublic void start(Stage primaryStage) {// Create menu and menu itemsMenuBar menuBar = new MenuBar();Menu menuFile = new Menu("File");menuBar.getMenus().addAll(menuFile);MenuItem menuItemNewGame = new MenuItem("New Game");MenuItem menuItemChangeSize = new MenuItem("Change size");MenuItem menuItemChangeWinSize = new MenuItem("Change winning size");MenuItem menuItemSaveAs = new MenuItem("Save As...");MenuItem menuItemLoadGame = new MenuItem("Load Game");MenuItem menuItemExit = new MenuItem("Exit");menuFile.getItems().addAll(menuItemNewGame, new SeparatorMenuItem(),menuItemChangeSize,menuItemChangeWinSize, new SeparatorMenuItem(),menuItemSaveAs,menuItemLoadGame, new SeparatorMenuItem(),menuItemExit);menuItemNewGame.setOnAction(e -> newGame());menuItemSaveAs.setOnAction(e -> saveAs(primaryStage));menuItemLoadGame.setOnAction(e -> loadGame(primaryStage));menuItemExit.setOnAction(e -> System.exit(0));menuItemNewGame.setAccelerator(KeyCombination.keyCombination("Ctrl+N"));menuItemSaveAs.setAccelerator(KeyCombination.keyCombination("Ctrl+S"));menuItemLoadGame.setAccelerator(

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 7 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
N/A
Tags
Computer file, whoseTurn

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture