Giter Site home page Giter Site logo

java_tictactoe's Introduction

Tic Tac Toe Game

This is a simple console-based implementation of the popular Tic Tac Toe game using Java. The game features a 3x3 board with two players, X and O, who take turns marking the spaces in the grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner.

How to Play

To play the game, simply run the program in any Java IDE or from the command line. The game starts with an empty board and the prompt for X player to make the first move. The player should enter a number between 1 and 9 to mark the respective square on the board. The game continues until a player wins or the board is full and the game ends in a draw.

Implementation

The game logic is implemented in a single TicTacToe class that uses a board array to store the moves and a turn variable to keep track of whose turn it is. The checkWinner() method checks the board for any winning combination, and returns the winner (if there is one) or null if the game is still in progress. The printBoard() method prints out the current board on the console.

The main method of the TicTacToe class implements the game loop that takes input from the user, updates the board, and checks for the winner. It also includes input validation and error handling for invalid inputs.

Conclusion

This Tic Tac Toe game is a simple and fun project that demonstrates the basics of Java programming, including arrays, control structures, and user input handling.

java_tictactoe's People

Contributors

p4r1nc3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.