22WJ1A05Z8_RTP (1) (1) (1)

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 33

A REAL TIME PROJECT ON

“TIC TAC TOE”

Submitted to the:
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS(AUTONOMUS)

In partial satisfaction of the requirements for the degree of

BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE & ENGINEERING
By:

YALLA HARSHITH REDDY


ROLL NO.: 22WJ1A05Z8, CSE -5, GNITC

Under the Esteemed Guidance Of


Mr. Devdas Saraswat
(Associate Professor of CSE, GNITC)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (AUTONOMOUS)

SCHOOL OF ENGINEERING AND TECHNOLOGY,


IBRAHIMPATNAM, R.R DISTRICT 501506 2023-2024
Department of Computer Science & Engineering

CERTIFICATE

This is to certify that this Real Time project entitled "TIC TAC TOE GAME
" being submitted by Yalla Harshith reddy(22WJ1A05Z8), in partial
fulfilment for the award of the Degree of Bachelor of Technology in
Computer Science & Engineering of the GuruNanak Institution
Technical Campus, Hyderabad during the academic year 2023-2024, is
a record of bonafide work carried out under our guidance and
supervision at Guru Nanak Institutions Technical Campus
(Autonomous).

Mr. Devdas Saraswat Mr. V. Devasekhar Dr.GeetaTripathi

RTP PROJECT COORDINATOR ACADEMIC COORDINATOR HOD CSE


PROJECT COMPLETION CERTIFICATE

This is to certify that the following students of Second year B. Tech,


Department Of Computer Science and Engineering - Guru Nanak Institutions
Technical Campus (GNITC) have completed their training and project at GNITC
successfully.

STUDENT NAME:
1. YALLA HARSHITH
REDDY
2. ROLL NO :22WJ1A05Z8

The project titled "TIC TAC TOE GAME " in june 2024. The project has been
completed in all aspects.

SIGNATURE
ACKNOWLEDGEMENT

I wish to express my sincere thanks to Dr. Koduganti Venkat Rao, Director, GNITC for providing
meWith the conductive environment for carrying through my academic schedules and project with
ease.

I wish to express my sincere thanks to Dr. Rishi Sayal, Professor &Associate Director, GNITC for
providing me with the conductive environment for carrying through my academic schedules and
project with ease.

I have been truly blessed to have a wonderful adviser Dr. Geeta Tripathi , Professor & HOD of
CSE, GNITC for guiding me to explore the ramification of my work and I express my sincere
gratitudetowards him for leading me throughout the completion of the project.

I would like to say my sincere thanks to Mr. Devdas Saraswat, Associate Professor, Department
of CSE, RTP Project Coordinator, for providing seamless support and right suggestions are given
in the completion of the project.

I specially thank my internal guide Mr.V.Devasekhar, Associate Professor & Academic


coordinator of CSE, GNITC for his suggestions and constant guidance in every stage of the project.

Finally, I would like to thank my family members for their moral support and encouragement to achieve
goals.

YALLA HARSHITH
REDDY

(22WJ1A05Z8)
ABSTRACT

This project involves the development of a Tic-Tac-Toe game using Java, aimed at providing an interactive
and educational experience for players. The game features a graphical user interface (GUI) that allows two
players to compete on a 3x3 grid, following the traditional rules of Tic-Tac-Toe. The application includes
core functionalities such as turn-based play, win condition detection, and draw scenarios. Additionally, it
incorporates basic artificial intelligence (AI) to enable single-player mode, where the player competes against
the computer. This project not only serves as an engaging pastime but also as a practical exercise in
understanding fundamental programming concepts, object-oriented design, and user interface development in
Java. Future enhancements are proposed to expand the game’s capabilities, including online multiplayer
support, advanced AI, and customizable game settings, to enrich the overall user experience.
TABLE OF CONTENT

CHAPTER TITLE PAGE


NO. NO

LIST OF FIGURES
LISTOF SYMBOLS I-IV

1. CHAPTER 1: INTRODUCTION 1-3


