Saturday, January 10, 2015

Ticacte Game in C graphics

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<string.h>
#include<dos.h>

void*message;
int select(int mult)
{
 union REGS inregs, outregs ;
 int bli=1,use=1,key=34,i;
 settextstyle(2,0,5);
 while(key!=28)
  {
    if(bli>0)
    {
      use=bli;
      setfillstyle(1,0);
      bli=0-bli;
    }
    else if(bli<0)
    {
      use=0-bli;
      setfillstyle(1,8);
      bli=0-bli;
    }
    floodfill(221,111+use*40,15);
    delay(100);
    if(bli<0)
    {
      key=kbhit();
      if(kbhit())
      {
inregs.h.ah = 0 ;
int86(22, &inregs, &outregs) ;
key=outregs.h.ah;
      }
    }
    if((key==72)&&(use>1))
     {
      bli=use-1;
     }
    if((key==80)&&(use<mult))
     {
      bli=use+1;
     }
  }
 if(bli<0)
  bli=0-bli;
 return(bli);
}
void box(char mes[50])
{ putimage(5,5,message,0);
  settextstyle(0,0,1);
  outtextxy(20,30,mes);
}
void draw(char mn[3][3])
{
 char as[3][3][3];
 char num[9][3];
 for(int i=0;i<10;i++)
 { strcpy(num[i]," ");
   num[i][0]=char(49+i);
 }
 for(i=0;i<3;i++)
  for(int j=0;j<3;j++)
   strcpy(as[i][j],"  ");
 for(i=0;i<3;i++)
 { for(j=0;j<3;j++)
    {as[i][j][0]=mn[i][j];}
 }
 clearviewport();
 setcolor(15);
 rectangle(0,0,639,479);
 setfillstyle(1,8);
 settextstyle(0,0,1);
 for(i=0;i<3;i++)
 {
  rectangle(192,117+i*85,267,192+i*85);
  outtextxy(260,185+i*85,num[0+i*3]);
  rectangle(277,117+i*85,352,192+i*85);
  outtextxy(345,185+i*85,num[1+i*3]);
  rectangle(362,117+i*85,437,192+i*85);
  outtextxy(430,185+i*85,num[2+i*3]);
 }
 floodfill(500,430,15);
 setcolor(15);
 settextstyle(1,0,4);
 for(i=0;i<3;i++)
 {
  outtextxy(221,135+i*85,as[i][0]);
  outtextxy(306,135+i*85,as[i][1]);
  outtextxy(391,135+i*85,as[i][2]);
 }
}
void main()
{
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
message=malloc(imagesize(5,5,634,55));
setcolor(15);
rectangle(5,5,634,55);
setfillstyle(1,RED);
floodfill(30,30,15);
outtextxy(10,10,"Message:-");
getimage(5,5,634,55,message);
char col[3][3],input,madu,comps,hums,mess[70]={"computer has selected
the
symbol   . Press any key to continue.."};
int
exii,dang[8],my[8],hard,many,result,guess=7,bre,mad=2,count=0,dont=0,play[
8],p,q,end=0,note,inpu,first,use;
do
{guess=7;mad=2;count=0;dont=0;end=0;result=0;
for(int i=0;i<8;i++)
play[i]=0;
many=0;exii=1;
clearviewport();
setcolor(15);
rectangle(0,0,639,479);
rectangle(20,320,620,460);
rectangle(220,150,390,180);
rectangle(240,155,370,175);
setfillstyle(1,8);
floodfill(100,100,15);
setcolor(15);
settextstyle(4,0,4);
outtextxy(200,50,"TIC TAC TOE");
settextstyle(3,0,1);
outtextxy(40,290,"How to play :-");
outtextxy(35,330,"In this Game, you may select your symbol. You must
try
attain");
outtextxy(26,350,"three of your symbols in a line. if you suceed you
are
the winner.");
outtextxy(35,370," But at the same time you should prevent the computer
from");
outtextxy(35,390,"getting three of its symbols in a line. To play enter
the number");
outtextxy(32,410,"associated with the place where you want to play.
Press
any key");
outtextxy(35,430,"to start");
settextstyle(2,0,6);
outtextxy(258,155,"Start Game");
select(1);
hard=2;
for(int j=0;j<8;j++)
{dang[j]=0;my[j]=0;play[j]=0;}
for(j=0;j<3;j++)
{
 for(int k=0;k<3;k++)
 col[j][k]=' ';
 }
draw(col);
box("Please type in your symbol");
hums=getche();
if((hums!='X')&&(hums!='x')
)
comps='X';
else
comps='0';
mess[33]=comps;
box(mess);
getch();
randomize();
first=(int(rand()%100));
if(hard==2)guess=(int(rand()%100));
else guess=5;
if((first%4)>=2)
{use=guess%3;box("Computer has the first chance to play!");}
else
{use=3;
mad=0;box("You have the first chance to play!");}
delay(2000);
do
{
for(int j=0;j<8;j++)
{dang[j]=0;my[j]=0;}
count++;
mad++;bre=0;
if((end!=1)&&(mad!=1))
{
switch(use)
{
  case 0:{ switch(count)
  {
  case 1: col[2][2]=comps;break;
  case 2: {if(col[1][1]==hums)
   {col[0][0]=comps;play[0]=1;}
  else if((col[2][0]==hums)||(col[2][1]==hums))
   {col[0][2]=comps;play[1]=1;}
  else if((col[0][1]==hums))
   {col[0][2]=comps;play[3]=1;}
   else if((col[1][0]==hums))
   {col[2][0]=comps;play[4]=1;}
  else if((col[0][2]==hums)||(col[1][2]==hums))
   {col[2][0]=comps;play[2]=1;}
  else if (col[0][0]==hums)
  {col[0][2]=comps;play[3]=1;}
   else dont=1;
  }break;
  case 3:{if(play[0]==1)
     dont=1;
  else if((play[1]==1)&&(col[1][2]==hums))
      {col[0][0]=comps;}
  else if((play[2]==1)&&(col[2][1]==hums))
      {col[0][0]=comps;}
  else if((play[3]==1)&&((col[2][1]==hums)||(col[1][2]==hums)))
{col[2][0]=comps;}
  else if((play[4]==1)&&(col[2][1]==hums))
{col[0][2]=comps;}
  else
dont=1;
  }break;
  case 4:dont=1;break;
      }
  }break;
  case 1:{switch(count)
 { case 1:col[0][1]=comps;break;
   case 2:{if(col[2][0]==hums)
     col[0][0]=comps;
   else if(col[1][0]==hums)
     col[0][0]=comps;
   else if(col[0][2]==hums)
     col[1][0]=comps;
   else if(col[1][2]==hums)
     col[0][2]=comps;
   else if(col[0][0]==hums)
     col[1][2]=comps;
   else if(col[2][2]==hums)
     col[0][2]=comps;
   else if(q<=1)
     col[2][2]=comps;
   else
     col[2][0]=comps;
   } break;
   case 3:dont=1;
  }

  }break;
  case 2:{switch(count)
 { case 1:col[1][1]=comps;break;
   case 2:dont=1;
 }
 }break;
  case 3:{dont=1;
 }break;
}
if(dont==1)
{
for(int i=0,l=2;i<3;i++,l--)
{
if(col[i][i]==hums)
 dang[0]++;
else if(col[i][i]==comps)
 my[0]++;
if(col[i][l]==hums)
 dang[1]++;
else if(col[i][l]==comps)
 my[1]++;
}
for(j=0;j<3;j++)
{
 for(int k=0;k<3;k++)
     {
       if(col[j][k]==hums)
dang[j+2]++;
       else if(col[j][k]==comps)
my[j+2]++;
       if(col[k][j]==hums)
dang[j+5]++;
       else if(col[k][j]==comps)
my[j+5]++;
     }
}
for(int j=0;j<8;j++)
{
if((my[j]==3)||(dang[j]==3)||(count==5))
end=1;
if((dang[j]==2)&&(my[j]!=0))
dang[j]=0;
if((my[j]==2)&&(dang[j]==0))
{my[j]=3;bre=1;}
}
if(bre==1)
{for(j=0;j<8;j++)
  dang[j]=0;
}
if((dang[0]==2)||(my[0]==3))
  {
   for(int i=0;i<3;i++)
   { if(col[i][i]==' ')
       col[i][i]=comps;

    }}
else if((dang[1]==2)||(my[1]==3))
      {
       for(int i=0,l=2;i<3;i++,l--)
       { if(col[i][l]==' ')
col[i][l]=comps;
       }}

else
if((dang[2]==2)||(my[2]==3)||(dang[3]==2)||(my[3]==3)||(dang[4]==2)||(my[4
]==3))
{
for(j=0;j<3;j++)
 {if((dang[j+2]==2)||(my[j+2]==3))
  for(int k=0;k<3;k++)
     {if(col[j][k]==' ')
{col[j][k]=comps;bre=1;}}
  }
}
else
if((dang[5]==2)||(my[5]==3)||(dang[6]==2)||(my[6]==3)||(dang[7]==2)||(my[7
]==3))
{
for(int j=0;j<3;j++)
 {if((dang[j+5]==2)||(my[j+5]==3))
  for(int k=0;k<3;k++)
     {if(col[k][j]==' ')
{col[k][j]=comps;bre=1;}}
  }
}
else if(col[1][1]==' ')
col[1][1]=comps;
else if((use==2)&&(col[2][2]==' '))
col[2][2]=comps;
else if((use==2)&&(col[0][2]==' '))
col[0][2]=comps;
else
if((((col[0][0]==hums)&&(col[2][2]==hums))||((col[0][2]==hums)&&(col[2][0]
==hums)))&&(col[1][2]==' '))
col[1][2]=comps;
else
if((col[1][1]!=hums)&&((col[0][0]==hums)||(col[2][2]==hums))&&((col[0][1]=
=hums)||(col[1][2]==hums))&&(col[0][2]==' '))
col[0][2]=comps;
else
if((col[1][1]!=hums)&&((col[0][0]==hums)||(col[2][2]==hums))&&((col[1][0]=
=hums)||(col[2][1]==hums))&&(col[2][0]==' '))
col[2][0]=comps;
else
if((col[1][1]!=hums)&&((col[0][2]==hums)||(col[2][0]==hums))&&((col[2][1]=
=hums)||(col[1][2]==hums))&&(col[2][2]==' '))
col[2][2]=comps;
else
if((col[1][1]!=hums)&&((col[0][2]==hums)||(col[2][0]==hums))&&((col[0][1]=
=hums)||(col[1][0]==hums))&&(col[0][0]==' '))
col[0][0]=comps;
else if((col[1][1]!=comps)&&(col[2][2]==' '))
col[2][2]=comps;
else if((col[1][1]!=comps)&&(col[0][2]==' '))
col[0][2]=comps;
else if(col[0][0]==' ')
col[0][0]=comps;
else if(col[2][2]==' ')
col[2][2]=comps;
else if(col[0][1]==' ')
col[0][1]=comps;
else if(col[1][2]==' ')
col[1][2]=comps;
else if(col[0][2]==' ')
col[0][2]=comps;
else if(col[2][0]==' ')
col[2][0]=comps;
else if(col[1][0]==' ')
col[1][0]=comps;
else if(col[2][1]==' ')
col[2][1]=comps;
}
for(int i=0;i<8;i++)
{if(my[i]==3)
end=1;
}
}
star:
draw(col);
box(" ");
if(end!=1)
{
box("play");
madu=getche();
if((int(madu)<49)||(int(madu)>57))
{box("INVALID ENTRY!");for(long double jk=0;jk<99999999;jk++);goto
star;}
inpu=int(madu)-48;
p=(inpu-1)/3;
switch(inpu%3)
{case 0:q=2;break;
 case 1:q=0;break;
 case 2:q=1;break;
 }
if(col[p][q]!=' ')
{box("Space is already occupied!");for(long double
jk=0;jk<99999999;jk++);goto star;}
col[p][q]=hums;
}
for(j=0;j<8;j++)
{dang[j]=0;my[j]=0;}
for(int i=0,l=2;i<3;i++,l--)
{
if(col[i][i]==hums)
 dang[0]++;
else if(col[i][i]==comps)
 my[0]++;
if(col[i][l]==hums)
 dang[1]++;
else if(col[i][l]==comps)
 my[1]++;
}
for(j=0;j<3;j++)
{
 for(int k=0;k<3;k++)
     {
      if(col[j][k]==hums)
dang[j+2]++;
       else if(col[j][k]==comps)
my[j+2]++;
       if(col[k][j]==hums)
dang[j+5]++;
       else if(col[k][j]==comps)
my[j+5]++;
     }
}
for(j=0;j<8;j++)
{if((my[j]==3)||(dang[j]==3))
 end=1;
}
}while((end!=1));
draw(col);
for(int asd=0;asd<6;asd++)
{many=many+1;
 if((my[0]==3)||(dang[0]==3))
  {exii=0;
  if(many%2==1)
   for(int m=0,n=0;m<3;m++,n++)
   { setfillstyle(1,BLUE);floodfill(193+m*85,118+n*85,15); }
  else
   for(int m=0,n=0;m<3;m++,n++)
   { setfillstyle(1,BLACK);floodfill(193+m*85,118+n*85,15); }}
 else if((my[1]==3)||(dang[1]==3))
  {exii=0;
  if(many%2==1)
   for(int m=0,n=2;m<3;m++,n--)
   { setfillstyle(1,BLUE);floodfill(193+m*85,118+n*85,15); }
  else
   for(int m=0,n=2;m<3;m++,n--)
   { setfillstyle(1,BLACK);floodfill(193+m*85,118+n*85,15); }}
   else for(j=2;j<8;j++)
  {if(((my[j]==3)||(dang[j]==3))&&(j<5))
   {exii=0;
  if(many%2==1)
   for(int m=0,n=j-2;m<3;m++)
    { setfillstyle(1,BLUE);floodfill(193+m*85,118+n*85,15); }
  else
   for(int m=0,n=j-2;m<3;m++)
    { setfillstyle(1,BLACK);floodfill(193+m*85,118+n*85,15); }}
  else if((my[j]==3)||(dang[j]==3))
   {exii=0;
  if(many%2==1)
   for(int m=0,n=j-5;m<3;m++)
    { setfillstyle(1,BLUE);floodfill(193+n*85,118+m*85,15); }
  else
   for(int m=0,n=j-5;m<3;m++)
    { setfillstyle(1,BLACK);floodfill(193+n*85,118+m*85,15); }}
  }
for(long double jk=0;jk<9999999;jk++);
if(exii==1)break;
}
for(int m=0;m<8;m++)
 { if(my[m]==3)
  result=1;
 }
for(m=0;m<8;m++)
 { if(dang[m]==3)
  result=2; }
switch(result)
{case 1:box("You loose! Want to try again(y/n)");break;
 case 2:box("You win! Want to try again(y/n)");break;
 default:box("The game is draw! Want to try again(y/n)");break;
}
input=getche();
}while(input=='Y'||input=='y');
clearviewport();
outtextxy(80,150,"This game is developed by Compiler Watch out! coming
soon");
outtextxy(170,175,"from the same developer `The Gunman'!");
for(long double mas=0;mas<=99999999;mas++);
exit(0);
}



for more you can Visit http://codesofprogramming.blogspot.in/

Sudoku in C Graphics

#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>

#define _LEFT 120
#define _TOP 100
#define _WIDTH   40
#define _HEIGHT   35

#define xBlockSpace  5
#define yBlockSpace  5

#define fixedBlockFillColor RED
#define fixedTextColor     GREEN

#define BlockFillColor1     LIGHTBLUE
#define BlockFillColor2     GREEN
#define playerTextColor   RED

#define SudokuTableColor   GREEN

#define BlockLineColor   BLUE
#define activeBlockLineColor    CYAN

#define UP_ARROW       72
#define DOWN_ARROW   80
#define LEFT_ARROW     75
#define RIGHT_ARROW   77
#define F2   60
#define F3   61

#define AND &&
#define YA ||

#define TRUE 1
#define FALSE 0

int Sudoku[9][3][3] = {0};
int fixedBlocks[9][3][3] = {0};

int activeBlock = 0;
int activeRow = 0;
int activeCol = 0;

int graphicsON ( );
int insertInto (  int block , int row , int col ,  int value );
void DrawBlock( int block , int row , int col, int active );
void keyPressed ( char keyCode );
int isFixedBlock( int block = activeBlock, int row = activeRow, int col = activeCol );
void initializeGame();
void showHint();
void DrawOut();
void DrawAllBox();
int isCompleted();
void showWin();
void signature();
int Menu ();
void drawMenu ( int selected , int defCol , int selCol );
void HowToPlay();
void About();
void SaveGame();
void LoadGame();
void Play();

/*
ÛßßßßßßßßßßßßßßßßßßßßßßßßßßÛ
Û    MAIN FUNCTION START   Û
ßßßßßßßßßßßßßßßßßßßßßßßßßßßß
*/
void main()
{
if ( graphicsON ( ) == FALSE ) return;
int rep;

Again:
cleardevice();
DrawOut ();
rep = Menu();
switch ( rep )
{
case 4:
closegraph();
return;
case 1:
/*
ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
ßÛ Initialize Trick Ûß
 ßßßßßßßßßßßßßßßßßßßß
*/
initializeGame();
Play();
goto Again;
case 2:
HowToPlay();
goto Again;
case 3:
About();
goto Again;
}
}
/*
ÛßßßßßßßßßßßßßßßßßßßßßßßßßßÛ
Û  MAIN FUNCTION COMPLETED Û
ßßßßßßßßßßßßßßßßßßßßßßßßßßßß
*/
int graphicsON ( )
{
char path[128] = { "d:\tc\bgi" };
int i = 0;

while ( TRUE )
{
int g = DETECT , d;
initgraph ( &g , &d , path );
if ( i > 2 ) return FALSE;
i++;

if ( graphresult() != grOk )
{
printf ( "
 BGI file not found: [ EGAVGA.BGI ]" );
printf ( "
 Enter the path of BGI directory:[ c:\tc\bgi ]-> " );
gets ( path );
}
else
{
return TRUE;
}
}
}

int insertInto ( int block , int row , int col ,  int value )
{
if ( isFixedBlock( block , row , col ) ) return FALSE;

if ( ( value > 9 ) || ( value < 0 ) ) return FALSE;
if ( ( block >= 9 ) || ( block < 0 ) ) return FALSE;
if ( ( row   >= 3 ) || ( row   < 0 ) ) return FALSE;
if ( ( col   >= 3 ) || ( col   < 0 ) ) return FALSE;

for ( int i = 0; i < 3; i++ )
{
for ( int j = 0; j < 3; j++ )
{
if ( Sudoku[block][i][j] == value )
  // return FALSE;
return ( block + 1 )* 100 + i * 10 + j;
}
}
int tempBlock = 3 * ( block / 3 );

for ( i = 0; i < 3; i++ )
{
for ( int j = 0; j < 3; j++ )
{
if ( Sudoku[tempBlock + i][row][j] == value )
// return FALSE;
return ( tempBlock + i + 1 )* 100 + row * 10 + j;
}
}

tempBlock = block % 3;

for ( i = 0; i < 3; i++ )
{
for ( int j = 0; j < 3; j++ )
{
if ( Sudoku[tempBlock + i * 3 ][j][col] == value )
// return FALSE;
return ( tempBlock + i * 3 + 1 )* 100 + j * 10 + col;
}
}

Sudoku[block][row][col] = value;

return TRUE;
}

void DrawBlock( int block , int row , int col , int active )
{
int temp;

temp = 3 * ( block % 3 );
int x = temp * ( _WIDTH + xBlockSpace ) + _LEFT ;

temp = 3 * ( block / 3 );
int y = _TOP + temp * ( _HEIGHT + yBlockSpace );

x = x + col * _WIDTH;
y = y + row * _HEIGHT;
char str[3];
settextstyle ( 1 , 0 , 1 );
int midTextWidth = textwidth ( "0" ) / 2;
int midTextHeight = textheight ( "0" ) / 2;

if  ( isFixedBlock( block , row , col ) )
{
setfillstyle ( 1 , fixedBlockFillColor );
setcolor ( fixedTextColor );
}
else if ( Sudoku[block][row][col] != 0 )
{
setfillstyle ( 1 , BlockFillColor2 );
setcolor ( playerTextColor );
}
else if ( Sudoku[block][row][col] == 0 )
{
setfillstyle ( 1 , BlockFillColor1 );
}

bar ( x , y , x + _WIDTH , y + _HEIGHT );
if ( Sudoku[block][row][col] != 0 )
{
itoa ( Sudoku[block][row][col] , str , 10 );
outtextxy ( x + _WIDTH / 2 - midTextWidth,
y + _HEIGHT / 2 - midTextHeight, str );
}

setcolor ( active == TRUE ? activeBlockLineColor : BlockLineColor );
rectangle ( x , y , x + _WIDTH , y + _HEIGHT );
}

void keyPressed ( char keyCode )
{
switch ( keyCode )
{
case UP_ARROW:
if ( activeRow == 0 )
{
activeRow = 2;
switch ( activeBlock )
{
case 0: case 1: case 2:
activeBlock += 6;
break;
case 3: case 4: case 5:
case 6: case 7: case 8:
activeBlock -= 3;
break;
}
}
else
{
activeRow--;
}
break;
case DOWN_ARROW:
if ( activeRow == 2 )
{
activeRow = 0;
switch ( activeBlock )
{
case 6: case 7: case 8:
activeBlock -= 6;
break;
case 3: case 4: case 5:
case 0: case 1: case 2:
activeBlock += 3;
break;
}
}
else
{
activeRow++;
}
break;
case LEFT_ARROW:
if ( activeCol == 0 )
{
activeCol = 2;
switch ( activeBlock )
{
case 0: case 3: case 6:
activeBlock += 2;
break;
case 1: case 2: case 4:
case 5: case 7: case 8:
activeBlock -= 1;
break;
}
}
else
{
activeCol--;
}
break;
case RIGHT_ARROW:
if ( activeCol == 2 )
{
activeCol = 0;
switch ( activeBlock )
{
case 2: case 5: case 8:
activeBlock -= 2;
break;
case 0: case 1: case 3:
case 4: case 7: case 6:
activeBlock += 1;
break;
}
}
else
{
activeCol++;
}
break;
}
// if ( isFixedBlock() ) keyPressed ( keyCode );
DrawBlock( activeBlock , activeRow , activeCol , TRUE );
}

int isFixedBlock( int block , int row , int col )
{
if ( fixedBlocks[block][row][col] == 1 )
return TRUE;
else
return 0;
}

void showHint()
{
for ( int i = 1; i <=20 ; i++ )
{
if ( insertInto ( activeBlock , activeRow , activeCol , random ( 9 ) + 1 ) == TRUE )
{
DrawBlock ( activeBlock , activeRow , activeCol , TRUE );
sound ( 140 );
delay ( 300 );
nosound ();

return;
}
}
sound ( 400 );
delay ( 300 );
nosound ();
}

void initializeGame()
{
int i, j, temp;
randomize( );
for ( i = 0; i < 9; i++ )
{
for ( j = 0; j < 3; j++ )
{
for ( int k = 0; k < 3; k++ )
{
Sudoku[i][j][k] = 0;
fixedBlocks[i][j][k] = 0;
}
}
}

for ( i = 0; i < 9; i++ )
{
temp = random( 3 ) + 1;
for ( j = 0; j < temp; j++ )
{
int row = random ( 3 );
int col = random ( 3 );
if ( insertInto ( i , row , col ,random ( 9 ) + 1 ) != TRUE )
{
j--;
continue;
}
else
{
fixedBlocks[i][row][col] = 1;
}
}
}
}

void DrawOut()
{
setbkcolor ( 8 );
settextstyle ( 4 , 0 , 6 );

char pattern[8] = { 254 ,2 ,250 ,138 ,186 ,162 ,190 ,128};

setfillpattern ( pattern , 6 );
setfillstyle ( 12 , 6 );
bar ( 0 , 0 , 639 ,80 );
setcolor ( 6 );
rectangle ( 0 , 0 , 639 , 80 );

setcolor ( 7 );
outtextxy ( 31 , 1 , " SUDOKU " );
setcolor ( RED );
outtextxy ( 30 , 2 , " SUDOKU " );

settextstyle ( 4 , 1 , 7 );
setcolor ( 7 );
outtextxy ( 11 , 101 , " SUDOKU " );
setcolor ( RED );
outtextxy ( 10 , 100 , " SUDOKU " );

settextstyle ( 4 , 1 , 7 );
setcolor ( 7 );
outtextxy ( 531 , 101 , " SUDOKU " );
setcolor ( RED );
outtextxy ( 530 , 102 , " SUDOKU " );

settextstyle ( 5 , 0 , 4 );
setcolor ( 7 );
outtextxy ( 301 , 9 , " By:  Rakesh Juyal " );
setcolor ( GREEN );
outtextxy ( 300 , 10 , " By:  Rakesh Juyal " );
}

int isCompleted()
{
int i , j , k;
for ( i = 0; i < 9; i++ )
{
for ( j = 0; j < 3; j++ )
{
for ( k = 0; k < 3; k++ )
{
if ( Sudoku[i][j][k] == 0 )
return FALSE;
}
}
}
return TRUE;
}

void showWin()
{
settextstyle ( 4 , 0  , 9 );

for ( int i = 0; i <= 15; i += 1 )
{
setcolor ( i );
outtextxy ( 50 + i, 150 + i , " YOU WIN " );
}
getch();
return;
}

int Menu ()
{
int ch;
int selected = 1;
int TotalOptions = 4;
setbkcolor ( 0 );
// setbkcolor ( BLUE );
signature();
drawMenu ( selected , RED , GREEN );
do
{
ch = getch();
if ( ch == DOWN_ARROW )
{
selected = selected >= TotalOptions ? 1 : selected + 1;
}
else if ( ch == UP_ARROW )
{
selected = selected < 2 ? TotalOptions : selected - 1;
}
drawMenu ( selected , RED , GREEN );
}while ( ch != '
' );

return selected;
}

void signature()
{
setcolor ( BROWN );
settextstyle ( 0 , 0 , 0 );
outtextxy ( 350 , 400 , " Programmer: " );
outtextxy ( 350 , 410 , "     mailto: " );
outtextxy ( 350 , 420 , "     mailto: " );

setcolor ( YELLOW );
outtextxy ( 450 , 400 , " Rakesh Juyal " );
outtextxy ( 450 , 410 , " juyalrules@Yahoo.com " );
outtextxy ( 450 , 420 , " rakesh@mindless.com " );

setcolor ( 12 );
outtextxy ( 450 , 410 , "           @Yahoo.com " );
outtextxy ( 450 , 420 , "       @mindless.com " );
}

void drawMenu ( int selected , int defCol , int selCol )
{
int x = 230;
int y = 120;
int width = 150;
int height = 30;
int i;
int TotalOptions = 4;
char menu_option[5][14]= {
"    PLAY     ",
" HOW TO PLAY ",
"  ABOUT GAME " ,
"     EXIT    "
};
setcolor ( WHITE );
setfillstyle ( 1 , defCol );
setlinestyle ( 0 , 0 , 0  );
settextstyle ( 0 , 0 , 0 );

for ( i = 1; i <= TotalOptions; i++ )
{
bar ( x , y , x + width , y + height );
rectangle ( x , y , x + width , y + height );
outtextxy ( x + 20 , y + 10 , menu_option[i - 1] );
y = y + height + 30;
}

setfillstyle ( 1 , selCol );
setcolor ( 14 );
y = y - TotalOptions * ( height + 30 );
y = y + ( selected - 1 ) * ( height + 30 );

bar ( x , y , x + width , y + height );
rectangle ( x , y , x + width , y + height );
outtextxy ( x + 20 , y + 10 , menu_option[selected - 1] );
}

void HowToPlay()
{
cleardevice();
DrawOut();
setbkcolor ( 0 );
settextstyle ( 0 , 0 , 0 );
setcolor ( LIGHTGREEN );
int y = 140 , yInc = 20;

outtextxy ( 150 , y , " 1. Use arrow keys to move UP, DOWN, LEFT, RIGHT." );
y = y + yInc;
outtextxy ( 150 , y , " 2. Press the number you want to enter [ 1 - 9 ]." );
y = y + yInc;
outtextxy ( 150 , y , " 3. Press '?' to get the HINT." );
y = y + yInc;
outtextxy ( 150 , y , " 4. Press 'F2' to save the GAME." );
y = y + yInc;
outtextxy ( 150 , y , " 5. Press 'F3' to load the GAME." );
y = y + yInc;

y = y + yInc;
outtextxy ( 150 , y , " 1. Fill all the blocks." );
y = y + yInc;
outtextxy ( 150 , y , " 2. Any number must not be repeated neither " );
y = y + yInc;
outtextxy ( 150 , y , "    horizontally, neither vertically, nor in Box." );

setcolor ( WHITE );

y = 120;
outtextxy ( 80 , y , " Instructions:" );
y = y + 6 * yInc;
outtextxy ( 80 , y , " Objective:" );


signature();
getch();
}

void About()
{
cleardevice();
DrawOut();
setbkcolor ( 0 );
settextstyle ( 0 , 0 , 0 );
setcolor ( LIGHTGREEN );
outtextxy ( 150 , 120 , " is a Japaneese Game. ( Actually i'm not sure )" );
outtextxy ( 150 , 140 , " Use any search engine to find about it." );

outtextxy ( 150 , 180 , " Rakesh Juyal " );
outtextxy ( 150 , 200 , " back with another Game after SNAKE WAR. " );
outtextxy ( 150 , 220 , " GOOD NEWS: SNAKE WAR will not have another version. " );

outtextxy ( 150 , 260 , " If you have any suggestion, or encountered a bug" );
outtextxy ( 150 , 280 , " feel free to mail me. " );

setcolor ( WHITE );
outtextxy ( 80 , 100 , " SUDOKU:" );
outtextxy ( 80 , 160 , " Programmer:" );
outtextxy ( 80 , 240 , " Bugs and Suggestions:" );

signature();
getch();
}

void SaveGame()
{
FILE *fp;
fp = fopen ( "SUDOKU.001" , "w");

settextstyle ( 2 , 0 , 6 );
setcolor ( RED );
setfillstyle ( 1 , 0 );
if ( fp == NULL )
{
bar ( 200 , 460 , 500 , 480 );
outtextxy ( 200 , 460 , " UNABLE TO SAVE " );
delay ( 300 );
bar ( 200 , 460 , 500 , 480 );
return;
}

bar ( 200 , 460 , 500 , 480 );
outtextxy ( 200 , 460 , " Saving... " );
delay ( 300 );

int i , j , k;
for ( i = 0; i < 9; i++ )
{
for ( j = 0; j < 3; j++ )
{
for ( k = 0; k < 3; k++ )
{
fputc ( Sudoku[i][j][k] , fp );
}
}
}

for ( i = 0; i < 9; i++ )
{
for ( j = 0; j < 3; j++ )
{
for ( k = 0; k < 3; k++ )
{
fputc ( fixedBlocks[i][j][k] , fp );
}
}
}
bar ( 200 , 460 , 500 , 480 );
outtextxy ( 200 , 460 , " Game Saved... " );
delay ( 300 );
bar ( 200 , 460 , 500 , 480 );

fclose ( fp );
}

void LoadGame()
{
FILE *fp;
fp = fopen ( "SUDOKU.001" , "r");

settextstyle ( 2 , 0 , 6 );
setcolor ( RED );
setfillstyle ( 1 , 0 );
if ( fp == NULL )
{
bar ( 200 , 460 , 500 , 480 );
outtextxy ( 200 , 460 , " UNABLE TO OPEN " );
delay ( 300 );
bar ( 200 , 460 , 500 , 480 );
return;
}

bar ( 200 , 460 , 500 , 480 );
outtextxy ( 200 , 460 , " Reading... " );
delay ( 300 );

int i , j , k;
int ch;

for ( i = 0; i < 9; i++ )
{
for ( j = 0; j < 3; j++ )
{
for ( int k = 0; k < 3; k++ )
{
Sudoku[i][j][k] = 0;
fixedBlocks[i][j][k] = 0;
}
}
}

for ( i = 0; i < 9; i++ )
{
for ( j = 0; j < 3; j++ )
{
for ( k = 0; k < 3; k++ )
{
ch = fgetc ( fp );
Sudoku[i][j][k] = ch;
}
}
}

for ( i = 0; i < 9; i++ )
{
for ( j = 0; j < 3; j++ )
{
for ( k = 0; k < 3; k++ )
{
ch = fgetc ( fp );
fixedBlocks[i][j][k] = ch;
}
}
}
fclose ( fp );

bar ( 200 , 460 , 500 , 480 );
outtextxy ( 200 , 460 , " Game Loaded... " );
delay ( 300 );
bar ( 200 , 460 , 500 , 480 );

Play();
}

void Play()
{
char ch;

cleardevice();
DrawOut();
setbkcolor ( BLACK );
DrawAllBox();
DrawBlock( activeBlock , activeRow , activeCol , TRUE );

while ( TRUE )
{
ch = getch();
if ( ( ch >= '0' ) && ( ch <= '9' ) )
{
int temp = insertInto ( activeBlock , activeRow , activeCol ,
ch - '0' );
if ( temp == TRUE )
{
DrawBlock ( activeBlock , activeRow , activeCol , TRUE );
if ( isCompleted() )
{
showWin();
//goto Again;
return;
}
}
else if ( temp == FALSE )
{
sound ( 700 );
delay ( 400 );
nosound ();
}
else
{
sound ( 500 );
DrawBlock ( activeBlock , activeRow , activeCol , FALSE );
DrawBlock ( temp / 100 - 1, ( temp / 10 ) % 10,
temp % 10 , TRUE );
delay ( 300 );
DrawBlock ( temp / 100 - 1,  ( temp / 10 ) % 10,
temp % 10 , FALSE );
DrawBlock ( activeBlock , activeRow , activeCol , TRUE );

nosound ();
}
}
else if ( ch == '?' )
{
showHint();
}
else if ( ch == 0 )
{
ch = getch();
if ( ch == F2 )
{
SaveGame();
continue;
}
else if ( ch == F3 )
{
LoadGame();
return;
}
DrawBlock( activeBlock , activeRow , activeCol , FALSE );
keyPressed ( ch );
}
else if ( ch == 0x1b )
break;
}
}

void DrawAllBox()
{
int x , y;
int i , j;
int temp;

setcolor ( BlockLineColor );
settextstyle ( 1 , 0 , 1 );

setlinestyle ( 0 , 0 , 3 );
y = _TOP - yBlockSpace ;
x = _LEFT - xBlockSpace;
setcolor ( SudokuTableColor );

for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++ )
{
rectangle ( x , y , x + 3 * _WIDTH + 2 * xBlockSpace  ,
y + 3 * _HEIGHT + 2 * yBlockSpace );

x = x + 3 * ( _WIDTH + xBlockSpace );
delay ( 100 );
}
y = y + 3 * ( _HEIGHT + yBlockSpace ) ;
x = _LEFT - xBlockSpace ;
}

x = _LEFT;
y = _TOP;

for ( i = 0; i < 9; i++ )
{
for ( j = 0; j < 3; j++ )
{
for ( int k = 0; k < 3; k++ )
{
DrawBlock ( i , j , k , FALSE );
setcolor ( BlockLineColor );
rectangle ( x , y , x + _WIDTH , y + _HEIGHT );
x = x + _WIDTH;
delay ( 10 );
}
y = y + _HEIGHT;
temp = 3 * ( i % 3 );
x = _LEFT + temp * ( _WIDTH + xBlockSpace );
}

temp = 3 * ( ( i + 1 ) % 3 );
x = temp * ( _WIDTH + xBlockSpace ) + _LEFT ;
temp = 3 * ( ( i + 1 ) / 3 );
y = _TOP + temp * ( _HEIGHT + yBlockSpace );
}
}



for more codes you can Visit http://codesofprogramming.blogspot.in/

Snake War in C Graphics

/*
 Snake WAR - I
*/

#include <graphics.h>
#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>

//#pragma warn -wrch
#define MAX      50

#define UP_ARROW      72
#define DOWN_ARROW    80
#define LEFT_ARROW    75
#define RIGHT_ARROW   77

#define WinMinX       40
#define WinMaxX       600
#define WinMinY       40
#define WinMaxY       440

enum Direction {Forward,Backward,Upward,Downward};

struct Coord
{
int x , y;
};

class Snake;
class Point
{
int x , y , color ;
public:
Point ( )
{
set ();
}

void set();
void draw( );
int getx() {  return x; }
int gety() { return y;  }
friend int point_vanished ( Point &p , Snake &s );
};

class Snake
{
Coord *_Snake;
int _CurSize, _color,_MaxSize, _Points;
char _player;
Direction _Direction;
public:
Snake ( int size = 20, int color = RED , char player = 'M' )
{
_Snake = new Coord [ size ];
_CurSize = 3;
if ( player == 'C' )
{
_Snake [0].x = WinMaxX - 10;
_Direction = Backward;
}
else
{
_Snake [0].x = WinMinX + 10;
_Direction = Forward;
}
//_Snake [0].x = WinMinX + 10;
_Snake [0].y = WinMinY + 10;
_color = color;
_MaxSize = size;
_player = player;
_Points = 0;
}
void set( int size = 20, int color = RED , char player = 'M' )
{
delete _Snake;
_Snake = new Coord [ size ];
_CurSize = 3;
if ( player == 'C' )
{
_Direction = Backward;
_Snake [0].x = WinMaxX - 10;
}
else
{
_Snake [0].x = WinMinX + 10;
_Direction = Forward;
}
_Snake [0].x = WinMinX + 10;
//_Snake [0].y = WinMinY + 10;
_color = color;
_MaxSize = size;
_player = player;
_Points = 0;
}

void change_direction ( Direction d);
void increment ();
void inc_disp ();
void shift_all ();
void display ( int color = BLACK );
void com_play ( Point p1 );
friend int point_vanished ( Point &p , Snake &s );
};
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Sound ( int s );
void Message_Display ( char msg[30] , char color );
void show_Header();
void signature();
int menu ();
void drawMenu ( int selected , int defCol , int selCol );
void show_About();
void show_HowTOPlay();
void show_New();
void Play();
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

int main()
{

int g = DETECT , d;
initgraph ( &g , &d , "d:\tc\bgi" );

int selected_option;

Start:
selected_option = menu();

switch ( selected_option )
{
case 1:
Play();
goto Start;
case 2:
show_HowTOPlay();
goto Start;
case 3:
show_New();
goto Start;
case 4:
show_About();
goto Start;
case 5:
return 1;
}
return 1;
}

/****************************************

****************************************/
/****************************************

****************************************/
void Snake :: increment ( )
{
 //int i;

shift_all();
if ( _Direction == Forward )
{
if ( _Snake[0].x >= WinMaxX )
{
_Snake[0].x = WinMinX ;
}
else
_Snake[0].x = _Snake[0].x + 10;
}
else if ( _Direction == Backward  )
{
if ( _Snake[0].x <= WinMinX )
{
_Snake[0].x = WinMaxX ;
}
else
_Snake[0].x = _Snake[0].x - 10;
}
else if ( _Direction == Upward  )
{
if ( _Snake[0].y <= WinMinY )
{
_Snake[0].y = WinMaxY ;
}
else
_Snake[0].y = _Snake[0].y - 10;
}
else if ( _Direction == Downward  )
{
if ( _Snake[0].y >= WinMaxY )
{
_Snake[0].y = WinMinY ;
}
else
_Snake[0].y = _Snake[0].y + 10;
}
}
/****************************************

****************************************/
void Snake :: shift_all ()
{
int i;
for ( i = _CurSize -1 ; i > 0; i-- )
{
_Snake[i].x = _Snake[i-1].x;
_Snake[i].y = _Snake[i-1].y;
}
}

void Snake :: inc_disp ()
{
display ( BLACK );
increment();
display ( _color );
}
/****************************************

****************************************/
void Snake :: display ( int color)
{
setfillstyle ( 1, color );
if ( color == 0 )
{
setcolor ( 0 );
bar ( _Snake[_CurSize - 1].x - 5 , _Snake[_CurSize - 1].y - 5 , _Snake[_CurSize - 1].x + 5 , _Snake[_CurSize - 1].y + 5 );
rectangle ( _Snake[_CurSize - 1].x - 5 , _Snake[_CurSize - 1].y - 5 ,_Snake[_CurSize - 1].x + 5 , _Snake[_CurSize - 1].y + 5 );
 //return ;
}
else
{
setcolor ( WHITE );
for ( int i = 0; i< _CurSize; i++ )
{
bar ( _Snake[i].x - 5 , _Snake[i].y - 5 , _Snake[i].x + 5 , _Snake[i].y + 5 );
rectangle ( _Snake[i].x - 5 , _Snake[i].y - 5 , _Snake[i].x + 5 , _Snake[i].y + 5 );
}

/*
//int i = 0;
bar ( _Snake[i].x - 5 , _Snake[i].y - 5 , _Snake[i].x + 5 , _Snake[i].y+ 5 );
rectangle ( _Snake[i].x - 5 , _Snake[i].y - 5 , _Snake[i].x + 5 ,_Snake[i].y );
*/
setfillstyle ( 1 , 0 );
fillellipse ( _Snake[0].x  , _Snake[0].y  , 2  , 2);

char msg[50];
setcolor ( WHITE );

if ( _player == 'C' )
{
bar ( 250 , 12 , 630 , WinMinY - 10 );
sprintf ( msg , "Com Snake at :- ( %d , %d ) Score:- %d", _Snake[0].x, _Snake[0].y , _Points );
outtextxy ( 250 , 12 , msg );
}
else
{
bar ( 250 , 1 , 630 , WinMinY - 10 );
sprintf ( msg , "Ur Snake at :-  ( %d , %d ) Score:- %d", _Snake[0].x, _Snake[0].y , _Points );
outtextxy ( 250 , 1 , msg );
}
}
}
/****************************************

****************************************/
void Snake :: change_direction ( Direction d)
{
if ( ( _Direction == Forward ) && ( d == Backward ) )
{
Sound ( -1 );
}
else if ( ( _Direction == Backward ) && ( d == Forward ) )
{
Sound ( -1 );
}
else if ( ( _Direction == Upward ) && ( d == Downward ) )
{
Sound ( -1 );
}
else if ( ( _Direction == Downward ) && ( d == Upward ) )
{
Sound ( -1 );
}
else
{
_Direction = d;
Sound ( 1 );
}
}

/******************
/******************/

void Point :: draw ( )
{
char msg[30];
setfillstyle ( 1 , color );
setcolor ( YELLOW );
bar ( x - 4 , y - 4 , x + 4 , y + 4 );
rectangle ( x - 4 , y - 4 , x + 4 , y + 4 );


setfillstyle ( 1 , 0 );
fillellipse ( x  , y  , 2 , 2 );

bar ( 1 , 1 , 300 , WinMinY - 10 );
sprintf ( msg , "Point at :- ( %d , %d )", x , y );
outtextxy ( 40 , 1 , msg );
}

void Point :: set ( )
{
color = random ( 15 ) + 1;
x = random ( ( ( WinMaxX - WinMinX  ) / 10 )  )   ;
y = random ( ( ( WinMaxY - WinMinY  ) / 10 )  )   ;
x = ( x * 10 ) + WinMinX;
y = ( y * 10 ) + WinMinY;
draw ( );
}

int point_vanished ( Point &p , Snake &s )
{
if ( ( s._Snake[0].x == p.x ) && ( s._Snake[0].y == p.y ) )
{
s._CurSize++;
if ( s._CurSize == s._MaxSize )
{
return 2;
}
s.increment ();
s.display ( RED );
Sound ( 2 );
delay ( 100 );

s._Points = s._Points + 20 ;
p.set();
return 1;
}
else
{
return -1;
}
}

void Sound ( int s )
{
if ( s == -1 )
{
sound ( 150 );
delay ( 30 );

sound ( 250 );
delay ( 30 );
nosound ();
}
else if ( s == 1 )
{
sound ( 450 );
delay ( 20 );
nosound ();
}
else if ( s == 2 )
{
sound ( 650 );
delay ( 20 );
nosound ();
}

}

void Snake :: com_play ( Point p1 )
{
if ( p1.getx() < _Snake[0].x )
{
if ( _Direction == Forward )
_Direction = p1.gety() < _Snake[0].y ? Upward : Downward;
else
_Direction = Backward;
}
else if ( p1.getx() > _Snake[0].x )
{
if ( _Direction == Backward )
_Direction = p1.gety() < _Snake[0].y ? Upward : Downward;
else
_Direction = Forward;
}
else
{
if ( p1.gety() < _Snake[0].y )
{
_Direction = Upward;
}
else if ( p1.gety() > _Snake[0].y )
{
_Direction = Downward;
}
}
}

void Message_Display ( char msg[30] , char color )
{
settextstyle ( 1 , 0 , 5 );
setcolor ( 8 );
outtextxy ( 195 , 205 , msg);

settextstyle ( 1 , 0 , 5 );
setcolor ( color );
outtextxy ( 200 , 200 , msg);
delay ( 1000 );
}

int menu ()
{
int ch;
int selected = 1;
int TotalOptions = 5;

cleardevice();
setbkcolor ( BLUE );
show_Header();
signature();

drawMenu ( selected , RED , GREEN );
do
{
ch = getch();
if ( ch == DOWN_ARROW )
{
selected = selected >= TotalOptions ? 1 : selected + 1;
drawMenu ( selected , RED , GREEN );
}
else if ( ch == UP_ARROW )
{
selected = selected < 2 ? TotalOptions : selected - 1;
drawMenu ( selected , RED , GREEN );
}

}while ( ch != '
' );

return selected;
}

void drawMenu ( int selected , int defCol , int selCol )
{
int x = 250;
int y = 100;
int width = 150;
int height = 30;
int i;
int TotalOptions = 5;
char menu_option[5][14]= {
"    PLAY     ",
" HOW TO PLAY ",
" WHAT'S NEW  ",
"   ABOUT ME  ",
"     EXIT    "
};
setcolor ( WHITE );

for ( i = 1; i <= TotalOptions; i++ )
{
if ( i == selected )
setfillstyle ( 1 , selCol );
else
setfillstyle ( 1 , defCol );
bar ( x , y , x + width , y + height );
rectangle ( x , y , x + width , y + height );
outtextxy ( x + 20 , y + 10 , menu_option[i - 1] );
y = y + height + 30;
}
}

void show_About()
{
cleardevice();
setbkcolor ( BLACK );
show_Header();
setcolor ( WHITE );
settextstyle ( 0 , 0 , 0 );

outtextxy ( 276 , 100 , "Programmer:" );
outtextxy ( 304 , 150 , "Date:" );
outtextxy ( 302 , 200 , "Email:" );
outtextxy ( 268 , 265 , "Dedicated To:" );
outtextxy ( 280 , 315 , "Thanks To:" );

setcolor ( LIGHTGREEN );

signature();

getch();
}

void show_HowTOPlay()
{
cleardevice();
setbkcolor ( BLACK );
show_Header();
settextstyle ( 0 , 0 , 0 );
setcolor ( WHITE );
outtextxy ( 20 , 100 , "Objective:" );
outtextxy ( 20 , 150 , "Playing:" );
outtextxy ( 20 , 220 , "Tip:" );

setcolor ( LIGHTGREEN );
outtextxy ( 120 , 120 , "To collect 50 boxes before the computer Snake." );
outtextxy ( 120 , 170 , "1. Use arrow keys to control your Snake." );
outtextxy ( 120 , 180 , "2. To collect the box just come near to the BOX." );
outtextxy ( 120 , 190 , "3. Press <ESC> to QUIT any time." );
outtextxy ( 120 , 240 , "1. Use shortcuts to collect the BOX. [ Computer Snake never " );
outtextxy ( 120 , 250 , "   uses shortcut]" );
outtextxy ( 120 , 260 , "2. Computer Snake can't Hurt you, so enjoy moving around." );

signature();

getch();
}

void signature()
{
setcolor ( BROWN );
settextstyle ( 0 , 0 , 0 );
outtextxy ( 350 , 400 , " Programmer: " );
outtextxy ( 350 , 410 , "     mailto: " );
outtextxy ( 350 , 420 , "     mailto: " );

setcolor ( YELLOW );
}

void show_Header()
{
setcolor ( RED );
settextstyle ( 1 , 0 , 4 );
outtextxy ( 193 , 27 , " SNAKE WAR - I " );
setcolor ( YELLOW );
outtextxy ( 195 , 25 , " SNAKE WAR - I " );
}

void show_New()
{
cleardevice();
setbkcolor ( BLACK );
show_Header();
settextstyle ( 0 , 0 , 0 );
setcolor ( WHITE );

outtextxy ( 20 , 100 , "What's new" );
outtextxy ( 20 , 150 , "What's next" );
outtextxy ( 20 , 260 , "When to expect next version" );
outtextxy ( 20 , 320 , "Comments, Bugs and Suggestions" );

setcolor ( LIGHTGREEN );
outtextxy ( 70 , 120 , "Nothing, cos it's the first version. :-)" );

outtextxy ( 70 , 170 , "In next version of this Game:- " );
outtextxy ( 90 , 180 , " > One or more player will be able to play."
outtextxy ( 90 , 190 , " > You'll be able to select Zero or more computer players." );
outtextxy ( 90 , 200 , " > You'll be able to PAUSE the Game any time." );
outtextxy ( 90 , 210 , " > You'll be able to select the color of each snake." );
outtextxy ( 90 , 220 , " > Keys will be customizable." );
outtextxy ( 90 , 230 , " > Snakes will be able to Hurt each other." );

outtextxy ( 70 , 280 , "Don't worry, i'll mail the code of next version too. [ Very Soon ]" );

outtextxy ( 70 , 340 , "For any suggestion or comment or Bug report feel free to mail me." );
outtextxy ( 70 , 350 , "There may be Bugs too in this game, so please let me know them." );

signature();
getch();
}

void Play()
{
Snake s1 ( MAX , GREEN , 'M' );
Snake s2 ( MAX , MAGENTA , 'C' );

char ch , KeyPressed = 0;

cleardevice();
randomize ();

rectangle ( WinMinX - 7, WinMinY - 7, WinMaxX + 7 , WinMaxY + 7 );
Point p1;

setbkcolor ( BLUE );
s1.inc_disp();
s2.inc_disp();

setcolor ( YELLOW );
outtextxy ( 10 , 450 , "> Collect 50 Boxes to WIN.   > Use shortcuts to WIN.");
setcolor ( CYAN );
outtextxy ( 10 , 460 , "> Use <ESC> to QUIT anytime. > LEFT , RIGHT , UP , DOWN Arrow Keys to Play. ");
getch();

KeyPressed = 1;
ch = 'R';
while ( 1 )
{
while ( !kbhit() )
{
s1.inc_disp();
if ( point_vanished ( p1 , s1 ) == 2 )
{
Message_Display ( "YOU WIN " , GREEN );
ch=0x1b;
getch();
break;
}

s2.com_play ( p1 );
s2.inc_disp();
if ( point_vanished ( p1 , s2 ) == 2 )
{
Message_Display ( "YOU LOSE " , GREEN );
ch=0x1b;
getch();
break;
}

delay ( 100 );
if ( KeyPressed == 1 )KeyPressed = 0;
}
if ( ch == 0x1b )
break;

ch = getch();
if ( KeyPressed == 1 )
{
KeyPressed = 0;
continue;
}
if ( ch == 0x1b )
break;
else if ( ch == 0 )
{
ch = getch ();
if ( ch == UP_ARROW )
{
s1.change_direction ( Upward );
KeyPressed = 1;
}
else if ( ch == DOWN_ARROW )
{
s1.change_direction ( Downward );
KeyPressed = 1;
}
else if ( ch == LEFT_ARROW )
{
s1.change_direction ( Backward );
KeyPressed = 1;
}
else if ( ch == RIGHT_ARROW )
{
s1.change_direction ( Forward );
KeyPressed = 1;
}
}
}
}



fore more codes you can Visit http://codesofprogramming.blogspot.in/