0% found this document useful (0 votes)
5 views13 pages

Approval

The document outlines a final semester project for a BS-CS program, detailing the development of a console-based Tic Tac Toe game using C++. It highlights the game's features, including interactive visuals, sound effects, robust input handling, and the ability to replay or exit after each round. The project aims to enhance traditional implementations by providing a more engaging user experience while fulfilling academic requirements.

Uploaded by

Zain Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views13 pages

Approval

The document outlines a final semester project for a BS-CS program, detailing the development of a console-based Tic Tac Toe game using C++. It highlights the game's features, including interactive visuals, sound effects, robust input handling, and the ability to replay or exit after each round. The project aims to enhance traditional implementations by providing a more engaging user experience while fulfilling academic requirements.

Uploaded by

Zain Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

BS-CS FINAL SEMESTER PROJECT

Game “Tic Tac Toe”

Program: BS-CS
Batch: 2024-2028

Project Advisor: Mr. Mohsin Raza

Submitted By

Ali Hamza
Muhammad Haroon 14
Muhammad Amir 19
STATEMENT OF SUBMISSION

This is to certify that Ali Hamza Roll No , Muhammad Haroon Roll No.
14,Muhammad Amir Roll No.19 have successfully completed the final semester
project name as game “tic tac toe” at the faculty of CS, Al-Shifa Institute of
Health Science Narowal, to fulfil the partial requriment of the degree of
Bacheloys in computer science.

Project Advisor Director HOD of CS


Mr. Mohsin Raza AIHS
Faculty of CS, AIHS
Tic Tac Toe

By
Ali Hamza
Muhammad Haroon
Muhammad Amir

DEGREE

Bachelor of Science in computer science

Department of Computer Science

University of AIHS
Session 2024-2028
ACKNOWLEDGEMENTS

We would like to express our deepest appreciation to a


personality who provided us the possibility to complete this
project. A special gratitude we give to our final semester
project coordinator Mr. Mohsin Raza , whose suggestions and
encouragement helped us to complete this project.

Ali Hamza:
Muhammad Haroon:
Muhammad Amir:
INTRODUCTION
This project is a console-based implementation of the classic Tic Tac Toe game developed using C++. It
is designed as part of our final semester project, focusing on basic concepts of arrays, control structures,
functions, and console manipulation.

The game is built for two players (Player 1 as 'X' and Player 2 as 'O') who take turns marking spaces in a
3×3 grid. The first player to align three of their marks in a horizontal, vertical, or diagonal row wins the
game. If all positions are filled and no player wins, the game results in a draw.

Key features include:

 Interactive and colorful console UI using SetConsoleTextAttribute()


 Input validation and error handling
 Sound effects with Beep() for each player's move
 Option to replay or exit after each round

The project not only demonstrates logical structuring and game design fundamentals, but also provides an
engaging user experience in a simple terminal environment.

Background and Existing System

Tic Tac Toe, also known as "Noughts and Crosses," is a simple yet engaging two-player game that has been
popular for decades. Traditionally played on paper, it involves two players taking turns to mark spaces in a
3×3 grid, aiming to place three of their marks in a row—horizontally, vertically, or diagonally.

In the realm of programming and software development, Tic Tac Toe is commonly chosen as a beginner-
level project due to its straightforward logic and manageable implementation. It helps learners grasp
fundamental programming concepts such as loops, conditionals, functions, arrays, and user input handling.

Existing System:

The traditional implementation of Tic Tac Toe has been done in various programming languages and
platforms—ranging from paper-based and mobile apps to web and graphical interfaces. However, most
existing implementations either:

 Are GUI-based and rely on external frameworks or libraries (e.g., using JavaFX, Python Tkinter, or
Unity).
 Provide minimal interactivity when done via console, often lacking color, sound, or real-time
feedback.
 Have limited user experience features such as proper input validation, error handling, or replay
options.

Our project aims to enhance the standard console-based Tic Tac Toe by introducing a more interactive and
visually appealing user experience using C++ and Windows console functions. This includes:

 Use of SetConsoleTextAttribute() for colored output to differentiate players and enhance


