C++ Basit Kodlar

Konu sahibi son olarak 3347 gün önce görüldü
Kod:
/*The Game of Minesweeper */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (****) 
{
srand((unsigned)time(NULL));
char decision; /*Yes-No decision about playing again.*/
int number;
int mine; /*The number of mines.*/
int x,r,y,c; /*row and column*/
int minefield[10][10];

do /*If decision is Yes, place mines again.*/ 
{ 
printf ("________________________________\\\\n== WELCOME TO THE MINESWEEPER ==\\\\n");

/*User enters a number which is between 0 and 100.*/ 
do
{
mine=-1;/*To control characters which was entered by user.*/
printf ("How many mines do you want in the minefield? <max:100, min:0>: "),
scanf ("%d", &mine);
fflush(stdin);
if (mine<0 || mine>100)printf("Ninvalid code!");
}
while(mine<0 || mine>100);

for(x=0; x<10; x++)/*Filling "0" in all cubicles.*/ 
for(y=0; y<10; y++)
minefield[x][y]=0;

/*Delivering mines.*/ 
for (number=0; number<mine; number++)
{ 
do/*Not to select the same places.*/
{
x=rand()%10;
y=rand()%10;
}
while (minefield[x][y]==’m’);
minefield[x][y]=’m’;
}
/*Calculating numbers around the mines.*/
for (x=0;x<10;x++)
{
for(y=0;y<10;y++)
if (minefield[x][y]==’m’ )
{
for(r=x-1; r<=x+1; r++)
if (x!=-1)
if (x!=10)
{
for (c=y-1; c<=y+1; c++)
if (y!=-1)
if (y!=10)
{
if(minefield[r][c]!=’m’)
++minefield[r][c];
}
}
}

} 

for (x=0; x<10; x++) 
{
for (y=0; y<10; y++)
if (minefield[x][y]==’m’) printf ("m");
else printf ("%d",minefield[x][y]);
printf("\\\\n");
}
/*Asking user wheter play again or not.*/
printf("\\\\nDo you want to play again?<Y/N>: ");
scanf ("%c", &decision);
fflush(stdin);
}
while (decision==’y’ || decision==’Y’);
return (0);
}
 
Geri