1.1 Scope 2
1.2 Objective 3
2. CHAPTER 2: ANALYSIS 4-6
2.1 Existing System 4
2.2 Problem Statement 4
2.3 Proposed System 5
2.4 Feasibility Study 5
2.4.1 Economical Feasibility 5
2.4.2 Technical Feasibility 5
2.4.3 Operational Feasibility 6

3. CHAPTER 3: DESIGN ENGINEERING 7-10


3.1 System Architecture 7
3.2 Module Diagram 8
3.3 Activity Diagram 9
3.4 Class Diagram 9
3.5 Use Case Diagram 10

ii
4. CHAPTER 4: IMPLEMENTATION 11-19
4.1 Purpose 11
4.2 Maintenance 11
4.3 Source Code 12-19

ii
LIST OF FIGURES

FIGURE NAME OF PAGE NO.


NO. THE
FIGURE
3.1 SYSTEM 8
ARCHITECTURE
3.2 MODULE DIAGRAM 8
3.3 ACTIVITY DIAGRAM 9
3.4 CLASS DIAGRAM 10
3.6 USE CASE DIAGRAM 10

iv
CHAPTER 1

INTRODUCTION

1. GENERAL

The evolution of digital games has significantly impacted both entertainment and
education. The system architecture of the Tic Tac Toe game is designed with modularity
and scalability in mind. It comprises several key components: the Game Engine handles
core game logic such as grid initialization, move validation, and win condition checks;
the User Interface module provides a command-line interface for user interaction,
managing input validation and displaying the game board; an Input Manager ensures
proper handling of player inputs, validating moves against game rules and managing
turn sequences; an Output Renderer module displays game states, including current
board configurations and game outcomes; and various utility functions support common
operations like checking for draw conditions and resetting the game. Two-player game,
stands out as an excellent tool for learning fundamental programming concepts. This
project focuses on developing a command-line-based Tic Tac Toe game using JAVA,
offering an accessible way for beginners to grasp essential coding skills. Tic Tac Toe,
also known as Noughts and Crosses, involves two players taking turns to mark a 3x3 grid
with their respective symbols, 'X' or 'O'. The objective is to place three of their marks
in a row, column, or diagonal. The simplicity of Tic Tac Toe makes it an ideal choice
for introducing basic programming constructs such as loops, conditionals, functions, and
user input handling.
1. Scope
The scope of this project includes several key
1
components:
Game Implementation: Creating a functional game board, allowing two players to input
their moves, and ensuring move validation.
User Interaction: Developing a command-line interface that handles user inputs, validates
moves, and provides feedback for invalid entries.
Game Logic: Implementing the core logic to check for win conditions, draw conditions,
and manage player turns.
Educational Value: Focusing on teaching basic Java programming skills and problem-
solving techniques.

Future Extensions: Laying the groundwork for potential enhancements, such as adding a
graphical user interface or implementing an AI opponent.

2. Advantages

Developing a Tic Tac Toe game using Javaoffers a range of advantages that make it an
ideal project for learning and skill enhancement. Firstly, it provides significant
educational value by introducing fundamental programming concepts such as loops,
conditionals, and functions in a practical and engaging context. The interactive nature
of the game allows learners to see immediate results from their code, reinforcing their
understanding through hands-on experience.

3. Disadvantages

While developing a Tic Tac Toe game using Java provides numerous educational
benefits, there are also several disadvantages to consider. One significant limitation is
the game’s simplicity, which may not sufficiently challenge more advanced learners or
those looking to develop more complex problem-solving skills. The basic nature of Tic
2
Tac Toe means
that once the core logic is implemented, there is little room for further intellectual
stimulation without introducing additional complexities..

1.2 Objective:

The primary objective of this project is to help beginners develop fundamental


programming skills through the creation of a command-line-based Tic Tac Toe game
using Java. By working on this project, learners will gain hands-on experience with basic
programming constructs such as loops, conditionals, and functions. Additionally, the
project aims to enhance problem-solving abilities by requiring logical thinking to
implement game logic, validate moves, and handle user input. Another key objective is
to emphasize the importance of writing clean, readable, and maintainable code,
encouraging the use of modular design and proper documentation. . Ultimately, this
foundational project prepares learners for more advanced topics in programming and
game development, such as graphical user interfaces and artificial intelligence, by
providing a solid base of understanding and practical applications

