SlideShare a Scribd company logo
1 of 29
By :- Krishna Kumar Agrawalla
INDEX
1.1. Short introduction To C++Short introduction To C++
2. Introduction to Tic Tac Toe C++ Program
3.3. System RequirementsSystem Requirements
4.4. CodingCoding
5.5. Output ResultOutput Result
6. Initialization Of Variables &explanatory statements
7. Game Loops
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
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
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
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
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.
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
*/
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.
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
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
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.
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
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.
Game Loops
( player's moves )
The second if statement handles the 4 cases from
the middle 5th square .
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.
Game Loops
( player's moves )
Screen Shot “ Game Draw”
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 .
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.
Thank You

More Related Content

What's hot

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
 
Android application - Tic Tac Toe
Android application - Tic Tac ToeAndroid application - Tic Tac Toe
Android application - Tic Tac ToeSarthak Srivastava
 
Tic Tac Toe Java Development
Tic Tac Toe Java DevelopmentTic Tac Toe Java Development
Tic Tac Toe Java Developmentpengqia chen
 
Tic tac toe game with graphics presentation
Tic  tac  toe game with graphics presentationTic  tac  toe game with graphics presentation
Tic tac toe game with graphics presentationPrionto Abdullah
 
MIND GAME ZONE - Abhijeet
MIND GAME ZONE - AbhijeetMIND GAME ZONE - Abhijeet
MIND GAME ZONE - AbhijeetAbhijeet Kalsi
 
Snake game implementation in c
Snake game implementation in cSnake game implementation in c
Snake game implementation in cUpendra Sengar
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmUjjawal Poudel
 
Ludo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationLudo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationZakaria Hossain
 
project on snake game in c language
project on snake game in c languageproject on snake game in c language
project on snake game in c languageAshutosh Kumar
 
Rock, Paper, Scissors
Rock, Paper, ScissorsRock, Paper, Scissors
Rock, Paper, ScissorsJohnathan
 
Rock ,Paper, Scissors IAI .pptx
Rock ,Paper, Scissors IAI .pptxRock ,Paper, Scissors IAI .pptx
Rock ,Paper, Scissors IAI .pptxHome
 
Project proposal presentation(tic tac-toe-game)
Project proposal presentation(tic tac-toe-game)Project proposal presentation(tic tac-toe-game)
Project proposal presentation(tic tac-toe-game)Ikhtiar Khan Sohan
 
report on snake game
report on snake game report on snake game
report on snake game azhar niaz
 
Game Development Step by Step
Game Development Step by StepGame Development Step by Step
Game Development Step by StepBayu Sembada
 
Final Year Game Project Presentation
Final Year Game Project Presentation Final Year Game Project Presentation
Final Year Game Project Presentation Nusrat Jahan Shanta
 

What's hot (20)

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
 
Android application - Tic Tac Toe
Android application - Tic Tac ToeAndroid application - Tic Tac Toe
Android application - Tic Tac Toe
 
Tic Tac Toe Java Development
Tic Tac Toe Java DevelopmentTic Tac Toe Java Development
Tic Tac Toe Java Development
 
Tic Tac Toe ppt
Tic Tac Toe pptTic Tac Toe ppt
Tic Tac Toe ppt
 
Tic tac toe game with graphics presentation
Tic  tac  toe game with graphics presentationTic  tac  toe game with graphics presentation
Tic tac toe game with graphics presentation
 
Tic Tac Toe
Tic Tac ToeTic Tac Toe
Tic Tac Toe
 
MIND GAME ZONE - Abhijeet
MIND GAME ZONE - AbhijeetMIND GAME ZONE - Abhijeet
MIND GAME ZONE - Abhijeet
 
Snake game implementation in c
Snake game implementation in cSnake game implementation in c
Snake game implementation in c
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max Algorithm
 
Ludo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationLudo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentation
 
project on snake game in c language
project on snake game in c languageproject on snake game in c language
project on snake game in c language
 
Synopsis tic tac toe
Synopsis tic tac toeSynopsis tic tac toe
Synopsis tic tac toe
 
Rock, Paper, Scissors
Rock, Paper, ScissorsRock, Paper, Scissors
Rock, Paper, Scissors
 
Rock ,Paper, Scissors IAI .pptx
Rock ,Paper, Scissors IAI .pptxRock ,Paper, Scissors IAI .pptx
Rock ,Paper, Scissors IAI .pptx
 
Project proposal presentation(tic tac-toe-game)
Project proposal presentation(tic tac-toe-game)Project proposal presentation(tic tac-toe-game)
Project proposal presentation(tic tac-toe-game)
 
report on snake game
report on snake game report on snake game
report on snake game
 
Zombi - Shoot for Survive
Zombi - Shoot for SurviveZombi - Shoot for Survive
Zombi - Shoot for Survive
 
Game Development Step by Step
Game Development Step by StepGame Development Step by Step
Game Development Step by Step
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Final Year Game Project Presentation
Final Year Game Project Presentation Final Year Game Project Presentation
Final Year Game Project Presentation
 

Similar to Tic tac toe c++ programing

#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
 
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
 
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
 
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
 
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
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeScott Wlaschin
 
Software Engineering Project
Software Engineering ProjectSoftware Engineering Project
Software Engineering ProjectIvann Grande
 
ma project
ma projectma project
ma projectAisu
 
Multiplayer Networking Game
Multiplayer Networking GameMultiplayer Networking Game
Multiplayer Networking GameTanmay Krishna
 
tic_tac_toe.pptx
tic_tac_toe.pptxtic_tac_toe.pptx
tic_tac_toe.pptxKunaljit2
 
[Scorebook final]
[Scorebook final][Scorebook final]
[Scorebook final]Freelancer
 
The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210Mahmoud Samir Fayed
 
Galactic Wars XNA Game
Galactic Wars XNA GameGalactic Wars XNA Game
Galactic Wars XNA GameSohil Gupta
 
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
 
2 Level Guitar Hero Final Report
2 Level Guitar Hero Final Report2 Level Guitar Hero Final Report
2 Level Guitar Hero Final ReportCem Recai Çırak
 

Similar to Tic tac toe c++ programing (20)

#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
 
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
 
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
 
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
 
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
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-Toe
 
Software Engineering Project
Software Engineering ProjectSoftware Engineering Project
Software Engineering Project
 
ma project
ma projectma project
ma project
 
Multiplayer Networking Game
Multiplayer Networking GameMultiplayer Networking Game
Multiplayer Networking Game
 
tic_tac_toe.pptx
tic_tac_toe.pptxtic_tac_toe.pptx
tic_tac_toe.pptx
 
RandomGuessingGame
RandomGuessingGameRandomGuessingGame
RandomGuessingGame
 
[Scorebook final]
[Scorebook final][Scorebook final]
[Scorebook final]
 
Python in details
Python in detailsPython in details
Python in details
 
The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210
 
Galactic Wars XNA Game
Galactic Wars XNA GameGalactic Wars XNA Game
Galactic Wars XNA Game
 
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
 
2 Level Guitar Hero Final Report
2 Level Guitar Hero Final Report2 Level Guitar Hero Final Report
2 Level Guitar Hero Final Report
 
Ddn
DdnDdn
Ddn
 

Recently uploaded

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 

Recently uploaded (20)

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 

Tic tac toe c++ programing

  • 1. By :- Krishna Kumar Agrawalla
  • 2. INDEX 1.1. Short introduction To C++Short introduction To C++ 2. Introduction to Tic Tac Toe C++ Program 3.3. System RequirementsSystem Requirements 4.4. CodingCoding 5.5. Output ResultOutput Result 6. Initialization Of Variables &explanatory statements 7. Game Loops
  • 3. 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.
  • 4. Introduction to Tic Tac Toe 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.
  • 5. Introduction to Tic Tac Toe 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
  • 6. 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
  • 7. Tic Tac Toe 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. 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(); }
  • 10. 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;
  • 11. 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; }
  • 12. /******************************************************************* 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
  • 14.
  • 15. 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.
  • 16. 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 */
  • 17. 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.
  • 18. 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!!
  • 19. 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
  • 20. 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
  • 21. 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.
  • 22. 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
  • 23. 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.
  • 24. Game Loops ( player's moves ) The second if statement handles the 4 cases from the middle 5th square .
  • 25. 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.
  • 26. Game Loops ( player's moves ) Screen Shot “ Game Draw”
  • 27. 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 .
  • 28. 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.