SlideShare a Scribd company logo
1 of 31
Presented By : UTKARSH AGGARWAL
3 July, 2017
(Console Game) C++ Program
ACKNOWLEDGEMENT
I wish to express my deep gratitude and sincere thanks toI wish to express my deep gratitude and sincere thanks to
the principal ,Mrs. Shashi Jain , Vanasthali Public school forthe principal ,Mrs. Shashi Jain , Vanasthali Public school for
her encouragement to make this project .her encouragement to make this project .
I extend my hearty thanks to Mrs. Sarika Gupta, ourI extend my hearty thanks to Mrs. Sarika Gupta, our
Computer teacher , who guided me to the successfulComputer teacher , who guided me to the successful
completion of this project .completion of this project .
INDEX
1.1. Short introduction To C++Short introduction To C++
2. Introduction to Tic Tac Toe (Console Game) C++ Program
3.3. System RequirementsSystem Requirements
4.4. CodingCoding
5.5. Output ResultOutput Result
6. Initialization Of Variables &explanatory statements
7. Game Loops
8.8. BibliographyBibliography
Short Introduction To C++
C++ is a general-purpose programming language.
It has imperative, object oriented and generic
programming features, while also providing
facilities for low-level memory manipulation.
It was designed with a bias toward system programming and embedded,
resource-constrained and large systems, with performance,
efficiency and flexibility of use as its design highlights. C++
has also been found useful in many other contexts, with key
strengths being software infrastructure and resource-
constrained applications , including desktop applications, servers (e.g. e-
commerce, web search or SQL servers), and performance-critical
applications (e.g. telephone switches or space probes).C++ is
a compiled language, with implementations of it available on many platforms.
Introduction to Tic Tac Toe
(Console Game) C++ Program
This program is a game program, Tic Tac
Toe. Most of us have played this game in
our leisure time, and we have make a C+
+ program on it.
Tic-tac-toe (or Noughts and crosses, Xs and Os) is a pencil-
and-paper game for two players, X and O, who take turns
marking the spaces in a 3×3 grid. The player who succeeds
in placing three respective marks in a horizontal, vertical, or
diagonal row wins the game.
Introduction to Tic Tac Toe
(Console Game) C++ Program
This game uses board to control players
In each turn players enter a number and
choose a move
Simplify programing assumes that player
one always moves first and uses X's
Player two moves at 2nd position and
uses O's
A Sample Screen Shot of a Game
System Requirements
• Operating system: Windows XP, Vista 7 and 8 .
• Processor : Pantium III/1.4 GHz processor.
• RAM:512 MB
• Hard Disk:900 MB Space required
Tic Tac Toe
(Console Game) C++ Program
How the program structured :
At the time when program start we initialize variables, and we run
the game loop until the game end or players choose to quit
The game consists of three steps
• Display board
• Get players move
• Check for game end
CODING
# include <iostream.h>
#include <conio.h>
char square[10] = {'o','1','2','3','4','5','6','7','8','9'};
int checkwin();
void board();
int main()
{
int player = 1,i,choice;
char mark;
clrscr();
do
{
board();
player=(player%2)?1:2;
cout << "Player " << player << ", enter a number: ";
cin >> choice;
mark=(player == 1) ? 'X' : 'O';
if (choice == 1 && square[1] == '1')
square[1] = mark;
else if (choice == 2 && square[2] == '2')
square[2] = mark;
else if (choice == 3 && square[3] == '3')
square[3] = mark;
else if (choice == 4 && square[4] == '4')
square[4] = mark;
else if (choice == 5 && square[5] == '5')
square[5] = mark;
else if (choice == 6 && square[6] == '6')
square[6] = mark;
else if (choice == 7 && square[7] == '7')
square[7] = mark;
else if (choice == 8 && square[8] == '8')
square[8] = mark;
else if (choice == 9 && square[9] == '9')
square[9] = mark;
else
{
cout<<"Invalid move ";
player--;
getch();
}
i=checkwin();
player++;
}
while(i==-1);
board();
if(i==1)
cout<<"==>aPlayer "<<--player<<" win ";
Else
cout<<"==>aGame draw";
getch();
return 0;
} /*********************************************
FUNCTION TO RETURN GAME STATUS
1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
O GAME IS OVER AND NO RESULT
**********************************************/
int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;
else if (square[4] == square[5] && square[5] == square[6])
return 1;
else if (square[7] == square[8] && square[8] == square[9])
return 1;
else if (square[1] == square[4] && square[4] == square[7])
return 1;
else if (square[2] == square[5] && square[5] == square[8])
return 1;
else if (square[3] == square[6] && square[6] == square[9])
return 1;
else if (square[1] == square[5] && square[5] == square[9])
return 1;
else if (square[3] == square[5] && square[5] == square[7])
return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3' &&
square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7] != '7'
&& square[8]!=‘8’&&square[9]!=‘9’)
return 0;
else
return -1;
}
/*******************************************************************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
********************************************************************/
void board()
{
clrscr();
cout << "nntTic Tac Toenn";
cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
cout << endl;
cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;
cout << " | | " << endl << endl;
}
/*******************************************************************
END OF PROJECT
OUTPUT
Presented by: Utkarsh aggarwal
Initialization Of Variables &
explanatory statements
This portion of code is for initialization of variables,
the variables of squares are initializing with the
characters from 1 to 9.
The player turn will be initializing to 1 because since
the player 1 makes the first turn
Game over is initialize to true but that does not really
matter for this program because after game loop
game check itself for winner.
Presented by: utkarsh aggarwal
Initialization Of Variables &
explanatory statements
Program comments are explanatory statements that we can include in the C++ code
that we write and helps anyone reading its source code. All programming languages
allow for some form of comments.
C++ supports single line and multi-line comments. All characters available inside any
comment are ignored by C++ compiler.
C++ comments start with /* and end with */. For example:
// This is a comment
/* C++ comments can also
span multiple lines
*/
Presented by: Utkarsh aggarwal
Game Loops
After initialization game began to move forward for main game
loop these loops are while and do while loop which are
encapsulated in statements that what to do or not to do.
Once we enter the game loop
The first thing will be done is print
the game board which displays the
tic tac toe game board in console
window
Remember we initialize these
squares with characters from 1 to 9
for basic console input and output.
Presented by: Utkarsh aggarwal
Game Loops
When we run the program the board looks like this
!!Notice that the console window
prompts the player for move
The player's moves are handled by
the next portion of code!!
Game Loops
( player's moves )
cPlayerMark determines that first player has X and second has 0
This portion of statements check for player turn if it's not the first
player move its promoted the move to next player
Then the next line gets the valid move of the player
Presented by: Utkarsh aggarwal
Game Loops
( player's moves )
If players input an invalid move it's prompted for another
move and says try again like this ..
A Screen Shot of an Invalid Move
Presented by: Utkarsh aggarwal
Game Loops
( player's moves )
The cin statement gets the valid
move for the player
Notice that it's begin with another
loop it has pretty much statements to
check the conditions.
The check for valid move is pretty
large branch of square check.
Presented by: Utkarsh aggarwal
Game Loops
( player's moves )
Each branch of the if statement makes two check, the first input
check that the input is valid digit from 1 to 9 and second check is for
make sure of the input is digit not an character, second check also
make sure that the number which is entered not entered
Previously
Presented by: Utkarsh aggarwal
Game Loops
( player's moves )
After the valid move the series of checks perform to check
the games conditions.
Note there are the nine ways to end the game, 8 conditions
to win the game and 1 condition for draw the game.
The first conditions check the ending game condition
through
the walls of 1st square.
Presented by: Utkarsh aggarwal
Game Loops
( player's moves )
The second if statement handles the 4 cases from
the middle 5th square .
Presented by: Utkarsh aggarwal
Game Loops
( player's moves )
The third if statement handles the 2 cases from the 9th square
In each of these cases we check that the squares not equals to its number
character.
This check ensures that we have an extra O and the other two checks make
sure that the other two squares have the same O in the series like this one
Those cases cover the win condition however game will be ended and draw like
this.
Presented by: Utkarsh aggarwal
Game Loops
( player's moves )
Screen Shot “ Game Draw”
Presented by: Utkarsh aggarwal
Game Loops
(Final Check)
After that we print the ending board of the game and tells
whose win and ask the user to play another game or quit
If the user want play again the looping is continue and the
board will be reset and the player turn also set back to 1
On the other hand the game will be quit .
Presented by: Utkarsh aggarwal
Game Loops
(Final Check)
The final check takes cover of the case that game will be draw
and all the squares will be marked.
When we determine that the game is over we run through over
final condition
If the game is over we check for the game that someone is win
the game Boolean which we set at the last part, if some has
won then it will be last one or last player which is moved.
Presented by: Utkarsh aggarwal
Tic Tac Toe | (Console Game) C++ Program
Hope you Enjoy & Learn Something
BIBLIOGRAPHY
•Help from internet
2007 Xoax[xoax.net ( C++ Lesson # 9 )]
http://www.cppforschool.com
http://www.geeksforgeeks.org
•Help from book
Introduction to C++(sumita arora)
•Help from friends

More Related Content

What's hot

C++ projct
C++ projctC++ projct
C++ projctJ M
 
Tic Tac Toe Project
Tic Tac Toe Project Tic Tac Toe Project
Tic Tac Toe Project KanikaJawla
 
Design phase of game development of unity 2d game
Design phase of game development of unity 2d game Design phase of game development of unity 2d game
Design phase of game development of unity 2d game Muhammad Maaz Irfan
 
Initial design (Game Architecture)
Initial design (Game Architecture)Initial design (Game Architecture)
Initial design (Game Architecture)Rajkumar Pawar
 
Final year project presentation
Final year project presentationFinal year project presentation
Final year project presentationSulemanAliMalik
 
Rock paper-scissors
Rock paper-scissorsRock paper-scissors
Rock paper-scissors2gymkori
 
Android Application And Unity3D Game Documentation
Android Application And Unity3D Game DocumentationAndroid Application And Unity3D Game Documentation
Android Application And Unity3D Game DocumentationSneh Raval
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game DevelopmentSumit Jain
 
Car racing game for android
Car racing game for androidCar racing game for android
Car racing game for androidravijot singh
 
Tic Tac Toe Java Development
Tic Tac Toe Java DevelopmentTic Tac Toe Java Development
Tic Tac Toe Java Developmentpengqia chen
 
Mini Max Algorithm Proposal Document
Mini Max Algorithm Proposal DocumentMini Max Algorithm Proposal Document
Mini Max Algorithm Proposal DocumentUjjawal Poudel
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d GameIsfand yar Khan
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Snake game implementation in c
Snake game implementation in cSnake game implementation in c
Snake game implementation in cUpendra Sengar
 
Car Game - Final Year Project
Car Game - Final Year ProjectCar Game - Final Year Project
Car Game - Final Year ProjectVivek Naskar
 
report on snake game
report on snake game report on snake game
report on snake game azhar niaz
 
Artificial intelligence in gaming.
Artificial intelligence in gaming.Artificial intelligence in gaming.
Artificial intelligence in gaming.Rishikese MR
 
Number Guessing Game
Number Guessing GameNumber Guessing Game
Number Guessing GameManish Kumar
 
Workflow of Creating Game UX/UI Design
Workflow of Creating Game UX/UI DesignWorkflow of Creating Game UX/UI Design
Workflow of Creating Game UX/UI DesignDevGAMM Conference
 

What's hot (20)

C++ projct
C++ projctC++ projct
C++ projct
 
Tic Tac Toe Project
Tic Tac Toe Project Tic Tac Toe Project
Tic Tac Toe Project
 
Design phase of game development of unity 2d game
Design phase of game development of unity 2d game Design phase of game development of unity 2d game
Design phase of game development of unity 2d game
 
Initial design (Game Architecture)
Initial design (Game Architecture)Initial design (Game Architecture)
Initial design (Game Architecture)
 
Final year project presentation
Final year project presentationFinal year project presentation
Final year project presentation
 
TicTacToe.pptx
TicTacToe.pptxTicTacToe.pptx
TicTacToe.pptx
 
Rock paper-scissors
Rock paper-scissorsRock paper-scissors
Rock paper-scissors
 
Android Application And Unity3D Game Documentation
Android Application And Unity3D Game DocumentationAndroid Application And Unity3D Game Documentation
Android Application And Unity3D Game Documentation
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Car racing game for android
Car racing game for androidCar racing game for android
Car racing game for android
 
Tic Tac Toe Java Development
Tic Tac Toe Java DevelopmentTic Tac Toe Java Development
Tic Tac Toe Java Development
 
Mini Max Algorithm Proposal Document
Mini Max Algorithm Proposal DocumentMini Max Algorithm Proposal Document
Mini Max Algorithm Proposal Document
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Snake game implementation in c
Snake game implementation in cSnake game implementation in c
Snake game implementation in c
 
Car Game - Final Year Project
Car Game - Final Year ProjectCar Game - Final Year Project
Car Game - Final Year Project
 
report on snake game
report on snake game report on snake game
report on snake game
 
Artificial intelligence in gaming.
Artificial intelligence in gaming.Artificial intelligence in gaming.
Artificial intelligence in gaming.
 
Number Guessing Game
Number Guessing GameNumber Guessing Game
Number Guessing Game
 
Workflow of Creating Game UX/UI Design
Workflow of Creating Game UX/UI DesignWorkflow of Creating Game UX/UI Design
Workflow of Creating Game UX/UI Design
 

Similar to Tic tac toe on c++ project

Game programming-help
Game programming-helpGame programming-help
Game programming-helpSteve Nash
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfinfo382133
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdfaquacareser
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdfaquapariwar
 
AI based Tic Tac Toe game using Minimax Algorithm
AI based Tic Tac Toe game using Minimax AlgorithmAI based Tic Tac Toe game using Minimax Algorithm
AI based Tic Tac Toe game using Minimax AlgorithmKiran Shahi
 
0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptxAhishektttPhm
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfezzi97
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfanjandavid
 
This is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxThis is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxabhi353063
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfmanjan6
 
C PROGRAM CODE FOR SNAKE AND LADDER GAME
C PROGRAM CODE FOR SNAKE AND LADDER GAMEC PROGRAM CODE FOR SNAKE AND LADDER GAME
C PROGRAM CODE FOR SNAKE AND LADDER GAMEAbarajitha3
 
[Scorebook final]
[Scorebook final][Scorebook final]
[Scorebook final]Freelancer
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfFashionColZone
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - pythonSunjid Hasan
 

Similar to Tic tac toe on c++ project (20)

Game programming-help
Game programming-helpGame programming-help
Game programming-help
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
AI based Tic Tac Toe game using Minimax Algorithm
AI based Tic Tac Toe game using Minimax AlgorithmAI based Tic Tac Toe game using Minimax Algorithm
AI based Tic Tac Toe game using Minimax Algorithm
 
python.pptx
python.pptxpython.pptx
python.pptx
 
0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
TIC-TAC-TOE IN C
TIC-TAC-TOE IN CTIC-TAC-TOE IN C
TIC-TAC-TOE IN C
 
This is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxThis is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docx
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
C PROGRAM CODE FOR SNAKE AND LADDER GAME
C PROGRAM CODE FOR SNAKE AND LADDER GAMEC PROGRAM CODE FOR SNAKE AND LADDER GAME
C PROGRAM CODE FOR SNAKE AND LADDER GAME
 
[Scorebook final]
[Scorebook final][Scorebook final]
[Scorebook final]
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
 
Aipapercpt
AipapercptAipapercpt
Aipapercpt
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
tic-tac-toe: Game playing
 tic-tac-toe: Game playing tic-tac-toe: Game playing
tic-tac-toe: Game playing
 
Street runner final
Street runner finalStreet runner final
Street runner final
 
201707 CSE110 Lecture 13
201707 CSE110 Lecture 13   201707 CSE110 Lecture 13
201707 CSE110 Lecture 13
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 

Tic tac toe on c++ project

  • 1. Presented By : UTKARSH AGGARWAL 3 July, 2017 (Console Game) C++ Program
  • 2. ACKNOWLEDGEMENT I wish to express my deep gratitude and sincere thanks toI wish to express my deep gratitude and sincere thanks to the principal ,Mrs. Shashi Jain , Vanasthali Public school forthe principal ,Mrs. Shashi Jain , Vanasthali Public school for her encouragement to make this project .her encouragement to make this project . I extend my hearty thanks to Mrs. Sarika Gupta, ourI extend my hearty thanks to Mrs. Sarika Gupta, our Computer teacher , who guided me to the successfulComputer teacher , who guided me to the successful completion of this project .completion of this project .
  • 3. INDEX 1.1. Short introduction To C++Short introduction To C++ 2. Introduction to Tic Tac Toe (Console Game) C++ Program 3.3. System RequirementsSystem Requirements 4.4. CodingCoding 5.5. Output ResultOutput Result 6. Initialization Of Variables &explanatory statements 7. Game Loops 8.8. BibliographyBibliography
  • 4. Short Introduction To C++ C++ is a general-purpose programming language. It has imperative, object oriented and generic programming features, while also providing facilities for low-level memory manipulation. It was designed with a bias toward system programming and embedded, resource-constrained and large systems, with performance, efficiency and flexibility of use as its design highlights. C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource- constrained applications , including desktop applications, servers (e.g. e- commerce, web search or SQL servers), and performance-critical applications (e.g. telephone switches or space probes).C++ is a compiled language, with implementations of it available on many platforms.
  • 5. Introduction to Tic Tac Toe (Console Game) C++ Program This program is a game program, Tic Tac Toe. Most of us have played this game in our leisure time, and we have make a C+ + program on it. Tic-tac-toe (or Noughts and crosses, Xs and Os) is a pencil- and-paper game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three respective marks in a horizontal, vertical, or diagonal row wins the game.
  • 6. Introduction to Tic Tac Toe (Console Game) C++ Program This game uses board to control players In each turn players enter a number and choose a move Simplify programing assumes that player one always moves first and uses X's Player two moves at 2nd position and uses O's A Sample Screen Shot of a Game
  • 7. System Requirements • Operating system: Windows XP, Vista 7 and 8 . • Processor : Pantium III/1.4 GHz processor. • RAM:512 MB • Hard Disk:900 MB Space required
  • 8. Tic Tac Toe (Console Game) C++ Program How the program structured : At the time when program start we initialize variables, and we run the game loop until the game end or players choose to quit The game consists of three steps • Display board • Get players move • Check for game end
  • 9. CODING # include <iostream.h> #include <conio.h> char square[10] = {'o','1','2','3','4','5','6','7','8','9'}; int checkwin(); void board(); int main() { int player = 1,i,choice; char mark; clrscr(); do { board(); player=(player%2)?1:2; cout << "Player " << player << ", enter a number: "; cin >> choice; mark=(player == 1) ? 'X' : 'O'; if (choice == 1 && square[1] == '1')
  • 10. square[1] = mark; else if (choice == 2 && square[2] == '2') square[2] = mark; else if (choice == 3 && square[3] == '3') square[3] = mark; else if (choice == 4 && square[4] == '4') square[4] = mark; else if (choice == 5 && square[5] == '5') square[5] = mark; else if (choice == 6 && square[6] == '6') square[6] = mark; else if (choice == 7 && square[7] == '7') square[7] = mark; else if (choice == 8 && square[8] == '8') square[8] = mark; else if (choice == 9 && square[9] == '9') square[9] = mark; else { cout<<"Invalid move "; player--; getch(); }
  • 11. i=checkwin(); player++; } while(i==-1); board(); if(i==1) cout<<"==>aPlayer "<<--player<<" win "; Else cout<<"==>aGame draw"; getch(); return 0; } /********************************************* FUNCTION TO RETURN GAME STATUS 1 FOR GAME IS OVER WITH RESULT -1 FOR GAME IS IN PROGRESS O GAME IS OVER AND NO RESULT **********************************************/ int checkwin() { if (square[1] == square[2] && square[2] == square[3]) return 1; else if (square[4] == square[5] && square[5] == square[6]) return 1;
  • 12. else if (square[7] == square[8] && square[8] == square[9]) return 1; else if (square[1] == square[4] && square[4] == square[7]) return 1; else if (square[2] == square[5] && square[5] == square[8]) return 1; else if (square[3] == square[6] && square[6] == square[9]) return 1; else if (square[1] == square[5] && square[5] == square[9]) return 1; else if (square[3] == square[5] && square[5] == square[7]) return 1; else if (square[1] != '1' && square[2] != '2' && square[3] != '3' && square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7] != '7' && square[8]!=‘8’&&square[9]!=‘9’) return 0; else return -1; }
  • 13. /******************************************************************* FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK ********************************************************************/ void board() { clrscr(); cout << "nntTic Tac Toenn"; cout << "Player 1 (X) - Player 2 (O)" << endl << endl; cout << endl; cout << " | | " << endl; cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl; cout << " | | " << endl << endl; } /******************************************************************* END OF PROJECT
  • 15.
  • 16. Presented by: Utkarsh aggarwal Initialization Of Variables & explanatory statements This portion of code is for initialization of variables, the variables of squares are initializing with the characters from 1 to 9. The player turn will be initializing to 1 because since the player 1 makes the first turn Game over is initialize to true but that does not really matter for this program because after game loop game check itself for winner.
  • 17. Presented by: utkarsh aggarwal Initialization Of Variables & explanatory statements Program comments are explanatory statements that we can include in the C++ code that we write and helps anyone reading its source code. All programming languages allow for some form of comments. C++ supports single line and multi-line comments. All characters available inside any comment are ignored by C++ compiler. C++ comments start with /* and end with */. For example: // This is a comment /* C++ comments can also span multiple lines */
  • 18. Presented by: Utkarsh aggarwal Game Loops After initialization game began to move forward for main game loop these loops are while and do while loop which are encapsulated in statements that what to do or not to do. Once we enter the game loop The first thing will be done is print the game board which displays the tic tac toe game board in console window Remember we initialize these squares with characters from 1 to 9 for basic console input and output.
  • 19. Presented by: Utkarsh aggarwal Game Loops When we run the program the board looks like this !!Notice that the console window prompts the player for move The player's moves are handled by the next portion of code!!
  • 20. Game Loops ( player's moves ) cPlayerMark determines that first player has X and second has 0 This portion of statements check for player turn if it's not the first player move its promoted the move to next player Then the next line gets the valid move of the player Presented by: Utkarsh aggarwal
  • 21. Game Loops ( player's moves ) If players input an invalid move it's prompted for another move and says try again like this .. A Screen Shot of an Invalid Move Presented by: Utkarsh aggarwal
  • 22. Game Loops ( player's moves ) The cin statement gets the valid move for the player Notice that it's begin with another loop it has pretty much statements to check the conditions. The check for valid move is pretty large branch of square check. Presented by: Utkarsh aggarwal
  • 23. Game Loops ( player's moves ) Each branch of the if statement makes two check, the first input check that the input is valid digit from 1 to 9 and second check is for make sure of the input is digit not an character, second check also make sure that the number which is entered not entered Previously Presented by: Utkarsh aggarwal
  • 24. Game Loops ( player's moves ) After the valid move the series of checks perform to check the games conditions. Note there are the nine ways to end the game, 8 conditions to win the game and 1 condition for draw the game. The first conditions check the ending game condition through the walls of 1st square. Presented by: Utkarsh aggarwal
  • 25. Game Loops ( player's moves ) The second if statement handles the 4 cases from the middle 5th square . Presented by: Utkarsh aggarwal
  • 26. Game Loops ( player's moves ) The third if statement handles the 2 cases from the 9th square In each of these cases we check that the squares not equals to its number character. This check ensures that we have an extra O and the other two checks make sure that the other two squares have the same O in the series like this one Those cases cover the win condition however game will be ended and draw like this. Presented by: Utkarsh aggarwal
  • 27. Game Loops ( player's moves ) Screen Shot “ Game Draw” Presented by: Utkarsh aggarwal
  • 28. Game Loops (Final Check) After that we print the ending board of the game and tells whose win and ask the user to play another game or quit If the user want play again the looping is continue and the board will be reset and the player turn also set back to 1 On the other hand the game will be quit . Presented by: Utkarsh aggarwal
  • 29. Game Loops (Final Check) The final check takes cover of the case that game will be draw and all the squares will be marked. When we determine that the game is over we run through over final condition If the game is over we check for the game that someone is win the game Boolean which we set at the last part, if some has won then it will be last one or last player which is moved. Presented by: Utkarsh aggarwal
  • 30. Tic Tac Toe | (Console Game) C++ Program Hope you Enjoy & Learn Something
  • 31. BIBLIOGRAPHY •Help from internet 2007 Xoax[xoax.net ( C++ Lesson # 9 )] http://www.cppforschool.com http://www.geeksforgeeks.org •Help from book Introduction to C++(sumita arora) •Help from friends