Showing posts with label games in c. Show all posts
Showing posts with label games in c. Show all posts

Wednesday, 11 July 2012

TIC TAC TOE game in C



#include<stdio.h>
#include<conio.h>


void main()
{
int i,decision;
char po11= '7' , po12='8' , po13= '9' , po21='4' , po22='5' , po23='6' , po31='1' ,po32='2' ,po33='3';
clrscr();

printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);

for(i=1;i<=10;i++)
{

if(i==1||i==3||i==5||i==7||i==9)
{
printf(" player one where u want to enter press number = ");
scanf("%d",&decision);

      switch(decision)
      {
case 1:
if(po31=='1')
{
po31='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}
break;

case 2:
if(po32=='2')
{
po32='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;


case 3:
if(po33=='3')
{
po33='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;


case 4:
if(po21=='4')
{
po21='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;


case 5:
if(po22=='5')
{
po22='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;



case 6:
if(po23=='6')
{
po23='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}
break;


case 7:
if(po11=='7')
{
po11='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;


case 8:
if(po12=='8')
{
po12='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;



case 9:
if(po13=='9')
{
po13='X';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}
break;


      }

}


else if(i==2||i==4||i==6||i==8)
{
printf("\n player two where u want to enter press number = ");
scanf("%d",&decision);


      switch(decision)
      {
case 1:
if(po31=='1')
{
po31='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}
break;


case 2:
if(po32=='2')
{
po32='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;



case 3:
if(po33=='3')
{
po33='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;



case 4:
if(po21=='4')
{
po21='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;



case 5:
if(po22=='5')
{
po22='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;




case 6:
if(po23=='6')
{
po23='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}
break;




case 7:
if(po11=='7')
{
po11='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;



case 8:
if(po12=='8')
{
po12='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}

break;


case 9:
if(po13=='9')
{
po13='O';
printf(" %c | %c | %c \n", po11, po12, po13);
printf(" %c | %c | %c \n", po21, po22, po23);
printf(" %c | %c | %c \n\n\n\n", po31, po32, po33);
}
break;


      }

}


if(po11==po12 && po11==po13||po21==po22 && po21==po23||po31==po32 && po31== po33)
{
    if(po11=='X'||po21=='X'||po31=='X')
    {
    printf("player one win");
    break;
    }
    else
    {
    printf("player two win");
    break;
    }
}



else if(po11==po21 && po11==po31||po12==po22 && po12==po32||po13==po23 && po13== po33)
{
   if(po11=='X'||po12=='X'||po13=='X')
    {
    printf("player one win");
    break;
    }
    else
    {
    printf("player two win");
    break;
    }
}





else if(po11==po22 && po11==po33||po13==po22 && po13==po31)
{
   if(po11=='X'||po13=='X')
   {
   printf("player one win");
   break;
   }
   else
   {
   printf("player two win");
   break;
   }
}

}
getche();


}

Tuesday, 10 July 2012

Hangman Game in C


#include<stdio.h>
#include<conio.h>


void main()

{

int con,coi;

char a,b,c,d,e,f,g='_',h='_',i='_',j='_',k='_';

 clrscr();

 printf(" enter the five letter word = ");

 printf("\n%c %c %c %c %c\n",g,h,i,j,k);

 a=getch();

 printf("  ");

 b=getch();

 printf("  ");

 c=getch();

 printf("  ");

 d=getch();

 printf("  ");

 e=getch();

 printf("\n\n\nEnter how term u give to player to guess = ");

 scanf("%d",&coi);

 clrscr();



 printf("\n\nEnter the letter for guess = ------- \n");



 for(con=1;con<=coi;con++)

 {
printf("\n\n\tEnter again =  ");
f=getche();

if(f==a)
{
if(g=='_')
{
g=f;

}
}
if(f==b)
{
if(h=='_')
{
h=f;

}
}
if(f==c)


{
if(i=='_')
{
i=f;

}
}
if(f==d)
{
if(j=='_')
{
j=f;

}
}
       if(f==e)
       {
if(k=='_')
{
k=f;
}
       }


  printf("\n\n\n\t%c %c %c %c %c",g,h,i,j,k);



if (a==g&&b==h&&c==i&&d==j&&e==k)
{

printf("\n\n\nYou have won right word is = %c%c%c%c%c",a,b,c,d,e);

break;
}
}



if(g=='_'||h=='_'||i=='_'||j=='_'||k=='_')
  {
  printf("\n\n\nYou have loss it \n\n  right word is = %c%c%c%c%c",a,b,c,d,e);

  }



getche();

}

15 PUZZLE Game Code in C


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

int Game[4][4];

void Reset();
void Left();
void Right();
void Up();
void Down();
void Print();
int  Check();
void Logo();




void main()

{
int counter=0;
 char character='a';
 clrscr();

Reset();      
Logo();              
Print();
while(character!='q')
{
character=getch();
switch(character)
{
case 80:
Down();
Print();
Check();
break;

case 77:
Right();
Print();
Check();
break;

case 75:
Left();
Print();
Check();
break;

case 72:
Up();
Print();
Check();
break;

case'r':
Reset();
Print();
Check();
break;
}
}



}


void Logo()
{

clrscr();

printf("\n==============================================================================");
printf("\n                 This GAME Is Designed By ADMIN                ");
printf("\n==============================================================================");

printf("\n\n\n\n\n\n\t\t\t Keys: \n\n\n\t\t\t\t Up");
printf("\n\n\t\t\t\t Down");
printf("\n\n\t\t\t\t Left");
printf("\n\n\t\t\t\t Right\n\n\n\n");


printf("\n\n\n\n\t\t               'q' to Quit.");
printf("\n\n\n\n\n\n\n\t\t\tPress Any Key To Continue");

getch();
}





void Print()
{       clrscr();

printf("\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\n\t\t\t_____________________");
printf("\n\t\t\t|    |    |    |    |");
printf("\n\t\t\t|    |    |    |    |");
gotoxy(27,16);
{
printf("%d",Game[0][0]);
}
gotoxy(32,16);
{
printf("%d",Game[0][1]);
}
gotoxy(37,16);
{
printf("%d",Game[0][2]);
}
gotoxy(42,16);
{
printf("%d",Game[0][3]);
}
printf("\n\t\t\t|    |    |    |    |");
printf("\n\t\t\t---------------------");
printf("\n\t\t\t|    |    |    |    |");
printf("\n\t\t\t|    |    |    |    |");
gotoxy(27,20);
{
printf("%d",Game[1][0]);
}
gotoxy(32,20);
{
printf("%d",Game[1][1]);
}
gotoxy(37,20);
{
printf("%d",Game[1][2]);
}
gotoxy(42,20);
{
printf("%d",Game[1][3]);
}
printf("\n\t\t\t|    |    |    |    |");
printf("\n\t\t\t---------------------");
printf("\n\t\t\t|    |    |    |    |");
printf("\n\t\t\t|    |    |    |    |");
gotoxy(27,24);
{
printf("%d",Game[2][0]);
} gotoxy(32,24);
{
printf("%d",Game[2][1]);
}
gotoxy(37,24);
{
printf("%d",Game[2][2]);
}
gotoxy(42,24);
{
printf("%d",Game[2][3]);
}
printf("\n\t\t\t|    |    |    |    |");
printf("\n\t\t\t---------------------");
printf("\n\t\t\t|    |    |    |    |");
printf("\n\t\t\t|    |    |    |    |");
gotoxy(27,28);
{
printf("%d",Game[3][0]);
}
gotoxy(32,28);
{
printf("%d",Game[3][1]);
}
gotoxy(37,28);
{
printf("%d",Game[3][2]);
}
gotoxy(42,28);
{
printf("%d",Game[3][3]);
}
printf("\n\t\t\t|    |    |    |    |");
printf("\n\t\t\t~~~~~~~~~~~~~~~~~~~~~");
     
}




void Reset()
{
int reset=15,i,j;

for ( i=0;i<4;i++)
{
for ( j=0;j<4;j++)
{
Game[i][j]=reset--;
}
}
Game[3][3]=0;
}




int Check()
{

    int count=0,i,j,counter;
    int check=0;
    if(check!=0)
    {
    counter++;
    }

for ( i=0;i<4;i++)
{
for ( j=0;j<4;j++)
{
count++;
if(i==3 && j==3)
{
break;
}
if( Game[i][j]==count)
{
check++;
}

}
}
if(check==15)
{
gotoxy(32,36);
printf("Congratulations");
return 1;

}
else return 0;
}





void Left()
{
int x,y,i,j;
       
for ( i=0;i<4;i++)
{
for ( j=0;j<4;j++)
{
if (Game[i][j]==0)
{
x=i;
y=j;  
}
}
}
if(y!=3)
{
Game[x][y]=Game[x][y+1];
Game[x][y+1]=0;
}


}



void Right()
{
int x,y,i,j;

for ( i=0;i<4;i++)
{
for ( j=0;j<4;j++)
{
if (Game[i][j]==0)
{
x=i;
y=j;  
}
}
}
if(y!=0)
{
Game[x][y]=Game[x][y-1];
Game[x][y-1]=0;
}


}




void Up()
{
int x,y,i,j;

for ( i=0;i<4;i++)
{
for ( j=0;j<4;j++)
{
if (Game[i][j]==0)
{
x=i;
y=j;  
}
}
}
if(x!=3)
{
Game[x][y]=Game[x+1][y];
Game[x+1][y]=0;
}


}





void Down()
{
int x,y,i,j;

for ( i=0;i<4;i++)
{
for ( j=0;j<4;j++)
{
if (Game[i][j]==0)
{
x=i;
y=j;  
}
}
}
if(x!=0)
{
Game[x][y]=Game[x-1][y];
Game[x-1][y]=0;
}


}