鱼C论坛

 找回密码
 立即注册
查看: 5437|回复: 6

求一个用C语言写的扫雷代码!

[复制链接]
发表于 2015-5-17 19:15:46 | 显示全部楼层 |阅读模式
20鱼币
要求有扫雷的全部功能以及详细注释

最佳答案

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2015-5-17 19:15:47 | 显示全部楼层
转一个:
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include<time.h>
  5. showmine();
  6. setmine(int x);
  7. printmine();
  8. countmine(int rowno, int colno);
  9. char rowhead[20]="  1 2 3 4 5 6\n";
  10. char rowhead2[20]="  ----------- \n";
  11. char rowone[20]=  "1|\xf \xf \xf \xf \xf \xf \n";
  12. char rowtwo[20]=  "2|\xf \xf \xf \xf \xf \xf \n";
  13. char rowthree[20]="3|\xf \xf \xf \xf \xf \xf \n";
  14. char rowfour[20]= "4|\xf \xf \xf \xf \xf \xf \n";
  15. char rowfive[20]= "5|\xf \xf \xf \xf \xf \xf \n";
  16. char rowsix[20]=  "6|\xf \xf \xf \xf \xf \xf \n";
  17.                     
  18. int mines[8][8]={{0,0,0,0,0,0,0,0},
  19.     {0,0,0,1,0,0,0,0},
  20.     {0,0,0,0,1,0,0,0},
  21.     {0,0,1,0,0,1,0,0},
  22.     {0,0,0,0,0,0,0,0},
  23.     {0,0,0,0,0,0,1,0},
  24.     {0,0,0,0,1,0,0,0},
  25.     {0,0,0,0,0,0,0,0},
  26.      };  

  27. int countstep=0;
  28. int n=10;
  29. main()
  30. {
  31. int i,j;
  32. int flag=1;
  33. showmine();
  34.   setmine(n);
  35.       printmine();
  36. while(flag)
  37. {
  38.   printf("\n请输入位置:行号,列号:");
  39.   scanf("%d,%d", &i,&j);
  40.   if (mines[i][j]==1)
  41.   {
  42.    
  43.    printmine();
  44.    printf("\n BOOM!!!");
  45.    getchar();
  46.    getchar();
  47.    flag=0;
  48.   }
  49.   else
  50.   {
  51.    countmine(i,j);
  52.     system("cls");
  53.    showmine();
  54.    if(countstep==36-n)
  55.    {
  56.     printf("You Wind!");
  57.     getchar();
  58.     getchar();
  59.     flag=0;
  60.    }
  61.   }
  62. }

  63. }
  64. countmine(int rowno, int colno)
  65. {
  66. int count;
  67. int i,j;
  68. i=rowno;
  69. j=colno;
  70. count=mines[i-1][j]+mines[i+1][j]+mines[i][j-1]+mines[i][j+1]
  71.   +mines[i-1][j-1]+mines[i-1][j+1]+mines[i+1][j-1]+mines[i+1][j+1];
  72. switch(i)
  73. {
  74. case 1:
  75.   rowone[2*j]=(char)(count+48);
  76.   
  77.   break;
  78. case 2:
  79.   rowtwo[2*j]=(char)(count+48);
  80.   
  81.   break;
  82. case 3:
  83.   rowthree[2*j]=(char)(count+48);
  84.   
  85.   break;
  86. case 4:
  87.   rowfour[2*j]=(char)(count+48);
  88.   
  89.   break;
  90. case 5:
  91.   rowfive[2*j]=(char)(count+48);
  92.   
  93.   break;
  94. case 6:
  95.   rowsix[2*j]=(char)(count+48);
  96.   
  97.   break;
  98. }
  99.   countstep=countstep+1;
  100. }
  101. showmine()
  102. {
  103. printf(rowhead);
  104. printf(rowhead2);
  105. printf(rowone);
  106. printf(rowtwo);
  107. printf(rowthree);
  108. printf(rowfour);
  109. printf(rowfive);
  110. printf(rowsix);
  111. }
  112. setmine(int x)
  113. {  int i,j,k;
  114.    for(i=1;i<=6;i++)
  115.     for(j=1;j<=6;j++)
  116.          mines[i][j]=0;
  117.      srand(time(0));
  118. for(k=1;k<=x;)
  119. {
  120.   i=rand()%6+1;
  121.         j=rand()%6+1;
  122.         if(mines[i][j]!=1)
  123.    mines[i][j]=1;
  124.   else
  125.    continue;
  126.   k++;
  127. }
  128. }
  129. printmine()
  130. {  int i,j,k;
  131.   system("cls");
  132.    for(i=1;i<=6;i++)
  133.    {for(j=1;j<=6;j++)
  134.         if( mines[i][j]==1)
  135.    printf("%c ",15);
  136.    else
  137.     printf("%c ",2);
  138.    printf("\n");}

  139. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-5-17 21:17:02 | 显示全部楼层

你这个扫雷不正宗,我以前就看过了,我要的是弄个新的界面想win7里面的那种,不过还是谢谢了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2015-6-6 00:21:19 | 显示全部楼层
混个鱼币走人:big:big:big
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-6-6 13:50:34 | 显示全部楼层
你这个网上搜的吧?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-6-6 13:51:07 | 显示全部楼层

早在网上看过了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-6-6 13:52:03 | 显示全部楼层

算了也不打算用c写了,送你鱼币吧!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-20 03:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表