Hi everyone..
I am presently writing a game pack with many games using c++.. I have completed the design and the TIC TAC TOE game partly.. I would like you guys to give me suggestions to improve it.. I have attached the EXE file for those who do not have BGI compliant compilers....
The attachement is in my next post below
# include <dos.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
# include <iostream.h>
int i,k,y=180,select,counter,counter1;
void inig()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
}
void start()
{
inig();
int i;
setcolor(GREEN);
for (i=0;i<640;i++)
{ line (i,0,i,15);
line (i,480,i,465); }
settextjustify(CENTER_TEXT, CENTER_TEXT);
settextstyle(GOTHIC_FONT, HORIZ_DIR, 5);
setcolor(14);
settextstyle (10,HORIZ_DIR,5);
outtextxy(300,55,"Gamez Center");
delay(100);
settextstyle (1,HORIZ_DIR,2);
outtextxy(300,25, "I HND PRESENTS");
settextstyle (8,HORIZ_DIR,2);
outtextxy(300,175, "1) Tic Tac Toe");
settextstyle (8,HORIZ_DIR,2);
outtextxy(300,210, "2) Battle Ship");
outtextxy(300,245, "3) Run Man ");
outtextxy(300,280, "4) Snake ");
outtextxy(300,315, "5) Credits ");
outtextxy(300,350, "6) Exit ");
}
void circ(int cho)
{
setcolor(GREEN);
if(cho==1)
circle(200,100,30);
if(cho==2)
circle(300,100,30);
if(cho==3)
circle(400,100,30);
if(cho==4)
circle(200,200,30);
if(cho==5)
circle(300,200,30);
if(cho==6)
circle(400,200,30);
if(cho==7)
circle(200,300,30);
if(cho==8)
circle(300,300,30);
if(cho==9)
circle(400,300,30);
}
void cross(int tr)
{
setcolor(GREEN);
if(tr==1)
{
moveto(200,60);
lineto(160,140);
lineto(240,140);
lineto(200,60);
}
if(tr==2)
{
moveto(300,60);
lineto(260,140);
lineto(340,140);
lineto(300,60);
}
if(tr==3)
{
moveto(400,60);
lineto(360,140);
lineto(440,140);
lineto(400,60);
}
if(tr==4)
{
moveto(200,160);
lineto(160,240);
lineto(240,240);
lineto(200,160);
}
if(tr==5)
{
moveto(300,160);
lineto(260,240);
lineto(340,240);
lineto(300,160);
}
if(tr==6)
{
moveto(400,160);
lineto(360,240);
lineto(440,240);
lineto(400,160);
}
if(tr==7)
{
moveto(200,260);
lineto(160,340);
lineto(240,340);
lineto(200,260);
}
if(tr==8)
{
moveto(300,260);
lineto(260,340);
lineto(340,340);
lineto(300,260);
}
if(tr==9)
{
moveto(400,260);
lineto(360,340);
lineto(440,340);
lineto(400,260);
}
}
void win(int wi)
{
if(wi==1)
{
for(int crs=0;crs<20;crs++)
{
moveto(400-crs,60-crs);
lineto(360-crs,140-crs);
lineto(440-crs,140-crs);
lineto(400-crs,60-crs);
moveto(400-crs,160-crs);
lineto(360-crs,240-crs);
lineto(440-crs,240-crs);
lineto(400-crs,160-crs);
moveto(400-crs,260-crs);
lineto(360-crs,340-crs);
lineto(440-crs,340-crs);
lineto(400-crs,260-crs);
delay(10);
}
}
if(wi==2)
{
for(int crs=0;crs<20;crs++)
{
moveto(200-crs,260-crs);
lineto(160-crs,340-crs);
lineto(240-crs,340-crs);
lineto(200-crs,260-crs);
moveto(300-crs,260-crs);
lineto(260-crs,340-crs);
lineto(340-crs,340-crs);
lineto(300-crs,260-crs);
moveto(400-crs,260-crs);
lineto(360-crs,340-crs);
lineto(440-crs,340-crs);
lineto(400-crs,260-crs);
delay(10);
}
}
if(wi==3)
{
for(int crs=0;crs<20;crs++)
{
moveto(400-crs,60-crs);
lineto(360-crs,140-crs);
lineto(440-crs,140-crs);
lineto(400-crs,60-crs);
moveto(300-crs,160-crs);
lineto(260-crs,240-crs);
lineto(340-crs,240-crs);
lineto(300-crs,160-crs);
moveto(200-crs,260-crs);
lineto(160-crs,340-crs);
lineto(240-crs,340-crs);
lineto(200-crs,260-crs);
delay(10);
}
}
setcolor(RED);
settextstyle (9,HORIZ_DIR,2);
outtextxy(100,410, "The Computer Wins The Game");
delay(3000);
closegraph();
exit(0);
}
void ticlogic()
{
int x,y,x1,y1;
x=200;
y=100;
cross(9);
prog:
setcolor(GREEN);
circle(x,y,10);
x1=x;
y1=y;
select=getche();
setcolor(BLACK);
circle(x1,y1,10);
if(select==0x4d)
{
x=x+100;
if(x>400)
x=200;
}
if(select==0x4b)
{
x=x-100;
if(x<200)
x=400;
}
if(select==0x48)
{
y=y-100;
if(y<100)
y=300;
}
if(select==0x50)
{
y=y+100;
if(y>300)
y=100;
}
if(select==27)
exit(0);
if(select==13)
{
if(x==200 & y==100)
{
circ(1);
delay(1000);
cross(3);
counter=1;
}
if(counter==1)
{
if(x==400 && y==200)
{
circ(6);
delay(1000);
cross(7);
counter1=0;
}
if(counter1==0)
{
if(x==300 && y==100)
{
circ(2);
delay(1000);
cross(8);
win(2);
}
if(x==200 && y==200)
{
circ(4);
delay(1000);
cross(8);
win(2);
}
if(x==300 && y==200)
{
circ(5);
delay(1000);
cross(8);
win(2);
}
if(x==300 && y==300)
{
circ(8);
delay(1000);
cross(5);
win(3);
}
}
if(x==300 && y==100)
{
circ(2);
delay(1000);
cross(6);
win(1);
}
if(x==200 && y==200)
{circ(4);
delay(1000);
cross(6);
win(1);
}
if(x==300 && y==200)
{
circ(5);
delay(1000);
cross(6);
win(1);
}
if(x==200 && y==300)
{
circ(7);
delay(1000);
cross(6);
win(1);
}
if(x==300 && y==300)
{
circ(8);
delay(1000);
cross(6);
win(1);
}
}
}
goto prog;
}
void tictactoe()
{
for(int lines=17;lines<500;lines++)
{
setcolor(BLACK);
line(0,lines,800,lines);
delay(10);
}
closegraph();
inig();
setcolor(GREEN);
rectangle(1,479,639,1);
rectangle(2,478,638,2);
setcolor(BLUE);
line(150,150,450,150);
line(150,250,450,250);
line(250,50,250,350);
line(350,50,350,350);
line(150,151,450,151);
line(150,251,450,251);
line(251,50,251,350);
line(351,50,351,350);
ticlogic();
}
void select1()
{
settextstyle (8,HORIZ_DIR,1);
if(y==355)
{
setcolor(BLUE);
for (i=0;i<640;i++)
{ line (i,0,i,15);}
setcolor(GREEN);
outtextxy(1,1, " The program is exiting from the console mode please wait...... ");
delay(3000);
for(int lines=17;lines<500;lines++)
{
setcolor(BLACK);
line(0,lines,800,lines);
delay(3);
}
closegraph();
exit(0);
}
if(y==320)
{
setcolor(BLUE);
for (i=0;i<640;i++)
{ line (i,0,i,15);}
setcolor(GREEN);
outtextxy(1,1," Vasanth, Shefiu, Aravind, Akhil, Ridwaan and MH ");
delay(3000);
start();
}
if(y==180)
{ setcolor(BLUE);
for (i=0;i<640;i++)
{ line (i,0,i,15);
}
setcolor(GREEN);
outtextxy(1,1," Tic Tac Toe Game is loading please wait...................");
delay(3000);
tictactoe();
start();
}
}
void point()
{
int x;
int x1,y1;
x1=0;
y1=0;
x=400;
prog:
setcolor(BLACK);
for(int ci=0;ci<10;ci++)
{
circle(x1,y1,ci);
}
setcolor(GREEN);
for(ci=0;ci<10;ci++)
{
circle(x,y,ci);
}
x1=x;
y1=y;
k=getche();
if(k==0x50)
y=y+35;
if(y>355)
y=180;
if(k==27)
exit(0);
if(k==0x48)
y=y-35;
if(y<180)
y=355;
if(k==13)
select1();
goto prog;
}
void main()
{
inig();
start();
point();
tictactoe();
}