3
CHAPTER -2

ANALYSIS

During this phase, all the relevant information is collected from the customer to
develop a product as per their expectation. Any ambiguities must be resolved in
this phase only.
1. Existing System
Tic Tac Toe, a classic game known for its simplicity, has seen numerous
implementations across various platforms. Traditional physical board games
feature a 3x3 grid where players mark 'X' or 'O' to achieve a row, column, or
diagonal of their symbol. In the digital realm, Tic Tac Toe has been adapted into
countless software applications, ranging from basic command-line interfaces to
sophisticated graphical versions with AI opponents and online multiplayer
capabilities. These implementations cater to diverse audiences, from casual
players seeking quick entertainment to enthusiasts looking for strategic
challenges.
2. Problem Statement
Despite the prevalence of Tic Tac Toe games, existing implementations often
prioritize entertainment over educational value, making them less suitable for
beginners learning programming concepts. Many current systems lack
transparency in game logic and code accessibility, hindering learners'
understanding of underlying programming principles. Moreover, some
implementations introduce unnecessary complexity, such as advanced AI
algorithms or intricate graphical interfaces, which can obscure foundational
programming concepts. There is a clear need for a straightforward and

4
educational Tic Tac Toe implementation that serves as a practical introduction
to programming, emphasizing clear code structure and interactive learning.
3. Proposed System
The proposed system aims to address these shortcomings by developing a
command-line-based Tic Tac Toe game using Java. This system will prioritize
educational value by providing transparent and well-documented code that
demonstrates fundamental programming constructs such as loops, conditionals,
functions, and basic data structures. The game will feature a minimalist
command-line interface designed for simplicity and clarity, allowing two
human
players to interact directly with the game board. Key functionalities will include
move validation, win condition checks, and immediate feedback on game state
after each turn. By focusing on straightforward implementation and clear user
interaction, the proposed system aims to serve as an effective educational tool
for beginners while laying a foundation for deeper exploration into
programming and game development concepts.
4. Feasibility Study
1. Economical Feasibility
Economically, developing a Tic Tac Toe game using Java is highly feasible.
Java is an open-source programming language with a vast community and
extensive resources available at no cost. The development costs primarily
involve the time and effort invested by developers in coding, testing, and
documenting the game. There are minimal financial implications beyond the
initial investment in learning Python and understanding basic programming
principles, making the project economically viable for educational purposes.
2. Technical Feasibility
Technically, implementing a command-line Tic Tac Toe game in Java is
straightforward due to the language's clear syntax and built-in data structures.
Python's simplicity facilitates the implementation of game mechanics such as
grid 5
manipulation, move validation, and win condition checks. The command-line
interface provides a direct and intuitive user experience, ensuring that beginners
can easily understand and interact with the game. Python's platform
independence further enhances technical feasibility, allowing the game to run
seamlessly on various operating systems without significant compatibility
issues.
2.4.3 Operational Feasibility
Operationally, the proposed system is designed to be user-friendly and efficient.
The command-line interface simplifies user interactions by focusing on
essential functionalities: inputting moves, displaying the game board, and
determining game outcomes. Robust error handling mechanisms will be
implemented to manage invalid inputs and ensure smooth gameplay.

6
CHAPTER-3

DESIGN

In this phase, the requirement gathered in the SRS document is used as an


input and software architecture that is used for implementing system
development is derived.

Once the requirement is clear, a system is designed i.e. architecture,


components of the product are created and documented in a design document.

(i)High-Level Design:High-level design defines the architecture/design


of modules. It defines the functionality between the two modules.

(ii)Low-Level Design:Low-level Design defines the architecture/design


