(完整word版)纯C语言写的一个小型游戏 源代码 求一个用C语言编写的小游戏代码

\u7528C++\u7f16\u5199\u7684\u5c0f\u6e38\u620f\u6e90\u4ee3\u7801

\u4f7f\u7528\u8bed\u8a00\uff1aC++\u4f7f\u7528\u5de5\u5177\uff1avs2019

#include
#include
#include



/////////////////////////////////////////////
// \u5b9a\u4e49\u5e38\u91cf\u3001\u679a\u4e3e\u91cf\u3001\u7ed3\u6784\u4f53\u3001\u5168\u5c40\u53d8\u91cf
/////////////////////////////////////////////

#defineWIDTH10// \u6e38\u620f\u533a\u5bbd\u5ea6
#defineHEIGHT22// \u6e38\u620f\u533a\u9ad8\u5ea6
#defineSIZE20// \u6bcf\u4e2a\u6e38\u620f\u533a\u5355\u4f4d\u7684\u5b9e\u9645\u50cf\u7d20

// \u5b9a\u4e49\u64cd\u4f5c\u7c7b\u578b
enum CMD
{
CMD_ROTATE,// \u65b9\u5757\u65cb\u8f6c
CMD_LEFT, CMD_RIGHT, CMD_DOWN,// \u65b9\u5757\u5de6\u3001\u53f3\u3001\u4e0b\u79fb\u52a8
CMD_SINK,// \u65b9\u5757\u6c89\u5e95
CMD_QUIT// \u9000\u51fa\u6e38\u620f
};

// \u5b9a\u4e49\u7ed8\u5236\u65b9\u5757\u7684\u65b9\u6cd5
enum DRAW
{
SHOW,// \u663e\u793a\u65b9\u5757
HIDE,// \u9690\u85cf\u65b9\u5757
FIX// \u56fa\u5b9a\u65b9\u5757
};

// \u5b9a\u4e49\u4e03\u79cd\u4fc4\u7f57\u65af\u65b9\u5757
struct BLOCK
{
WORD dir[4];// \u65b9\u5757\u7684\u56db\u4e2a\u65cb\u8f6c\u72b6\u6001
COLORREF color;// \u65b9\u5757\u7684\u989c\u8272
}g_Blocks[7] = {{0x0F00, 0x4444, 0x0F00, 0x4444, RED},// I
{0x0660, 0x0660, 0x0660, 0x0660, BLUE},// \u53e3
{0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA},// L
{0x2260, 0x0E20, 0x0644, 0x0470, YELLOW},// \u53cdL
{0x0C60, 0x2640, 0x0C60, 0x2640, CYAN},// Z
{0x0360, 0x4620, 0x0360, 0x4620, GREEN},// \u53cdZ
{0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}};// T

// \u5b9a\u4e49\u5f53\u524d\u65b9\u5757\u3001\u4e0b\u4e00\u4e2a\u65b9\u5757\u7684\u4fe1\u606f
struct BLOCKINFO
{
byte id;// \u65b9\u5757 ID
char x, y;// \u65b9\u5757\u5728\u6e38\u620f\u533a\u4e2d\u7684\u5750\u6807
byte dir:2;// \u65b9\u5411
}g_CurBlock, g_NextBlock;

// \u5b9a\u4e49\u6e38\u620f\u533a
BYTE g_World[WIDTH][HEIGHT] = {0};



/////////////////////////////////////////////
// \u51fd\u6570\u58f0\u660e
/////////////////////////////////////////////

