Our Feeds
Categories
Home
About
XploitZ
Vulnerability
Hacking
Shellcode
Buffer Overflow
Programming
CSS
C
CPP
Python
PHP
Java
HTML
Android
Video Tutorials
PlayStore*
Thursday 4 July 2013
Ajith KP
Programming Languages Theory
Tic Tac Toe Game in Terminal [ C ]
Ajith KP
July 04, 2013
Hi GuyZ,
I wanna share a C Source code of
TicTacToe
Game. It is coded in C and compiled using
wxDev
C++
.
Please
share
it with your
friends
...
Source Code
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////// ////////// ////////// ////////// ////////// Coded By Ajith Kp ////////// ////////// ////////// ////////// [ http://www.terminalcoders.blogspot.in ] ////////// ////////// ////////// ////////// [ http://www.facebook.com/ajithkp560 ] ////////// ////////// ////////// ////////// @ajithkp560 ////////// ////////// ////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include
char game[3][3]={{"123"},{"456"},{"789"}}; int play[3][3], i, j, p1, p2, chk=0; void main() { banner(); for(i=0;i<3;i++) { for(j=0;j<3;j++) { play[i][j]=3; } } show(); readP1(); getch(); } void banner() { printf("\t\t\tTic Tac Toe Game: By Ajith Kp\nPlayer-1: x\nPlayer-2: 0\n\n\n"); } void show() { printf("\t\t -----------------\n"); for(i=0;i<3;i++) { printf("\t\t|"); for(j=0;j<3;j++) { printf(" %c |",game[i][j]); } printf("\n\t\t -----------------\n"); } } void readP1() { int c1, c2; try1: printf("\n\n\tPlayer-1: "); scanf("%d", &p1); c1=check(p1); if(c1==1) { goto try1; } else { pl1(p1); system("cls"); banner(); show(); gamed(); readP2(); } } void readP2() { int c2; try2: printf("\n\n\tPlayer-2: "); scanf("%d", &p2); c2=check(p2); if(c2==1) { goto try2; } else { pl2(p2); system("cls"); banner(); show(); gamed(); readP1(); } } int check(int c) { if(c==1) { if(game[0][0]=='x'||game[0][0]=='0') { return 1; } else { return 0; } } else if(c==2) { if(game[0][1]=='x'||game[0][1]=='0') { return 1; } else { return 0; } } else if(c==3) { if(game[0][2]=='x'||game[0][2]=='0') { return 1; } else { return 0; } } else if(c==4) { if(game[1][0]=='x'||game[1][0]=='0') { return 1; } else { return 0; } } else if(c==5) { if(game[1][1]=='x'||game[1][1]=='0') { return 1; } else { return 0; } } else if(c==6) { if(game[1][2]=='x'||game[1][2]=='0') { return 1; } else { return 0; } } else if(c==7) { if(game[2][0]=='x'||game[2][0]=='0') { return 1; } else { return 0; } } else if(c==8) { if(game[2][1]=='x'||game[2][1]=='0') { return 1; } else { return 0; } } else if(c==9) { if(game[2][2]=='x'||game[2][2]=='0') { return 1; } else { return 0; } } else { return 1; } } void pl1(int c) { if(c==1) { game[0][0]='x'; play[0][0]=0; } else if(c==2) { game[0][1]='x'; play[0][1]=0; } else if(c==3) { game[0][2]='x'; play[0][2]=0; } else if(c==4) { game[1][0]='x'; play[1][0]=0; } else if(c==5) { game[1][1]='x'; play[1][1]=0; } else if(c==6) { game[1][2]='x'; play[1][2]=0; } else if(c==7) { game[2][0]='x'; play[2][0]=0; } else if(c==8) { game[2][1]='x'; play[2][1]=0; } else if(c==9) { game[2][2]='x'; play[2][2]=0; } else { } } void pl2(int c) { if(c==1) { game[0][0]='0'; play[0][0]=1; } else if(c==2) { game[0][1]='0'; play[0][1]=1; } else if(c==3) { game[0][2]='0'; play[0][2]=1; } else if(c==4) { game[1][0]='0'; play[1][0]=1; } else if(c==5) { game[1][1]='0'; play[1][1]=1; } else if(c==6) { game[1][2]='0'; play[1][2]=1; } else if(c==7) { game[2][0]='0'; play[2][0]=1; } else if(c==8) { game[2][1]='0'; play[2][1]=1; } else if(c==9) { game[2][2]='0'; play[2][2]=1; } else { } } void checkGameOver() { chk=0; for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(play[i][j]==3) { chk=1; } } } if(chk!=1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: No one won!!!"); getch(); exit(0); } } void gamed() { if((play[0][0]==0&&play[0][1]==0&&play[0][2]==0)) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-1 Won!!!"); getch(); exit(0); } else if(play[1][0]==0&&play[1][1]==0&&play[1][2]==0) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-1 Won!!!"); getch(); exit(0); } else if(play[2][0]==0&&play[2][1]==0&&play[2][2]==0) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-1 Won!!!"); getch(); exit(0); } else if(play[0][0]==0&&play[1][1]==0&&play[2][2]==0) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-1 Won!!!"); getch(); exit(0); } else if(play[0][0]==0&&play[1][0]==0&&play[2][0]==0) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-1 Won!!!"); getch(); exit(0); } else if(play[0][1]==0&&play[1][1]==0&&play[2][1]==0) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-1 Won!!!"); getch(); exit(0); } else if(play[0][2]==0&&play[1][2]==0&&play[2][2]==0) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-1 Won!!!"); getch(); exit(0); } else if(play[0][2]==0&&play[1][1]==0&&play[2][0]==0)// { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else if(play[0][0]==1&&play[0][1]==1&&play[0][2]==1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else if(play[1][0]==1&&play[1][1]==1&&play[1][2]==1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else if(play[2][0]==1&&play[2][1]==1&&play[2][2]==1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else if(play[0][0]==1&&play[1][1]==1&&play[2][2]==1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else if(play[0][2]==1&&play[1][1]==1&&play[2][0]==1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else if(play[0][0]==1&&play[1][0]==1&&play[2][0]==1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else if(play[0][1]==1&&play[1][1]==1&&play[2][1]==1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else if(play[0][2]==1&&play[1][2]==1&&play[2][2]==1) { system("cls"); banner(); show(); printf("\n\n\t"); printf("Game Over: Player-2 Won!!!"); getch(); exit(0); } else { system("cls"); checkGameOver(); banner(); show(); } }
Newer Posts
Older Posts
Popular Posts
OpenGL: Line Drawing - DDA Algorithm
Hello GuYz, DDA algorithm is another popular line drawing algorithm. Source Code #include <gl/glut.h> #include <Wind...
Google Dork Generator
( keyword: ) ( site: ) ( intitle: ) ( inurl: )
JQuery Hide & Show Animation
This is just a simple example of JQuery Animation which include Animations Hide , Show and Events such as mouseenter , mouseleave and clic...
OpenGL: Midpoint Circle Drawing Algorithm
Hello GuyZ, Midpoint circle drawing algorithm is important circle drawing algorithm. Its implementation in OpenGL C++ is bellow... ...
P2P Networks
A P2P [ Peer 2 Peer ]computer network is one in which each computer in the network can act as a server or client for the other computers ...
Skin Detection Algorithm - Implementation in Java
Hi GuyZ,,, This is one of the partial solution of my Mini Project. This is an implementation of skin detection algorithm in Jav...
Digital Camera Day or Night - Python Solution
"You need to construct a feature in a Digital Camera, which will auto-detect and suggest to the photographer whether the pi...
Fist GUI Program - FASM
I hope you have read the previous posts about FASM. Else please read it here: http://terminalcoders.blogspot.in/search/label...
Easiest way to convert RGB Color Image to Gray scale Image in Java
Hello GuyZ, I would like to share Java code to convert RGB images to Gray scale images. I have seen many Java codes which converts im...
Beautiful Black-Green Theme for Hackers [GNOME/GTK/KALI LINUX]
If you like this theme download it from here: http://downloads.ziddu.com/download/24041123/HackerTheme.tar.gz.html ...
..:: SUPPORT US ::..
Labels
Programming Language
Programming Languages Theory
Adv. Hacking
Hacking
Vulnerability
C++
CPP
ALOGORITHM
Java
C
Python
Linux
PHP
Shellcode
Buffer Overflow
JavaFX
x64
Android
Digital Image Processing
Graphics
Image Processing
Metasploit
OpenGL
AI
FASM