Skip to main content

C-Programming:Minesweeper


-------------------------------------------------------------------------
Note:-
This game is tested on on CodeBlocks IDE and DevC++ IDE on Windows OS.
To run this game , use of CodeBlocks IDE or DevC++ IDE (on Windows OS) is recommended.
Using other IDE might generate errors.

(Windows OS is necessary, running Game on other OS might not work)
--------------------------------------------------------------------------   

#include<stdio.h> 
#include<stdlib.h>  
                 
                 
void welcome();
void rand_mines(char msweep[12][12]);
void printmatrix(char msweep[12][12],int r,char user_chart[12][12]);
int process(char msweep[12][12],int r,int c,char user_chart[12][12]);

int main()

{                    // size of array is 10,array starts from 1 to 11

char msweep[12][12] = {{'0'}};     
int i,r,c;  
char user_chart[12][12] = {{'0'}};

   
rand_mines(msweep); 

 
  printf("Enter your location(ONLY 1 - 11) on the minefield x,y\n");
  scanf("%d%d",&r,&c);

              printmatrix(msweep,12,user_chart); 

i = process(msweep,r,c,user_chart); //returns 1 or 0,1 is notmine 0 = mine
 
    
  while(i == 1)    
   {
     printf("Lucky BRAT, live on for another step\n");     
     printf(" %c Surrounding MINEs\n\n",msweep[r][c]);
    
     printmatrix(msweep,12,user_chart);
    
     printf("enter next move...(ONLY 1 - 11) ");
     scanf("%d%d",&r,&c);
     i=0;
    
     i = process(msweep,r,c,user_chart);   
  
  
   } 

  if(i==0)
   printf("Game OVER, ta ta. you stepped on a MINE !!\n");

return 0;   
   
}

void welcome()
{

char op; // opereation

printf("Welcome to MINESWEEPER in C >>.....\n");

printf("Enter <<\n");
printf("         i for instructions\n");
printf("         any other key to enter game\n");
scanf("%c",&op);

if(op == 'i')
  {
   printf("OH DEAR, what a shock you are unfortunatly in the midst of a "); printf("mine field.\n");   
  printf("Enter the coordinates of the x and y plane between 1 to 11\n");  
   printf("Are you destined to DIE or live ?\n");
   printf("HA ha ha hah, GOOD LUCK\n\n");
 
  }
else
return;   
}

void rand_mines(char msweep[12][12])

{
   
int r,c,m;


for(m=0;m<20;m++) // plant 20 rand mines
    
  {
   r = rand() % 13; // this is mine planting    
                    // so can be at the edges aswell
   c = rand() % 13; // so 0 to 13 is APPROPRIATE.
   
  
   msweep[r][c] = '9';
  printf("%d %d \n",r,c);
 
  } 
   
return;

}

void printmatrix(char msweep[][12],int r,char user_chart[12][12])
{
   
int i,j;   

printf("   .-.-.-.-.-.-.-.-.-.-.-.\n");

for(i=1;i<r;i++)
  {
   printf("./.");

   for(j=1;j<12;j++) //printing 1 to 11   
    {
     printf("%c ",user_chart[i][j]);//to refer to mines use msweep[i][j]   
    }
  
   printf(".\\.");
  
   printf("\n");  
 
  }

printf(".-.-.-.-.-.-.-.-.-.-.-.-.\n\n");

return;   
}

int process(char msweep[12][12],int r,int c,char user_chart[12][12])
{
   
int i=r,j=c,b=0,k;   
char C;

if(msweep[r][c] == '9')  
{  k=0;
   return k;
}
else
  {
   if(msweep[i-1][j-1] == '9')   
    b++; 
   if(msweep[i-1][j] == '9')   
    b++; 
   if(msweep[i-1][j+1] == '9')   
    b++; 
   if(msweep[i][j-1] == '9')   
    b++; 
   if(msweep[i][j+1] == '9')   
    b++; 
   if(msweep[i+1][j-1] == '9')   
    b++; 
   if(msweep[i+1][j] == '9')   
    b++; 
   if(msweep[i+1][j+1] == '9')   
    b++; 
 
  C = (char)(((int)'0')+b); // to covert int to char;

   msweep[r][c] = C;
   user_chart[r][c] = C;
 
  }
   
return 1; 
   
}

Comments

Popular posts from this blog

WINDOWS 8.1 ACTIVATION KEYS

Windows 8 Cracked Keys(Activation/Product Keys) 4NJ8T-3MRPX-HPRB6-9GKWD-Y4FXB J7JBD-2NTPH-HXFHK-3FXFP-TMQG7 VK7JG-NPHTM-C97JM-9MPGT-3V66T NG4HW-VH26C-733KW-K6F98-J8CK4 GNBB8-YVD74-QJHX6-27H4K-8QHDG XCVCF-2NXM9-723PB-MHCB7-2RYQQ HB39N-V9K6F-P436V-KWBTC-Q3R9V 6PN82-R4BBH-XX8K2-DCK84-VMFDH QGR4N-78PMD-KCRQ7-83BXT-YG667 BTNJ7-FFMBR-FF9BH-7QMJ9-H49T7 G9XNM-YYY38-8R9HM-YFPTX-T8XT7 CR8NG-63KCR-X2MPD-G7M7P-GQ4DH NGMMV-FVDXB-QP6XF-9FTRT-P7F9V 7TWWK-WNB2W-VRVPV-XG6RV-MBFDH HN42W-QF3D6-2KM6W-C79XK-JW8XV RFQ3N-4Y4XR-JY9PV-883PR-BY2KV VC972-N7YXW-G9WQY-VBDP4-GXT67 QDCTN-G878G-WBHHQ-GW7XP-XTJXV NBCCB-JJJDX-PKBKJ-KQX8X-WTV3H 2747P-9WNWW-MD6JF-HRC36-HFPKV 2Y8NR-PPTC4-XYX8G-4KQGC-6JCKV 38N79-8B9GY-J4JYJ-D29V3-YBFDH 3FCND-JTWFM-24VQ8-QXTMB-TXT67 GX9N8-4H2FH-D987T-BQ9GK-XKT67 P8MCC-G7NDR-D27YY-Q83CC-8W8XV KKPMN-469HY-H6V43-T8VX2-8W8XV T3NJK-3P683-2T7BJ-2X27F-8B2KV HB39N-V9K6F-P436V-KWBTC-Q3R9V 6PN82-R4BBH-XX8K2-DCK84-VMFDH QGR4N-78PMD-KCRQ7-83BXT-YG667 BTNJ7-FFMBR-FF9BH-7QMJ9-H49T7 G9XNM-YYY38-8R9HM-...