/* Chaythanya
If you are using turbo cpp compiler try to include conio.h ang uncomment the
function clrscr() for better looks */
#include<stdio.h>
#include<stdlib.h>
//#include<conio.h>
char a[5][5];
char pa[5][5];
int pc=0;
int r,c;
void intro(char* player);
int find(int choice);
void firstdisplay();
void make();
void play();
void display(char a[5][5]);
void play();
void intro(char* player)
{
printf("\n\t Welcome %s.. here are the rules of the game\n",player);
firstdisplay();
printf("\n\t This is the board, there are no empty columns each column is filled with either mine or character ");
printf("\n\t choose the appropriate no: to open the block\n\t Game begins!!...\n\n\n");
}
void make()
{
int i,j;
int d=65;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
pa[i][j]=' ';
if(pc==1)
{
if(5*(i+j)%3==0)
a[i][j]='X';
else
{
if((d!=120)&&(d!=88))
{
a[i][j]=d;
d++;
}
}
}
else
{
if((i+j)%(pc+1)==0)
a[i][j]='X';
else
{
if((d!=120)&&(d!=88))
{
a[i][j]=d;
d++;
}
}
}
}
}
firstdisplay();
}
void firstdisplay()
{
printf("\t _____ _____ _____ _____ _____ \n");
printf("\t| | | | | | \n");
printf("\t| 1 | 2 | 3 | 4 | 5 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| 6 | 7 | 8 | 9 | 10 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| 11 | 12 | 13 | 14 | 15 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| 16 | 17 | 18 | 19 | 20 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| 21 | 22 | 23 | 24 | 25 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
}
void play()
{
int b;
printf("\n\t Enter the block you want to open:");
scanf("%d",&b);
int success= find(b);
if(!success)
{
pa[r][c]=a[r][c];
if(a[r][c]=='X')
{
display(a);
return;
}
else
{ display(pa);
play();
}
}
else
{
printf("\n\n\t Wrong choice!!.. try again!!\n\n");
display(pa);
play();
}
}
int find(int choice)
{
if(choice==1){
r=0;
c=0;
return 0;
}
else if(choice==2){
r=0;
c=1;
return 0;
}
else if(choice==3){
r=0;
c=2;
return 0;
}
else if(choice==4){
r=0;
c=3;
return 0;
}
else if(choice==5){
r=0;
c=4;
return 0;
}
else if(choice==6){
r=1;
c=0;
return 0;
}
else if(choice==7){
r=1;
c=1;
return 0;
}
else if(choice==8){
r=1;
c=2;
return 0;
}
else if(choice==9){
r=1;
c=3;
return 0;
}
else if(choice==10){
r=1;
c=4;
return 0;
}
else if(choice==11){
r=2;
c=0;
return 0;
}
else if(choice==12){
r=2;
c=1;
return 0;
}
else if(choice==13){
r=2;
c=2;
return 0;
}
else if(choice==14){
r=2;
c=3;
return 0;
}
else if(choice==15){
r=2;
c=4;
return 0;
}
else if(choice==16){
r=3;
c=0;
return 0;
}
else if(choice==17){
r=3;
c=1;
return 0;
}
else if(choice==18){
r=3;
c=2;
return 0;
}
else if(choice==19){
r=3;
c=3;
return 0;
}
else if(choice==20){
r=3;
c=4;
return 0;
}
else if(choice==21){
r=4;
c=0;
return 0;
}
else if(choice==22){
r=4;
c=1;
return 0;
}
else if(choice==23){
r=4;
c=2;
return 0;
}
else if(choice==24){
r=4;
c=3;
return 0;
}
else if(choice==25){
r=4;
c=4;
return 0;
}
else
return 1;
}
void display(char a[5][5])
{
printf("\t _____ _____ _____ _____ _____ \n");
printf("\t| | | | | | \n");
printf("\t| %c | %c | %c | %c | %c |\n",a[0][0],a[0][1],a[0][2],a[0][3],a[0][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| %c | %c | %c | %c | %c |\n",a[1][0],a[1][1],a[1][2],a[1][3],a[1][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| %c | %c | %c | %c | %c |\n",a[2][0],a[2][1],a[2][2],a[2][3],a[2][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| %c | %c | %c | %c | %c |\n",a[3][0],a[3][1],a[3][2],a[3][3],a[3][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| %c | %c | %c | %c | %c |\n",a[4][0],a[4][1],a[4][2],a[4][3],a[4][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
}
void main()
{
char player,choice;
do
{
pc++;
// clrscr();
printf("\t\t MINE SWEEPER------> DEMO");
printf("\n\t\t*************************");
printf("\n\n\tEnter the name of the player:");
scanf(" %s",&player);
intro(&player);
make();
play();
printf ("\n\n\t GAME OVER!!\n\n");
printf("\n\n\tDo you wish to continue?(Y/n)");
scanf(" %c",&choice);
if(pc>3)
{
printf("\n\n\tOOops!! You have exceeded your maximum no: of chances well.. Better luck next time..\n\n");
exit(1);
}
}
while((choice=='Y'||choice=='y'));
}
If you are using turbo cpp compiler try to include conio.h ang uncomment the
function clrscr() for better looks */
#include<stdio.h>
#include<stdlib.h>
//#include<conio.h>
char a[5][5];
char pa[5][5];
int pc=0;
int r,c;
void intro(char* player);
int find(int choice);
void firstdisplay();
void make();
void play();
void display(char a[5][5]);
void play();
void intro(char* player)
{
printf("\n\t Welcome %s.. here are the rules of the game\n",player);
firstdisplay();
printf("\n\t This is the board, there are no empty columns each column is filled with either mine or character ");
printf("\n\t choose the appropriate no: to open the block\n\t Game begins!!...\n\n\n");
}
void make()
{
int i,j;
int d=65;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
pa[i][j]=' ';
if(pc==1)
{
if(5*(i+j)%3==0)
a[i][j]='X';
else
{
if((d!=120)&&(d!=88))
{
a[i][j]=d;
d++;
}
}
}
else
{
if((i+j)%(pc+1)==0)
a[i][j]='X';
else
{
if((d!=120)&&(d!=88))
{
a[i][j]=d;
d++;
}
}
}
}
}
firstdisplay();
}
void firstdisplay()
{
printf("\t _____ _____ _____ _____ _____ \n");
printf("\t| | | | | | \n");
printf("\t| 1 | 2 | 3 | 4 | 5 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| 6 | 7 | 8 | 9 | 10 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| 11 | 12 | 13 | 14 | 15 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| 16 | 17 | 18 | 19 | 20 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| 21 | 22 | 23 | 24 | 25 |\n");
printf("\t|_____|_____|_____|_____|_____|\n");
}
void play()
{
int b;
printf("\n\t Enter the block you want to open:");
scanf("%d",&b);
int success= find(b);
if(!success)
{
pa[r][c]=a[r][c];
if(a[r][c]=='X')
{
display(a);
return;
}
else
{ display(pa);
play();
}
}
else
{
printf("\n\n\t Wrong choice!!.. try again!!\n\n");
display(pa);
play();
}
}
int find(int choice)
{
if(choice==1){
r=0;
c=0;
return 0;
}
else if(choice==2){
r=0;
c=1;
return 0;
}
else if(choice==3){
r=0;
c=2;
return 0;
}
else if(choice==4){
r=0;
c=3;
return 0;
}
else if(choice==5){
r=0;
c=4;
return 0;
}
else if(choice==6){
r=1;
c=0;
return 0;
}
else if(choice==7){
r=1;
c=1;
return 0;
}
else if(choice==8){
r=1;
c=2;
return 0;
}
else if(choice==9){
r=1;
c=3;
return 0;
}
else if(choice==10){
r=1;
c=4;
return 0;
}
else if(choice==11){
r=2;
c=0;
return 0;
}
else if(choice==12){
r=2;
c=1;
return 0;
}
else if(choice==13){
r=2;
c=2;
return 0;
}
else if(choice==14){
r=2;
c=3;
return 0;
}
else if(choice==15){
r=2;
c=4;
return 0;
}
else if(choice==16){
r=3;
c=0;
return 0;
}
else if(choice==17){
r=3;
c=1;
return 0;
}
else if(choice==18){
r=3;
c=2;
return 0;
}
else if(choice==19){
r=3;
c=3;
return 0;
}
else if(choice==20){
r=3;
c=4;
return 0;
}
else if(choice==21){
r=4;
c=0;
return 0;
}
else if(choice==22){
r=4;
c=1;
return 0;
}
else if(choice==23){
r=4;
c=2;
return 0;
}
else if(choice==24){
r=4;
c=3;
return 0;
}
else if(choice==25){
r=4;
c=4;
return 0;
}
else
return 1;
}
void display(char a[5][5])
{
printf("\t _____ _____ _____ _____ _____ \n");
printf("\t| | | | | | \n");
printf("\t| %c | %c | %c | %c | %c |\n",a[0][0],a[0][1],a[0][2],a[0][3],a[0][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| %c | %c | %c | %c | %c |\n",a[1][0],a[1][1],a[1][2],a[1][3],a[1][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| %c | %c | %c | %c | %c |\n",a[2][0],a[2][1],a[2][2],a[2][3],a[2][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| %c | %c | %c | %c | %c |\n",a[3][0],a[3][1],a[3][2],a[3][3],a[3][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
printf("\t| | | | | |\n");
printf("\t| %c | %c | %c | %c | %c |\n",a[4][0],a[4][1],a[4][2],a[4][3],a[4][4]);
printf("\t|_____|_____|_____|_____|_____|\n");
}
void main()
{
char player,choice;
do
{
pc++;
// clrscr();
printf("\t\t MINE SWEEPER------> DEMO");
printf("\n\t\t*************************");
printf("\n\n\tEnter the name of the player:");
scanf(" %s",&player);
intro(&player);
make();
play();
printf ("\n\n\t GAME OVER!!\n\n");
printf("\n\n\tDo you wish to continue?(Y/n)");
scanf(" %c",&choice);
if(pc>3)
{
printf("\n\n\tOOops!! You have exceeded your maximum no: of chances well.. Better luck next time..\n\n");
exit(1);
}
}
while((choice=='Y'||choice=='y'));
}






0 comments:
Post a Comment