void Init();// \u521d\u59cb\u5316\u6e38\u620f
void Quit();// \u9000\u51fa\u6e38\u620f
void NewGame();// \u5f00\u59cb\u65b0\u6e38\u620f
void GameOver();// \u7ed3\u675f\u6e38\u620f
CMD GetCmd();// \u83b7\u53d6\u63a7\u5236\u547d\u4ee4
void DispatchCmd(CMD _cmd);// \u5206\u53d1\u63a7\u5236\u547d\u4ee4
void NewBlock();// \u751f\u6210\u65b0\u7684\u65b9\u5757
bool CheckBlock(BLOCKINFO _block);// \u68c0\u6d4b\u6307\u5b9a\u65b9\u5757\u662f\u5426\u53ef\u4ee5\u653e\u4e0b
void DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW);// \u753b\u65b9\u5757
void OnRotate();// \u65cb\u8f6c\u65b9\u5757
void OnLeft();// \u5de6\u79fb\u65b9\u5757
void OnRight();// \u53f3\u79fb\u65b9\u5757
void OnDown();// \u4e0b\u79fb\u65b9\u5757
void OnSink();// \u6c89\u5e95\u65b9\u5757



/////////////////////////////////////////////
// \u51fd\u6570\u5b9a\u4e49
/////////////////////////////////////////////

// \u4e3b\u51fd\u6570
void main()
{
Init();

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

// \u6309\u9000\u51fa\u65f6\uff0c\u663e\u793a\u5bf9\u8bdd\u6846\u54a8\u8be2\u7528\u6237\u662f\u5426\u9000\u51fa
if (c == CMD_QUIT)
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("\u60a8\u8981\u9000\u51fa\u6e38\u620f\u5417\uff1f"), _T("\u63d0\u9192"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
Quit();
}
}
}


// \u521d\u59cb\u5316\u6e38\u620f
void Init()
{
initgraph(640, 480);
srand((unsigned)time(NULL));

// \u663e\u793a\u64cd\u4f5c\u8bf4\u660e
setfont(14, 0, _T("\u5b8b\u4f53"));
outtextxy(20, 330, _T("\u64cd\u4f5c\u8bf4\u660e"));
outtextxy(20, 350, _T("\u4e0a\uff1a\u65cb\u8f6c"));
outtextxy(20, 370, _T("\u5de6\uff1a\u5de6\u79fb"));
outtextxy(20, 390, _T("\u53f3\uff1a\u53f3\u79fb"));
outtextxy(20, 410, _T("\u4e0b\uff1a\u4e0b\u79fb"));
outtextxy(20, 430, _T("\u7a7a\u683c\uff1a\u6c89\u5e95"));
outtextxy(20, 450, _T("ESC\uff1a\u9000\u51fa"));

// \u8bbe\u7f6e\u5750\u6807\u539f\u70b9
setorigin(220, 20);

// \u7ed8\u5236\u6e38\u620f\u533a\u8fb9\u754c
rectangle(-1, -1, WIDTH * SIZE, HEIGHT * SIZE);
rectangle((WIDTH + 1) * SIZE - 1, -1, (WIDTH + 5) * SIZE, 4 * SIZE);

// \u5f00\u59cb\u65b0\u6e38\u620f
NewGame();
}


// \u9000\u51fa\u6e38\u620f
void Quit()
{
closegraph();
exit(0);
}


// \u5f00\u59cb\u65b0\u6e38\u620f
void NewGame()
{
// \u6e05\u7a7a\u6e38\u620f\u533a
setfillstyle(BLACK);
bar(0, 0, WIDTH * SIZE - 1, HEIGHT * SIZE - 1);
ZeroMemory(g_World, WIDTH * HEIGHT);

// \u751f\u6210\u4e0b\u4e00\u4e2a\u65b9\u5757
g_NextBlock.id = rand() % 7;
g_NextBlock.dir = rand() % 4;
g_NextBlock.x = WIDTH + 1;
g_NextBlock.y = HEIGHT - 1;

// \u83b7\u53d6\u65b0\u65b9\u5757
NewBlock();
}


// \u7ed3\u675f\u6e38\u620f
void GameOver()
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("\u6e38\u620f\u7ed3\u675f\u3002\n\u60a8\u60f3\u91cd\u65b0\u6765\u4e00\u5c40\u5417\uff1f"), _T("\u6e38\u620f\u7ed3\u675f"), MB_YESNO | MB_ICONQUESTION) == IDYES)
NewGame();
else
Quit();
}


// \u83b7\u53d6\u63a7\u5236\u547d\u4ee4
DWORD m_oldtime;
CMD GetCmd()
{
// \u83b7\u53d6\u63a7\u5236\u503c
while(true)
{
// \u5982\u679c\u8d85\u65f6\uff0c\u81ea\u52a8\u4e0b\u843d\u4e00\u683c
DWORD newtime = GetTickCount();
if (newtime - m_oldtime >= 500)
{
m_oldtime = newtime;
return CMD_DOWN;
}

// \u5982\u679c\u6709\u6309\u952e\uff0c\u8fd4\u56de\u6309\u952e\u5bf9\u5e94\u7684\u529f\u80fd
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;
}
}
}

// \u5ef6\u65f6 (\u964d\u4f4e CPU \u5360\u7528\u7387)
Sleep(20);
}
}


// \u5206\u53d1\u63a7\u5236\u547d\u4ee4
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;
}
}


// \u751f\u6210\u65b0\u7684\u65b9\u5757
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;

// \u4e0b\u79fb\u65b0\u65b9\u5757\u76f4\u5230\u6709\u5c40\u90e8\u663e\u793a
WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
while((c & 0xF) == 0)
{
g_CurBlock.y--;
c >>= 4;
}

// \u7ed8\u5236\u65b0\u65b9\u5757
DrawBlock(g_CurBlock);

// \u7ed8\u5236\u4e0b\u4e00\u4e2a\u65b9\u5757
setfillstyle(BLACK);
bar((WIDTH + 1) * SIZE, 0, (WIDTH + 5) * SIZE - 1, 4 * SIZE - 1);
DrawBlock(g_NextBlock);

// \u8bbe\u7f6e\u8ba1\u65f6\u5668\uff0c\u7528\u4e8e\u5224\u65ad\u81ea\u52a8\u4e0b\u843d
m_oldtime = GetTickCount();
}


// \u753b\u65b9\u5757
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;
}
}


// \u68c0\u6d4b\u6307\u5b9a\u65b9\u5757\u662f\u5426\u53ef\u4ee5\u653e\u4e0b
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 = WIDTH) || (y < 0))
return false;

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

return true;
}


// \u65cb\u8f6c\u65b9\u5757
void OnRotate()
{
// \u83b7\u53d6\u53ef\u4ee5\u65cb\u8f6c\u7684 x \u504f\u79fb\u91cf
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:
// \u65cb\u8f6c
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.dir++;
g_CurBlock.x += dx;
DrawBlock(g_CurBlock);
}


// \u5de6\u79fb\u65b9\u5757
void OnLeft()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x--;
DrawBlock(g_CurBlock);
}
}


// \u53f3\u79fb\u65b9\u5757
void OnRight()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x++;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x++;
DrawBlock(g_CurBlock);
}
}


// \u4e0b\u79fb\u65b9\u5757
void OnDown()
{
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.y--;
DrawBlock(g_CurBlock);
}
else
OnSink();// \u4e0d\u53ef\u4e0b\u79fb\u65f6\uff0c\u6267\u884c\u201c\u6c89\u5e95\u65b9\u5757\u201d\u64cd\u4f5c
}


// \u6c89\u5e95\u65b9\u5757
void OnSink()
{
int i, x, y;

// \u8fde\u7eed\u4e0b\u79fb\u65b9\u5757
DrawBlock(g_CurBlock, HIDE);
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
while (CheckBlock(tmp))
{
g_CurBlock.y--;
tmp.y--;
}
DrawBlock(g_CurBlock, FIX);

// \u56fa\u5b9a\u65b9\u5757\u5728\u6e38\u620f\u533a
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)
{// \u5982\u679c\u65b9\u5757\u7684\u56fa\u5b9a\u4f4d\u7f6e\u8d85\u51fa\u9ad8\u5ea6\uff0c\u7ed3\u675f\u6e38\u620f
GameOver();
return;
}
else
g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;
}

b <<= 1;
}

// \u68c0\u67e5\u662f\u5426\u9700\u8981\u6d88\u6389\u884c\uff0c\u5e76\u6807\u8bb0
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)
{
// \u5ef6\u65f6 200 \u6beb\u79d2
Sleep(200);

// \u64e6\u6389\u521a\u624d\u6807\u8bb0\u7684\u884c
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);
}
}
}

// \u4ea7\u751f\u65b0\u65b9\u5757
NewBlock();
}

"扫雷"小游戏C代码

#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
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,ge,mo;  /*自定义变量*/
srand((int)time(NULL));  /*启动随机数发生器*/
leb1:  /*选择模式*/
printf("
   请选择模式:
  1.标准  2.自定义
");
scanf("%d",&mo);
if(mo==2)  /*若选择自定义模式,要输入三个参数*/
{do
{t=0; printf("请输入
行数 列数 雷的个数
");
scanf("%d%d%d",&hang,&lie,&ge);
if(hang<2){printf("行数太少
"); t=1;}
if(hang>100){printf("行数太多
");t=1;}
if(lie<2){printf("列数太少
");t=1;}
if(lie>100){printf("列数太多
");t=1;}
if(ge<1){printf("至少要有一个雷
");t=1;}
if(ge>=(hang*lie)){printf("雷太多了
");t=1;}
}while(t==1);
}
else{hang=10,lie=10,ge=10;}  /*否则就是选择了标准模式(默认参数)*/
for(i=1;i<=ge;i=i+1)  /*确定雷的位置*/
{do
{t=0; z[i]=rand( )%(hang*lie);
for(j=1;j<i;j=j+1){if(z[i]==z[j]) t=1;}
}while(t==1);
}
for(i=0;i<=hang+1;i=i+1)  /*初始化a,b,c*/
{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]='+';} }
for(i=1;i<=ge;i=i+1)  /*把雷放入c*/
{x=z[i]/lie+1; y=z[i]%lie+1; c[x][y]='#';}
for(i=1;i<=hang;i=i+1)  /*计算b中数字*/
{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;
}
}
for(i=1;i<=ge;i=i+1)  /*把雷放入b中*/
{x=z[i]/lie+1; y=z[i]%lie+1; b[x][y]='#';}

lei=ge;  /*以下是游戏设计*/
do
{leb2:  /*输出*/
system("cls");printf("



");

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("
  |");
for(i=1;i<=lie;i=i+1){printf("---|");}
printf("
");
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("
   |");
for(j=1;j<=lie;j=j+1){printf("---|");}
printf("
");
}

scanf("%d%c%d",&u,&w,&v);  /*输入*/
u=u+1,v=v+1;
if(w!='#'&&a[u][v]=='@')
goto leb2;
if(w=='#')
{if(a[u][v]=='+'){a[u][v]='@'; lei=lei-1;}
else if(a[u][v]=='@'){a[u][v]='?'; lei=lei+1;}
else if(a[u][v]=='?'){a[u][v]='+';}
goto leb2;
}
a[u][v]=b[u][v];

leb3:  /*打开0区*/
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];
}
}

for(i=1;i<=hang;i=i+1)  /*检测0区*/
{for(j=1;j<=lie;j=j+1)
{if(a[i][j]=='0')
{if(a[i-1][j-1]=='+'||a[i-1][j-1]=='@'||a[i-1][j-1]=='?')t=1;
if(a[i-1][j+1]=='+'||a[i-1][j+1]=='@'||a[i-1][j+1]=='?')t=1;
if(a[i+1][j-1]=='+'||a[i+1][j-1]=='@'||a[i+1][j-1]=='?')t=1;
if(a[i+1][j+1]=='+'||a[i+1][j+1]=='@'||a[i+1][j+1]=='?')t=1;
if(a[i+1][j]=='+'||a[i+1][j]=='@'||a[i+1][j]=='?')t=1;
if(a[i][j+1]=='+'||a[i][j+1]=='@'||a[i][j+1]=='?')t=1;
if(a[i][j-1]=='+'||a[i][j-1]=='@'||a[i][j-1]=='?')t=1;
if(a[i-1][j]=='+'||a[i-1][j]=='@'||a[i-1][j]=='?')t=1;
}
}
}
if(t==1)goto leb3;
}

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]!='@'&&a[i][j]!='?')n=n+1;}
}
}
while(a[u][v]!='#'&&n!=(hang*lie-ge));

for(i=1;i<=ge;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("
  |");
for(i=1;i<=lie;i=i+1){printf("---|");}
printf("
");
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("
   |");
for(j=1;j<=lie;j=j+1) {printf("---|");}
printf("
");
}
if(n==(hang*lie-ge)) printf("你成功了!
");
else printf("    游戏结束!
");
printf("    重玩请输入1
");
t=0;
scanf("%d",&t);
if(t==1)goto leb1;
}

/*注:在DEV c++上运行通过。行号和列号都从0开始,比如要确定第0行第9列不是“雷”,就在0和9中间加入一个字母,可以输入【0a9】三个字符再按回车键。3行7列不是雷,则输入【3a7】回车;第8行第5列是雷,就输入【8#5】回车,9行0列是雷则输入【9#0】并回车*/



  • (瀹屾暣word鐗)绾疌璇█鍐欑殑涓涓皬鍨嬫父鎴 婧愪唬鐮
    绛旓細include<stdio.h>#include<math.h>#include#include<stdlib.h>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,ge,mo; ...
  • 鐢C璇█鎬庢牱缂栧啓涓鍙ヨ瘽
    绛旓細1銆侀鍏堬紝鎵撳紑缂栬瘧鍣紝鏂板缓鏂囦欢銆傚嚭鐜扮殑绌虹櫧澶勬槸鍐欎唬鐮佺殑銆2銆佽緭鍏モ#include<stdio.h>鈥滆繖涓负澶存枃浠躲3銆佺浜岃锛岃緭鍏モ漨ain鈥滐紝鍔犱笂涓瀵光濆皬鎷彿鈥溿4銆佸湪main锛屼笅鏂癸紝杈撳叆涓瀵瑰ぇ鎷彿 {}銆5銆佸湪澶ф嫭鍙烽噷杈撳叆锛屸漰rintf("Hello,Word\n")锛涒濄6銆佽繍琛岀▼搴忓嵆鍙湅鍒拌緭鍏ョ殑璇濅簡銆
  • C璇█鑳藉紑鍙戜粈涔
    绛旓細Windows寰堣佺殑鐗堟湰閮芥槸鐢C璇█鍐欑殑锛屼箣鍚庢敼鐢–++浜嗭紝涓嶈繃C++鏄吋瀹笴璇█鐨勩侺inux鍜孶NIX绯诲垪鐨勬搷浣滅郴缁熷唴鏍稿嚑涔庨兘鏄敤C璇█鍐欑殑锛岃屼笖寰堝杩愯鍦ㄦ澘瀛愪笂鐨勫祵鍏ュ紡鎿嶄綔绯荤粺鍩烘湰閮芥槸鐢–璇█缁撳悎姹囩紪鍐欑殑銆傚鏋滀綘鐪熸兂鍋氫釜鎿嶄綔绯荤粺锛孋璇█缁濆鍙互鑳滀换銆3锛庡鏉傝繍绠楄蒋浠 涔嬫墍浠ヨC璇█閫傚悎杩涜澶嶆潅璁$畻杞欢鐨勫紑...
  • 濡備綍鐢C璇█缂栧啓绋嬪簭,鍒涘缓WORD鏂囨。銆
    绛旓細妤间笂涓や綅鐨勪唬鐮併傚垱寤虹殑doc鑳界敤word姝e父鎵撳紑锛焪ord鏂囨。鏈夎嚜宸辩殑缁撴瀯鍚э紝濡傛灉鐩存帴璇诲啓鏁版嵁鎭愭曚笉琛屽惂锛
  • 鎬庝箞缂栧啓C璇█绋嬪簭,濡:Helloworld鐨?
    绛旓細1銆佺偣鍑荤‘瀹氬嵆鍙紝鍒涘缓鍑轰竴涓猦elloworld.c鐨勫皬绋嬪簭锛岀劧鍚庢垜浠氨鍙互缂栧啓鎴戜滑鐨凥ello World灏忕▼搴忎簡銆傛鏃跺氨闇瑕佹垜浠殑VC++ 6.0鏉ョ紪璇戞绋嬪簭锛岀紪璇戞棤閿欒鎵嶈繍琛屾绋嬪簭锛岀紪璇戞寜閽拰杩愯鎸夐挳濡備笅鍥剧殑绾㈣壊绠ご澶勶細2銆佹垨鑰呭彲浠ョ偣鍑荤粍寤哄伐鍏锋爮涓嬬殑缂栬瘧鑿滃崟椤癸紝鐒跺悗鍐嶇偣鍑绘墽琛岃彍鍗曢」锛屼篃鏈夊揩鎹烽敭锛屾寜Ctrl+F7缂栬瘧...
  • C璇█鍐浠g爜
    绛旓細//姘村钩鏈夐檺锛岀▼搴忓啓寰椾笉绠娲侊紝浣嗕篃鑳戒娇鐢ㄣ#include<stdio.h>int GetEachWordLength(char *, int *, int *);int main(){ char str[] = "how can I help you"; int arr[10];//鐢ㄤ簬瀛樺偍鍚勪釜鍗曡瘝闀垮害鐨勬暟缁勶紝10鍙槸涓殏鏃剁殑澶у皬锛屽湪鑷畾涔夊嚱鏁颁腑浼氬緱鍒皊tr涓崟璇嶆暟 int n, i;/...
  • c璇█鍐绋嬪簭
    绛旓細maxword鏄繑鍥炴渶闀跨殑鍗曡瘝 { int maxlen,i;maxlen=strlen(words[0]);strcpy(maxword,words[0]);for(i=1;i<n;i++){ if (strlen(words[i])>maxlen){ maxlen=strlen(words[i]);strcpy(maxword,words[i]);} } } int main(){ char s[1000],a[100][30],c,b[30];int i,j,ct...
  • 鐢C璇█缂栧啓鈥滆儗鍗曡瘝 绋嬪簭鈥
    绛旓細scanf("%c%c",&ch,&chioch);if(ch=='y'||ch=='Y') exit(0);} default :printf("浣犺緭鍏ヤ簡閿欒鐨勬搷浣滐紝鏃犳硶鎵ц锛侊紒锛");exit(0);} } } void tianjia(struct word str[100],int &count) //寰璇嶅簱涓坊鍔犺瘝缁 { char ch;do{ printf("褰曞叆璇嶅簱锛侊紒锛乗n");printf("璇疯緭鍏...
  • C璇█銆傚湪灞忓箷涓婅緭鍑篽ello word
    绛旓細浠ヤ笅涓虹▼搴忎唬鐮佸強鎵ц缁撴灉锛歩nclude <stdio.h> include <windows.h> int main(){printf("hello world!\n");system("pause");return 0;} 鎵ц缁撴灉锛
  • 绾疌璇█瀹炵幇鍥惧儚澶勭悊?
    绛旓細define ONE 255 define ZERO 0 / typedef struct tagBITMAPFILEHEADER { // bmfh WORD bfType;DWORD bfSize;WORD bfReserved1;WORD bfReserved2;DWORD bfOffBits;} BITMAPFILEHEADER;typedef struct tagBITMAPINFOHEADER{ // bmih DWORD biSize;LONG biWidth;LONG biHeight;WORD ...
  • 扩展阅读:论文ai生成免费网站 ... c语言代码复制在word文档 ... c语言自动生成器 ... 免费毕业论文ai生成 ... 论文电子版word格式 ... 论文模板word电子版 ... 代码hello world ... c语言必背100代码 ... 论文下载免费网站 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网