readability.
 Beep() function for sound effects during player moves to make the game more lively.
 Full input validation, handling incorrect inputs and already-filled boxes gracefully.
 Clean, structured grid representation for better clarity.
 Option to replay the game or exit after each round.

By doing so, we bridge the gap between a simple console-based game and a more immersive experience—
all without needing any external libraries or advanced GUI frameworks.

Problem Statement

Traditional Tic Tac Toe games are either played on paper or implemented in very basic formats via console or GUI
applications. However, most implementations lack the aesthetic presentation, player-friendly feedback, and
immersive features such as audio cues and colored UI.

 Minimal visual appeal in most basic console implementations.


 No auditory feedback for player actions.
 No validation for invalid inputs, which can lead to crashes or confusion.
 Lack of game reset or replay functionality.

Existing System

This program is a console-based two-player Tic Tac Toe game, implemented in C++ with added visual and sound
features for enhanced user experience.

Proposed System

The proposed system is a fully interactive two-player Tic Tac Toe game developed in C++, designed to overcome the
limitations of traditional console-based implementations. It integrates colorful visuals, sound effects, and robust
input handling to deliver a more engaging and user-friendly experience.

1. Colorful Console Interface:

 Utilizes the SetConsoleTextAttribute function (Windows API) to add vivid colors.


 Differentiates Player 1 (X) and Player 2 (O) using distinct color codes.
 The Tic Tac Toe board is neatly organized to enhance visual clarity and gameplay feel.

2. Audio Feedback:

 Employs the Beep() function to generate distinct tones when a player makes a move:
 Provides auditory cues for improved immersion.

3. Robust Input Handling:

 Detects and handles non-numeric and out-of-range inputs gracefully.


 Prevents players from overwriting an already-filled cell and displays a warning.
 Avoids game crashes due to invalid input, ensuring smooth gameplay.

4. Win/Draw Detection:

 Checks all possible winning conditions (rows, columns, diagonals).


 Declares a draw if all cells are filled with no winner.
5. Game Replay Option:

 After each round, players are prompted to play again or exit.


 If chosen to replay, the game board is automatically reset for a new round.

6. Exit Option:

 Players can exit the game at any point by entering ‘0’.

Main Modules

1. Global Variables

 char board[3][3] — Represents the game board with initial values.


 char turn — Tracks current player (X or O).
 int row, column — Store chosen cell coordinates.
 bool draw — Tracks if the game ends in a draw.

2. setColor(int color)

 Uses Windows API to set the console text color.

3. display_board()

 Clears the screen and draws the game board using color-coded tiles for X (green), O (red), and numbers
(white).
 Visually structured and uses ASCII box drawing.

4. play_sound(char player)

 Plays a beep with different pitch based on the player:


o X = higher tone (750 Hz)
o O = lower tone (500 Hz)

5. player_turn()

 Asks the current player for input.


 Handles input validation and errors.
 Updates the board with player's move and switches turn.

6. gameover()

 Checks for:
o Winning conditions (rows, columns, diagonals).
o Draw condition (no empty spaces left).
 Returns true if the game is still going, false otherwise.

7. main()

 Displays welcome message and authors.


 Game loop:
o Runs the game until a win or draw is detected.
o Displays result (winner or draw).
o Prompts user to play again or exit.
o Resets the board if playing again.

Expected Outcome
1. Welcome Screen

When the game starts, it shows a colorful welcome message with credits:

Waits 3 seconds before moving on...

2. Game Board Display

A visually structured, colorful 3x3 grid like this appears:

Each number represents a spot a player can pick. As players pick spots, numbers are replaced with X or O, colored
accordingly:

 Player 1 (X) → Green


 Player 2 (O) → Red

3. Player Turn Prompt

Each player is asked to make a move:

--> Enter the number(1.....9) or 0 to Exit:

If a player enters:

 A valid number (1–9): Game updates the board and plays a beep.
 0: Exits the game with a goodbye message.
 Invalid input (non-number or out of range): Shows an error and re-prompts.

4. Sound Effects

