|
发表于 2015-5-17 19:15:47
|
显示全部楼层
转一个:
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include<time.h>
- showmine();
- setmine(int x);
- printmine();
- countmine(int rowno, int colno);
- char rowhead[20]=" 1 2 3 4 5 6\n";
- char rowhead2[20]=" ----------- \n";
- char rowone[20]= "1|\xf \xf \xf \xf \xf \xf \n";
- char rowtwo[20]= "2|\xf \xf \xf \xf \xf \xf \n";
- char rowthree[20]="3|\xf \xf \xf \xf \xf \xf \n";
- char rowfour[20]= "4|\xf \xf \xf \xf \xf \xf \n";
- char rowfive[20]= "5|\xf \xf \xf \xf \xf \xf \n";
- char rowsix[20]= "6|\xf \xf \xf \xf \xf \xf \n";
-
- int mines[8][8]={{0,0,0,0,0,0,0,0},
- {0,0,0,1,0,0,0,0},
- {0,0,0,0,1,0,0,0},
- {0,0,1,0,0,1,0,0},
- {0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,1,0},
- {0,0,0,0,1,0,0,0},
- {0,0,0,0,0,0,0,0},
- };
-
- int countstep=0;
- int n=10;
- main()
- {
- int i,j;
- int flag=1;
- showmine();
- setmine(n);
- printmine();
- while(flag)
- {
- printf("\n请输入位置:行号,列号:");
- scanf("%d,%d", &i,&j);
- if (mines[i][j]==1)
- {
-
- printmine();
- printf("\n BOOM!!!");
- getchar();
- getchar();
- flag=0;
- }
- else
- {
- countmine(i,j);
- system("cls");
- showmine();
- if(countstep==36-n)
- {
- printf("You Wind!");
- getchar();
- getchar();
- flag=0;
- }
- }
- }
-
- }
- countmine(int rowno, int colno)
- {
- int count;
- int i,j;
- i=rowno;
- j=colno;
- count=mines[i-1][j]+mines[i+1][j]+mines[i][j-1]+mines[i][j+1]
- +mines[i-1][j-1]+mines[i-1][j+1]+mines[i+1][j-1]+mines[i+1][j+1];
- switch(i)
- {
- case 1:
- rowone[2*j]=(char)(count+48);
-
- break;
- case 2:
- rowtwo[2*j]=(char)(count+48);
-
- break;
- case 3:
- rowthree[2*j]=(char)(count+48);
-
- break;
- case 4:
- rowfour[2*j]=(char)(count+48);
-
- break;
- case 5:
- rowfive[2*j]=(char)(count+48);
-
- break;
- case 6:
- rowsix[2*j]=(char)(count+48);
-
- break;
- }
- countstep=countstep+1;
- }
- showmine()
- {
- printf(rowhead);
- printf(rowhead2);
- printf(rowone);
- printf(rowtwo);
- printf(rowthree);
- printf(rowfour);
- printf(rowfive);
- printf(rowsix);
- }
- setmine(int x)
- { int i,j,k;
- for(i=1;i<=6;i++)
- for(j=1;j<=6;j++)
- mines[i][j]=0;
- srand(time(0));
- for(k=1;k<=x;)
- {
- i=rand()%6+1;
- j=rand()%6+1;
- if(mines[i][j]!=1)
- mines[i][j]=1;
- else
- continue;
- k++;
- }
- }
- printmine()
- { int i,j,k;
- system("cls");
- for(i=1;i<=6;i++)
- {for(j=1;j<=6;j++)
- if( mines[i][j]==1)
- printf("%c ",15);
- else
- printf("%c ",2);
- printf("\n");}
-
- }
复制代码 |
|