of individual components.
3.1 System Architecture
The system architecture of the Tic Tac Toe game is designed with modularity
and
scalability in mind. It comprises several key components: the Game Engine
handles core game logic such as grid initialization, move validation, and win
condition checks; the User Interface module provides a command-line interface
for user interaction, managing input validation and displaying the game board;
an Input Manager ensures proper handling of player inputs, validating moves
against

7
game rules and managing turn sequences; an Output Renderer module displays
game states, including current board configurations and game outcomes; and
various utility functions support common operations like checking for draw
conditions and resetting the game.

3.2 Module Diagram

The module diagram illustrates the modular structure of the Tic Tac Toe game,
highlighting distinct components such as the Game Engine module, responsible
for initializing the game, managing player turns, and evaluating win conditions;

8
the User Interface module, handling user inputs, validating moves, and
displaying the game board; and the Utility module, containing helper functions
for checking game states and managing overall game flow.

3.3 Activity Diagram

The activity diagram outlines the flow of actions within the Tic Tac Toe game,
including the initialization of the game board and player setup, the alternation
between players for inputting moves, the validation of each move against
current game state, the evaluation of win conditions to determine game
outcomes, and the option for players to restart the game after a win, draw, or
when desired.

3.4 Class Diagram

The class diagram depicts the object-oriented structure of the Tic Tac Toe game,
showing classes such as GameBoard, representing the 3x3 grid with methods
for updating and displaying its state; Player, defining attributes and methods for
each player including their symbol ('X' or 'O') and current turn status;
and 9
GameManager, coordinating the game flow by handling initialization, player
turns, move validation, and win condition checks.

3.6 Use Case Diagram

The use case diagram outlines interactions between users and the Tic Tac Toe
game system, detailing how players input moves, receive output displaying the
current game state, and have the option to restart the game upon completion.

10
CHAPTER -4

IMPLEMENTATION & CODING

Implementation/Coding starts once the developer gets the Design document.


The Software design is translated into source code. All the components of the
software are implemented in this phase.

1. Purpose

The implementation of the Tic Tac Toe game in serves both educational and
practical purposes. Primarily, it provides beginners with a practical introduction
to fundamental programming concepts such as loops, conditionals, functions,
and basic data structures like lists. By developing this game, learners can gain
hands- on experience in problem-solving and logic implementation within the
context of a simple command-line interface. The project emphasizes best
practices in coding, including modularity, documentation, and error handling,
essential for maintaining clean and efficient code. Beyond educational
objectives, the game aims to offer an enjoyable and interactive experience for
players, demonstrating how foundational programming concepts can be
applied to create functional software.

2. Maintenance

Maintenance of the Tic Tac Toe game project involves ongoing efforts to ensure
its functionality, usability, and adaptability over time. This includes regular bug
fixes to address any issues or errors encountered during gameplay, such as

11
incorrect move validation or display inconsistencies. Enhancements based on
user feedback or project goals, such as adding graphical user interfaces,
implementing AI opponents, or introducing multiplayer capabilities, are also
part of maintenance efforts. Documentation updates are crucial for keeping all
project- related information current and accessible, including explanations of
game rules, code structure, and usage instructions. Code refactoring is
another aspect of maintenance, aimed at improving code quality by
restructuring or optimizing existing code for better readability, performance,
and maintainability. Utilizing version control systems like Git helps manage
changes, track project evolution, and ensure stability across different iterations
of development.

4.3. Source Code

Import java.util.Scanner;