After each move:

 Player 1 (X) → Beep at 750 Hz


 Player 2 (O) → Beep at 500 Hz

5. Handling Invalid Moves

If a player picks a filled box:

6. Game Over Conditions

 Winning: If 3 in a row is achieved:

 Draw: If the board is full and no winner:

7. Play Again Prompt

After the game ends:


 If '1': Board resets, game restarts
 If '2': Exits with message:

Tools & Technology

Tools & Technology version Purpose


Laptop
Dev C++ 5.0 (4.9.9.2)
development
Programming
C++
language
REQUIREMENT ANALYSIS

✅ Functional Requirements

1. Two-Player Game Support


o Supports two players: Player 1 (X) and Player 2 (O).
o Alternates turn between players.
2. Game Board Display
o 3x3 grid visualized in the console.
o Each cell initially numbered 1 to 9.
o Uses ASCII art with borders and styled layout.
o Board updates after every valid move.
3. Player Input Handling
o Players input a number (1–9) to make their move.
o Option 0 exits the game immediately.
o Prevents overwriting already occupied cells.
o Input is validated to avoid crashes from non-numeric input.
4. Game Logic
o Checks for win conditions:
 Rows, columns, and diagonals.
o Detects draw when all cells are filled with no winner.
5. Sound Feedback
o Plays a distinct beep (Beep) for each player (X and O) on their move.
6. Console Color Coding
o Different colors for:
 Titles, instructions, players, and board pieces.
o Highlights active player input and game status.
7. Game Replay Option
o After each game ends, players can:
 Play again (1).
 Exit (2).
o Board and states reset on replay.
8. Credits and Loading
o Displays a welcome screen with contributors.
o Shows a loading message with a delay before game starts.

🛠 Non-Functional Requirements

1. Platform Dependency
o Uses Windows-specific headers and functions:
 windows.h for Beep() and console color.
 system("cls") for screen clearing.
 Not portable to Unix/Linux without modification.
2. User Experience
o Engaging via color, sound, and layout.
o Clearly communicates errors and guides the user.
3. Performance
o Lightweight and runs smoothly on standard consoles.
o Efficient checking logic for win/draw conditions
TESTING

1) Sound problem
Solve :
void play_sound(char player)
{
if (player == 'X')
{
Beep(750, 300);
}
else if (player == 'O')
{
Beep(500, 300);
}
}

2) Exit problem
Solve :

cout << "\n\t\t\t\t\t Exiting... Until Next Time! ";


sleep(2);
exit(0);

3)Restart problem
Solve :

bool play_again = true;


while (play_again)
{
int choice;
cout << "\n\tPress '1' to Play Again and '2' to
Exit\n\t";
cin >> choice;
if (choice == 1)
{
play_again = true;
}
else
{
play_again = false;
}

sleep(2);
}
CONCLUSION & FUTURE WORK

Conclusion

The Tic Tac Toe game successfully provides an interactive and visually appealing experience for two players. With a
colorful console UI, basic sound feedback, and proper input handling, it brings a traditional paper-and-pencil game to
life in a digital format. The game logic correctly handles win conditions, draws, and input validation, ensuring a
smooth and error-free user experience. The inclusion of player turn indicators and feedback for invalid inputs further
enhances the usability of the game.

Future Work

To further enhance the game, the following improvements could be implemented:

1. AI Opponent: Introduce a single-player mode with an AI opponent using minimax or heuristic logic.
2. Mouse Input Support: Use Windows API for mouse input to make gameplay more intuitive.
3. Save & Load Feature: Allow players to save the game state and resume later.
4. Score Tracking: Keep track of scores across multiple rounds for both players.
5. Enhanced UI Elements: Add animations or graphical elements using a game library like SFML or SDL.
6. Cross-Platform Support: Refactor the code to remove Windows-specific dependencies like windows.h and
Beep(), making it compatible with Linux/MacOS.
7. Sound Customization: Allow players to choose or mute game sounds.
8. Difficulty Levels: For single-player mode, add difficulty settings to make the AI more or less challenging

You might also like