Skip to content

This Java program is a Tic Tac Toe game built using JavaFX. It features a 3x3 grid where players alternate marking Xs and Os. The `TicTacToe` class sets up the game interface, handles player moves, and checks for a winner after each turn. It uses a 2D array to track moves and displays a winner alert through an `Alert` box when the game ends.

Notifications You must be signed in to change notification settings

Himanshu-Khadka/TicTacToe-With-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java File path: src/main/java/himanshukhadka/tictactoe/TicTacToe.java

TicTacToe-With-Java

This Java program is a simple implementation of the classic game Tic Tac Toe, utilizing JavaFX to create a graphical user interface. The game is presented on a 3x3 grid where players take turns marking the spaces in an attempt to align three of their marks either horizontally, vertically, or diagonally, thus winning the game.

The main class, TicTacToe, extends the JavaFX Application class, indicating that it is a JavaFX application. It defines a start method, which sets up the game interface. This includes creating a GridPane to represent the game board, where each cell in the grid is interactive and can be clicked to make a move.

Each cell is represented by a Pane and initialized as empty. Clicking a cell triggers a handleMove method, which checks if the space is unoccupied and the game has not yet been won. If these conditions are met, the current player's symbol (X or O) is drawn on the selected cell, and control switches to the other player.

The program checks for a winner after each move. If a player wins, an alert is displayed with a message congratulating the winning player. The game board uses a 2D character array to track the moves of each player, which helps in determining the winner during the game.

This description covers how the game is initialized, how interactions are handled, and how the end of the game is managed. It provides insights into the user interface elements and the logic used to enforce the rules of Tic Tac Toe.

About

This Java program is a Tic Tac Toe game built using JavaFX. It features a 3x3 grid where players alternate marking Xs and Os. The `TicTacToe` class sets up the game interface, handles player moves, and checks for a winner after each turn. It uses a 2D array to track moves and displays a winner alert through an `Alert` box when the game ends.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages