最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

c语言游戏代码大全,c语言经典游戏代码

IT圈 admin 49浏览 0评论

2024年1月23日发(作者:衷吉)

case 'a':case 'A':if(a>0)printf(' '),GamePosition(hout,--a,b),printf('☆');break;case 'd':case 'D':if(a<20)printf('>break;}}CloseHandle(hThread);system('pause');return 0;}扫雷游戏代码源码#include#include#includeint main (){int delta[8][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};int row =0,col = 0,num = 0;char map[10][10] = {0};char show[10][10] = {0};

srand(time(0));for(row = 0;row <=>for(col = 0;col <=>map[row][col] = '0';}}do{row = rand() % 10;col = rand() % 10;if(map[row][col] == '0'){map[row][col] = 'x';num++;}}while(num <>for (row = 0;row <=>for (col = 0;col <=>if(map[row][col] != 'x'){int cnt = 0;for (num = 0;num <=>if(row + delta[num][0] <>continue;}if(row + delta[num][0] > 9){continue;}if(col + delta[num][1] <>continue;}if(col + delta[num][1] > 9){continue;}if(map[row + delta[num][0]][col + delta[num][1]]== 'x'){cnt++;}

}map[row][col] = '0' + cnt;}}}for (row = 0;row <>for(col = 0;col < 10;col="">printf('* ');}printf('n');}num = 0;int x,y;do{printf('please enter the coordinate of array:');scanf('%d%d',&x,&y);show[x-1][y-1] = 1;if(map[x-1][y-1] == '0'){for (num = 0;num <=>if(x-1 + delta[num][0] <>continue;}if(x-1 + delta[num][0] > 9){continue;}if(y -1+ delta[num][1] <>continue;}if(y-1 + delta[num][1] > 9){continue;}show[x-1+delta[num][0]][y-1+delta[num][1]] = 1;}}

if (map[x-1][y-1]!= 'x'&&map[x-1][y-1] != '0'){for (num = 0;num <=>int cnt = 0;if(x-1 + delta[num][0] <>continue;}if(x-1 + delta[num][0] > 9){continue;}if(y-1 + delta[num][1] <>continue;}if(y-1 + delta[num][1] > 9){continue;}if( map[x -1 + delta[num][0]][y -1+ delta[num][1]] != 'x'){show[x-1 + delta[num][0]][y -1+ delta[num][1]] = 1 ;}}}if(map[x-1][y-1] == 'x') {printf('game over!n');for (row = 0;row <>for(col = 0;col < 10;col="">printf('%c ',map[row][col]);}printf('n');}return 0;}system('cls');printf('mine sweeping:n');for (row = 0;row <>for(col = 0;col < 10;col="">

if (show[row][col] == 1){printf('%c ', map[row][col]);}else{printf('* ');}}printf('n');}num = 0;for (row = 0;row <>for(col = 0;col < 10;col="">if (show[row][col] == 1 ){num++;}}}printf('num:%dn',num);}while(num <>printf('you win!');return 0;}

2024年1月23日发(作者:衷吉)

case 'a':case 'A':if(a>0)printf(' '),GamePosition(hout,--a,b),printf('☆');break;case 'd':case 'D':if(a<20)printf('>break;}}CloseHandle(hThread);system('pause');return 0;}扫雷游戏代码源码#include#include#includeint main (){int delta[8][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};int row =0,col = 0,num = 0;char map[10][10] = {0};char show[10][10] = {0};

srand(time(0));for(row = 0;row <=>for(col = 0;col <=>map[row][col] = '0';}}do{row = rand() % 10;col = rand() % 10;if(map[row][col] == '0'){map[row][col] = 'x';num++;}}while(num <>for (row = 0;row <=>for (col = 0;col <=>if(map[row][col] != 'x'){int cnt = 0;for (num = 0;num <=>if(row + delta[num][0] <>continue;}if(row + delta[num][0] > 9){continue;}if(col + delta[num][1] <>continue;}if(col + delta[num][1] > 9){continue;}if(map[row + delta[num][0]][col + delta[num][1]]== 'x'){cnt++;}

}map[row][col] = '0' + cnt;}}}for (row = 0;row <>for(col = 0;col < 10;col="">printf('* ');}printf('n');}num = 0;int x,y;do{printf('please enter the coordinate of array:');scanf('%d%d',&x,&y);show[x-1][y-1] = 1;if(map[x-1][y-1] == '0'){for (num = 0;num <=>if(x-1 + delta[num][0] <>continue;}if(x-1 + delta[num][0] > 9){continue;}if(y -1+ delta[num][1] <>continue;}if(y-1 + delta[num][1] > 9){continue;}show[x-1+delta[num][0]][y-1+delta[num][1]] = 1;}}

if (map[x-1][y-1]!= 'x'&&map[x-1][y-1] != '0'){for (num = 0;num <=>int cnt = 0;if(x-1 + delta[num][0] <>continue;}if(x-1 + delta[num][0] > 9){continue;}if(y-1 + delta[num][1] <>continue;}if(y-1 + delta[num][1] > 9){continue;}if( map[x -1 + delta[num][0]][y -1+ delta[num][1]] != 'x'){show[x-1 + delta[num][0]][y -1+ delta[num][1]] = 1 ;}}}if(map[x-1][y-1] == 'x') {printf('game over!n');for (row = 0;row <>for(col = 0;col < 10;col="">printf('%c ',map[row][col]);}printf('n');}return 0;}system('cls');printf('mine sweeping:n');for (row = 0;row <>for(col = 0;col < 10;col="">

if (show[row][col] == 1){printf('%c ', map[row][col]);}else{printf('* ');}}printf('n');}num = 0;for (row = 0;row <>for(col = 0;col < 10;col="">if (show[row][col] == 1 ){num++;}}}printf('num:%dn',num);}while(num <>printf('you win!');return 0;}

发布评论

评论列表 (0)

  1. 暂无评论