Public class TicTacToe {

Private char[][] board;

Private char currentPlayer;

Private char player1Symbol;

Private char player2Symbol;

Public TicTacToe(char player1Symbol, char player2Symbol) {

This.player1Symbol = player1Symbol;

This.player2Symbol = player2Symbol;

Board = new char[3][3];

12
currentPlayer = player1Symbol; // Player 1 starts the
game

initializeBoard();

// Initialize board with empty


spaces

Private void initializeBoard()

{ For (int I = 0; I < 3; i++) {

For (int j = 0; j < 3; j++) {

Board[i][j] = ‘-‘;

// Print the current board state

Private void printBoard()

{ System.out.println(“-------------“

);

For (int I = 0; I < 3; i++) {

System.out.print(“| “);

For (int j = 0; j < 3; j++)

{
13
System.out.print(board[i][j] + “ | “);

System.out.println();

System.out.println(“-------------“);

// Check if the board is full

Private boolean isBoardFull() {

Boolean isFull = true;

For (int I = 0; I < 3; i++) {

For (int j = 0; j < 3; j++) {

If (board[i][j] == ‘-‘) {

isFull = false;

Return isFull;

14
}

// Check if there is a winner

Private boolean checkForWin() {

Return (checkRowsForWin() || checkColumnsForWin() ||


checkDiagonalsForWin());

// Check rows for a win

Private boolean checkRowsForWin() {

For (int I = 0; I < 3; i++) {

If (checkRowCol(board[i][0], board[i][1], board[i][2])) {

Return true;

Return false;

// Check columns for a win

Private boolean checkColumnsForWin() {

15
For (int I = 0; I < 3; i++) {

If (checkRowCol(board[0][i], board[1][i], board[2][i])) {

Return true;

Return false;

// Check diagonals for a win

Private boolean checkDiagonalsForWin() {

Return (checkRowCol(board[0][0], board[2][2]) ||


board[1][1], checkRowCol(board[0][2], board[1][1],
board[2][0]));
}

// Check if all three values are the same (and not empty) indicating a
win

Private boolean checkRowCol(char c1, char c2, char c3) {

Return (c1 != ‘-‘ && c1 == c2 && c2 == c3);

// Change player turns

16
Private void changePlayer() {

If (currentPlayer == player1Symbol) {

currentPlayer = player2Symbol;

} else {

currentPlayer = player1Symbol;

// Place a mark on the board at position (row, col) for the current player

Private void placeMark(int row, int col) {

If (row >= 0 && row < 3 && col >= 0 && col < 3 && board[row][col] ==
‘-‘) {

Board[row][col] =

currentPlayer; If

(checkForWin()) {

System.out.println(“Player “ + currentPlayer + “ wins!”);

changePlayer();

} else {

System.out.println(“Invalid move. Try again.”);

}
17
}

Public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print(“Enter player 1’s symbol: “);

Char player1Symbol = scanner.next().charAt(0);

System.out.print(“Enter player 2’s symbol: “);

Char player2Symbol = scanner.next().charAt(0);

TicTacToe game = new TicTacToe(player1Symbol, player2Symbol);

Int row, col;

While (!game.isBoardFull() && !game.checkForWin()) {

System.out.println(“Current board:”);

Game.printBoard();

System.out.println(“Player “ + game.currentPlayer + “, enter your move


(row [1-3] column [1-3]): “);

18
// Input handling and adjustment from 1-based to 0-based
index

Row = scanner.nextInt() – 1;

Col = scanner.nextInt() – 1;

Game.placeMark(row, col);

// Game over – print final board and winner (if any)

Game.printBoard();

If (!game.checkForWin() && game.isBoardFull()) {

System.out.println(“It’s a draw!”);

Scanner.close();

This implementation allows for two players to play Tic Tac Toe with custom
symbols and ensures proper handling of turns, input validation, and
determining the winner.

19
CHAPTER-5

TESTING

When testing a Tic Tac Toe game project in Java, it's important to cover various aspects of the
game to ensure its correctness and reliability. Here’s a guide to what you should consider and
the types of tests you might perform: ### 1. **Unit Testing** Unit testing involves testing
individual components or units of your game logic to ensure they function correctly in
isolation. The primary focus is on the following: - **Game Initialization**: Ensure that the
game board is initialized correctly, with all cells empty. - **Move Validation**: Verify that
the game correctly handles valid and invalid moves. A move is valid if it is within the
bounds of the board and the cell is not already occupied. - **Win Condition**: Ensure
that the game accurately detects when a player has won. This involves checking all rows,
columns, and diagonals for three identical marks. - **Draw Condition**: Verify that the
game correctly identifies a draw when the board is full and there is no winner. - **Turn
Management**: Ensure that the game alternates correctly between players (e.g., from player
X to player O). ### 2.
**Integration Testing** Integration testing ensures that different parts of the system work

20
together correctly. In the context of a Tic Tac Toe game, this might include: - **Game Flow**:
Verify that the game transitions correctly between different states (e.g., from an ongoing game
to a win or draw). - **Game State Management**: Ensure that the game state is maintained
correctly across multiple moves, including updating the board, alternating turns, and checking
for win/draw conditions. - **Input Handling**: Test the integration between the user input
(e.g., clicks on the GUI or command-line inputs) and the game logic to ensure inputs are
processed correctly. ### 3. **UI Testing** If your Tic Tac Toe game has a graphical user
interface (GUI), UI testing is essential to ensure that the interface behaves as expected. This
includes: TIC-TAC-TOE GAME - **Button Functionality**: Verify that buttons for each cell
on the board respond correctly to user clicks, displaying the appropriate player's mark. -
**Game Status Display**: Ensure that the UI correctly displays the current game status, such
as whose turn it is, and whether the game has been won or drawn. - **Reset Functionality**:
Test the functionality to reset the game, ensuring that the board is cleared and the game state
is reinitialized. ### 4. **End-to-End Testing** End-to-end testing involves testing the entire
application flow, from start to finish, as a user would interact with it. This includes: -
**Starting a New Game**: Verify that starting a new game initializes the board and sets the
game to the correct starting state. - **Playing the Game**: Test playing through a full
game, including making moves, switching turns, and reaching a win or draw. - **Handling
Edge Cases**: Ensure that the game handles edge cases gracefully, such as attempting to
make a move after the game has ended. ### Best Practices for Testing - **Automate
Tests**: Use automated testing frameworks such as JUnit for unit and integration tests. For
GUI tests, consider using tools like TestFX for JavaFX applications. - **Test-Driven
Development (TDD)**: Consider using TDD, where you write tests before implementing the
corresponding functionality. This can help ensure that your code meets the specified
requirements from the start. - **Code Coverage**: Aim for high code coverage with your
tests, ensuring that all critical paths and edge cases are tested. - **Continuous Integration
(CI)**: Integrate your tests into a CI pipeline to automatically run tests whenever changes
are made, ensuring that new code does not introduce regressions. By following these
guidelines and thoroughly testing each aspect of your Tic Tac Toe game, you can ensure a
robust and reliable application.

21
CHAPTER-6

POST IMPLEMENTATION

After completing your project cycle, you should carry out a post-implementation
review (PIR). The essence of a PIR is to discover if you met project objectives and
to identify any existing flaws in the project. Project management continues until you
complete the PIR process.

6.1 Purpose

The purpose of the post-implementation phase is to ensure the Tic Tac Toe game continues to
function correctly and remains useful and enjoyable for users after its initial deployment. This
phase focuses on monitoring the game’s performance in real-world scenarios, gathering user
feedback, and making necessary adjustments or improvements. By continually assessing the
game’s usability, reliability, and user satisfaction, developers can identify and address any

22
Result Analysis:

23
25
CHAPTER-7

CONCLUSION & ENHANCEMENT

7.1 Future Enhancement

One significant enhancement for the Tic-Tac-Toe game would be the integration of network
play, allowing players to compete against each other over the internet. This feature would
involve implementing socket programming to facilitate real-time communication between
devices. By enabling online multiplayer functionality, the game would offer a more dynamic
and interactive experience, appealing to a broader audience. Additionally, incorporating
features such as chat capabilities, matchmaking, and ranking systems would further enhance
the user experience, making the game more engaging and competitive.

7.2 Conclusion

Developing a Tic-Tac-Toe game in Java has provided a comprehensive learning experience,


covering fundamental aspects of programming, such as game logic implementation, user
interface design, and event handling. This project has not only reinforced core coding skills but
also introduced the principles of software design and user interaction. By successfully creating
a functional and enjoyable game, you have laid a strong foundation for future software
development projects. The skills and knowledge gained through this process will be invaluable
as you continue to explore more complex and sophisticated programming challenges.

26

You might also like