You are on page 1of 12

Computer Science Project

Academic Session 2017-18

Name of the Students: Kushagra Goel, Pradnya Shinde,


Tanmay Sutar

Roll No.: 11113, 11116, 11121

Class: XI-A

Name of the Teacher: Mrs. Sharmishtha Dhole

Signature of the Teacher: School Stamp


1
TOPIC:

Tic-Tac-Toe Game

2
INDEX

S.No Contents Page no.


1. Certificate 4
2. Acknowledgments 5
3. Problem Statement 6
4. System Requirements 7
5. Technology Used 8
6. Coding 9
7. Implementation 11
8. Conclusion 12
9. Bibliography 12

3
Department of Computer Science

CERTIFICATE

This is to certify that Kushagra Goel, a student of class XI has successfully

completed the investigatory project on the topic “Tic-Tac-Toe Game” during the

year 2017-2018 in partial fulfillment of the Computer Science Practical

Examination under AISSCE conducted by CBSE, New Delhi.

Teacher in-charge Head of the institution

External Examiner School Seal


4
ACKNOWLEDGEMENTS

This project consumed huge amount of work, research and dedication. Still,
implementation would not have been possible if we did not have a support of
few individuals. Therefore, I would like to extend my sincere gratitude.

I am grateful to my Computer Science teacher, who gave me all the time needed
for guiding and clearing my doubts in every step.

I am equally thankful to my parents for their cooperation. It is due to their


support and time to come up with this project.

I am also grateful to my school for harboring me.

Nevertheless, I express my gratitude towards my friends and team members for


their encouragement.

5
Problem Statement

Games are a way to improve one’s hand-eye coordination while providing


endless fun and a way to kill excess time.
Our project is a Tic-Tac-Toe game which can be played by two users
simultaneously.
It should be visually appealing and easy to use.
It should be coded to handle winning and draw scenarios in a proper fashion

6
System Requirements

To play the game, one needs to have a working C++ runtime environment.
To view the source code, one can open it in notepad, code editor or an integrated
development environment.

7
Technology Used

Atom
Atom is a free, opensource, cross-platform code editor which can be used to act
as an IDE when paired with a compiler such as MinGW.
Characteristics of C++:
• Object-Oriented Language
• Platform Independent
• Write Once Run Anywhere(WORA)
• Highly Secure

8
Coding

1. #include <iostream>
2. using namespace std;
3. char box[10] = {
4. 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9'
5. };
6. int checkwin();
7. void board();
8. int main() {
9. int player = 1, i, choice;
10. char mark;
11. do {
12. board();
13. player = (player % 2) ? 1 : 2;
14. cout << "Player " << player << ", enter your choice: ";
15. cin >> choice;
16. mark = (player == 1) ? 'X' : 'O';
17. if (choice == 1 && box[1] == '1') box[1] = mark;
18. else if (choice == 2 && box[2] == '2') box[2] = mark;
19. else if (choice == 3 && box[3] == '3') box[3] = mark;
20. else if (choice == 4 && box[4] == '4') box[4] = mark;
21. else if (choice == 5 && box[5] == '5') box[5] = mark;
22. else if (choice == 6 && box[6] == '6') box[6] = mark;
23. else if (choice == 7 && box[7] == '7') box[7] = mark;
24. else if (choice == 8 && box[8] == '8') box[8] = mark;
25. else if (choice == 9 && box[9] == '9') box[9] = mark;
26. else {
27. cout << "Wrong move ";
28. player--;
29. cin.ignore();
30. cin.get();
31. }
32. i = checkwin();
33. player++;
34. } while (i == -1);
35. board();
36. if (i == 1) cout << "==>\aPlayer " << --player << " WINS ";
37. else cout << "==>\aDRAW";
38. cin.ignore();
39. cin.get();
40. return 0;
41. }
42. int checkwin() {
43. if (box[1] == box[2] && box[2] == box[3]) return 1;
44. else if (box[4] == box[5] && box[5] == box[6]) return 1;
45. else if (box[7] == box[8] && box[8] == box[9]) return 1;
46. else if (box[1] == box[4] && box[4] == box[7]) return 1;
47. else if (box[2] == box[5] && box[5] == box[8]) return 1;
48. else if (box[3] == box[6] && box[6] == box[9]) return 1;
49. else if (box[1] == box[5] && box[5] == box[9]) return 1;
9
50. else if (box[3] == box[5] && box[5] == box[7]) return 1;
51. else if (box[1] != '1' && box[2] != '2' && box[3] != '3' && box[4] != '4' &&
box[5] != '5' && box[6] != '6' && box[7] != '7' && box[8] != '8' && box[9] != '9'
) return 0;
52. else return -1;
53. }
54. void board() {
55. system("cls");
56. cout << "\n\n\tTic Tac Toe\n\n";
57. cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
58. cout << endl;
59. cout << " | | " << endl;
60. cout << " " << box[1] << " | " << box[2] << " | " << box[3] << endl;
61. cout << "_____|_____|_____" << endl;
62. cout << " | | " << endl;
63. cout << " " << box[4] << " | " << box[5] << " | " << box[6] << endl;
64. cout << "_____|_____|_____" << endl;
65. cout << " | | " << endl;
66. cout << " " << box[7] << " | " << box[8] << " | " << box[9] << endl;
67. cout << " | | " << endl << endl;
68. }

10
Implementation

• Run the application


• A console window with a tic-tac-toe grid appears.
• Player 1 is X and Player 2 is O
• A player enters his choice corresponding to the number shown on the grid.
• The winning condition is tested on each step.
• A condition for draw is also included in the application

11
Conclusion

Our game successfully demonstrates the use of functions and audio in C++.
This game is based on a simple design using functions. The grid is updated as soon
as a player makes a move.
As a player makes a move, that block in the grid is blocked so that no one else can
put their mark in it.
After each move, conditions for winning(vertical, horizontal, diagonal) and draw
are checked.
If a player wins, the name of the winning player is declared and the game exits.

Bibliography

1. Computer Science with C++. – Sumita Arora

12

You might also like