Site hosted by Angelfire.com: Build your free website today!

Here is a game program where you can play Tic-Tac-Toe. The top left hand corner is the cordinate 1 1. The bottom right hand corner is 3 3. If any other number is used then the program will quit by itself..so only use #'s between 1-3. Have fun.



Want to Download the Program?


This is the Code for The Program.


#include <stdio.h> #include <iostream> #include "apmatrix.h" int main( void ) { bool win=false; apmatrix<char> XO(3,3,' '); int x,y; char play; do{ for ( int z=0;z<9&&win==false;z++) { { cout<<XO[0][0]<<" | "<<XO[0][1]<<" | "<<XO[0][2]<<endl; cout<<"--------------"<<endl; cout<<XO[1][0]<<" | "<<XO[1][1]<<" | "<<XO[1][2]<<endl; cout<<"--------------"<<endl; cout<<XO[2][0]<<" | "<<XO[2][1]<<" | "<<XO[2][2]<<endl; cout<<endl<<endl; cout<<"Player #"<<((z%2)+1)<<"'s turn"<<endl<<endl<<endl; do{ cout<<"Please enter where u want to put it (x y)"; cin>>x>>y; cout<<endl<<endl; } while(XO[x-1][y-1]!=' '); if((z%2)==0) XO[x-1][y-1]='X'; else XO[x-1][y-1]='O'; for (int x=0;x<3;x++) { if((XO[x][0]==XO[x][1])&&(XO[x][1]==XO[x][2])&&(XO[x][0]!=' ')) win=true; if((XO[0][x]==XO[1][x])&&(XO[1][x]==XO[2][x])&&(XO[0][x]!=' ')) win=true; } if((XO[0][0]==XO[1][1])&&(XO[1][1]==XO[2][2])&&(XO[1][1]!=' ')) win=true; if((XO[0][2]==XO[1][1])&&(XO[1][1]==XO[2][0])&&(XO[1][1]!=' ')) win=true; } if(win==true) { cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl; cout<<"Player #"<<(((z)%2)+1)<<" Wins"<<endl<<endl<<endl; cout<<XO[0][0]<<" | "<<XO[0][1]<<" | "<<XO[0][2]<<endl; cout<<"--------------"<<endl; cout<<XO[1][0]<<" | "<<XO[1][1]<<" | "<<XO[1][2]<<endl; cout<<"--------------"<<endl; cout<<XO[2][0]<<" | "<<XO[2][1]<<" | "<<XO[2][2]<<endl; break; } } if (!win) cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<"Cats Game"; }while(100); } </b>