用C语言编写的小游戏代码是什么? 求一个用C语言编写的小游戏代码

\u7528C\u8bed\u8a00\u7f16\u5199\u7684\u5c0f\u6e38\u620f\u4ee3\u7801\u662f\u4ec0\u4e48\uff1f

\u201c\u731c\u6570\u5b57\u5c0f\u6e38\u620f\u201d\uff0c\u6bcf\u4e2a\u6570\u5b57\u540e\u6309\u7a7a\u683c\uff0c\u6700\u540e\u6309\u56de\u8f66\u786e\u8ba4
#include
#include
#include
int a[4],b[4];
int count=0; //\u8ba1\u7b97\u731c\u6d4b\u6b21\u6570
void csh( ); //\u521d\u59cb\u5316
void start( ); //\u5f00\u59cb\u6e38\u620f
int main( )
{ csh( );
start( );
}
void csh( ) //\u521d\u59cb\u5316
{ printf("\n\n \u731c \u6570 \u5b57 \u5c0f \u6e38 \u620f\n\n");
printf(\u201c \u731c\u56db\u4e2a\u6570\u5b57\uff0c\u5982\u6570\u5b57\u4e0e\u987a\u5e8f\u90fd\u6b63\u786e\u8bb0\u4e3aA\uff0c\u6570\u5b57\u6b63\u786e\u4f4d\u7f6e\u4e0d\u5bf9\u8bb0\u4e3aB.\n\u201d);
}
void start( ) //\u5f00\u59cb\u6e38\u620f
{int m,n; //m\u662f\u5b8c\u5168\u731c\u5bf9\u7684\u4e2a\u6570,n\u662f\u987a\u5e8f\u4e0d\u5bf9\u7684\u4e2a\u6570
while(1)
{srand((unsigned)time(NULL)); //\u521d\u59cb\u5316\u968f\u673a\u6570\u53d1\u751f\u5668srand( )
while(1) { for(int i=0;i<4;i++) a[i]=rand( )%10; //rand( )\u51fd\u6570\u6bcf\u6b21\u968f\u673a\u4ea7\u751f\u4e00\u4e2a0-9\u7684\u6570
if( (a[3]!=a[2]&&a[3]!=a[1]&&a[3]!=a[0])&&
(a[2]!=a[1]&&a[2]!=a[0])&&a[1]!=a[0] ) break; } //4\u4e2a\u968f\u673a\u6570\u5404\u81ea\u4e0d\u76f8\u7b49
printf(" \u8bf7\u4f9d\u6b21\u8f93\u51654\u4e2a\u4e00\u4f4d\u6574\u6570:\n\n ");
while(1)
{for(int i=0;i<4;i++) scanf(\u201c%d\u201d,&b[i]);
printf(" \u4f60\u8f93\u5165\u7684\u662f:%d %d %d %d ",b[0],b[1],b[2],b[3]);
m=0;n=0;
for(int i=0;i<4;i++)
{for(int j=0;j<4;j++)
{ if(b[i]==a[j]&&i==j)m=m+1; if(b[i]==a[j]&&i!=j)n=n+1; }
}
count=count+1;
printf(" %dA %dB \u4f60\u8bd5\u4e86%d\u6b21\n ",m,n,count);
if(m==4)break;
if(count==8){ count=0; break; }
}
printf("\n");
if(m==4)printf(" \u4f60\u731c\u5bf9\u4e86(^-^)\uff01 \u5c31\u662f\uff1a%d %d %d %d\n",a[0],a[1],a[2],a[3]);
else printf(" \u4f60\u8f93\u4e86(T-T)\uff01\u54c8\u54c8\uff01\u5e94\u8be5\u662f:%d %d %d %d\n",a[0],a[1],a[2],a[3]);
int z;
printf(" \uff08\u8981\u7ee7\u7eed\u5417\uff1f1\u62160\uff09\n ");
scanf(\u201c%d\u201d,&z);
if(z==0) break;
}
}

#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】并回车*/



/*贪吃蛇*/

#include<stdio.h>

#include<time.h>

#include<conio.h>

#include<stdlib.h>

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++)

C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。



  • 鐢–璇█缂栧啓鐨勫皬娓告垙浠g爜鏄粈涔?
    绛旓細"鎵浄"灏忔父鎴廋浠g爜 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 ...
  • 姹備竴涓鐢–璇█缂栧啓鐨勫皬娓告垙浠g爜
    绛旓細c = GetCmd(); DispatchCmd(c); // 鎸夐鍑烘椂,鏄剧ず瀵硅瘽妗嗗挩璇㈢敤鎴锋槸鍚﹂鍑 if (c == CMD_QUIT) { HWND wnd = GetHWnd(); if (MessageBox(wnd, _T("鎮ㄨ閫鍑娓告垙鍚?"), _T("鎻愰啋"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK) Quit(); } }}// 鍒濆鍖栨父鎴弙oid Init(){ initgraph(640, 4...
  • 鐢–璇█缂栧啓鐨勫皬娓告垙浠g爜鏄粈涔?
    绛旓細/*涔熶笉鐭ラ亾浣鏄粈涔绾у埆鐨,鎴戞槸涓涓柊鎵,鍒氭帴瑙缂栫▼璇█,浠ヤ笅鏄垜鑷繁鍙樺緱涓涓皬绋嬪簭,鍦ㄦ墍鏈c璇█鐨勭紪璇戝櫒(vc++6.0銆乼urbo???)涓婇兘鑳借繍琛,浣犺繕鍙互杩涗竴姝ユ敼杩涖傝繖鏄竴涓被浼艰椽鍚冭泧鐨勫皬娓告垙銆傜浣犲ソ杩*/\x0d\x0a/*璐悆铔*/\x0d\x0a#include\x0d\x0a#include\x0d\x0a#include\x0d\x0a#includ...
  • C璇█缂栧啓鐚滄暟瀛娓告垙
    绛旓細//#include <iostream> unsigned char Num[4] = {0},getNum[4] = {0x20,0x20,0x20,0x20};void help(void){ char i =0,j = 0;for(i =0;i<4;i++){ for(j = 0;j<4;j++)if(Num[j] == getNum[i]){ if(i==j)printf("%dth is correct!\r\n",i);else { printf...
  • 濡備綍鐢╟璇█缂栧啓涓涓灏忔父鎴?
    绛旓細涓夈佸弬鑰浠g爜锛歩nclude <stdio.h>void main(){ double a,b; double L,S; scanf("%lf%lf",&a,&b);//杈撳叆瀹藉拰楂樸 L=2*(a+b);//璁$畻鍛ㄩ暱銆 S=a*b;//璁$畻闈㈢Н銆 printf("闈㈢Н=%lf, 鍛ㄩ暱=%lf\n", S, L);//杈撳嚭缁撴灉銆倉鍥涖佹敞鎰忎簨椤癸細鍥犱负娌℃湁闄愬埗杈撳叆涓...
  • 濡備綍浣跨敤C璇█缂栧啓绠鍗灏忔父鎴?
    绛旓細C璇█鏄璁$畻鏈轰笓涓氶兘瑕佸涔犵殑涓闂ㄥ熀纭瀛︾銆備竴鑸潵璇,鏄瘮杈冩灟鐕ョ殑.閭d箞,鎴戜滑鑳戒笉鑳介氳繃缂栦竴浜灏忔父鎴鏉ユ彁楂樺畠鐨勮叮鍛虫у憿?杩欐牱瀛︿範绋嬪簭璁捐,灏变笉浼氭槸涓浠惰壈鑻 ,鏋嚗鐨勪簨,瀹冨彉寰楄薄鐢佃剳娓告垙涓鏍峰厖婊″ソ濂,瀵屾湁涔愯叮銆備緥濡2048杩欐娓告垙锛氭柟娉/姝ラ锛歩nclude<stdio.h> include<stdlib.h> include include<con...
  • 鎬庢牱鐢–璇█缂栧啓涓涓灏忔父鎴?
    绛旓細鈥滆椽鍚冭泧鈥C浠g爜锛歩nclude <stdio.h> include <stdlib.h> include <conio.h> include include <Windows.h> define W 78 //娓告垙妗嗙殑瀹,x杞 define H 26 //娓告垙妗嗙殑楂,y杞 int dir=3; //鏂瑰悜鍙橀噺锛屽垵鍊3琛ㄧず鍚戔滃乏鈥漣nt Flag=0; //鍚冧簡椋熺墿鐨勬爣蹇(1鏄0鍚)int score=0; ...
  • 鏁欎綘濡備綍浣跨敤C璇█缂栧啓绠鍗灏忔父鎴
    绛旓細4, 鍦ㄨ糠瀹腑鎺㈢储 灏忔椂渚,鎴戝父鍦ㄤ竴浜涘皬浜轰功鍜屾潅蹇椾笂鐪嬭涓浜涜糠瀹鐨勬父鎴,闈炲父鍠滄鐜,杩樺父鍒颁竴浜涗功涓婃壘杩峰鐜╁憿.濂界殑,鐜板湪鎴戜滑鐢–璇█鏉ョ紪涓糠瀹殑娓告垙,閲嶆俯涓涓嬬骞寸殑涔愯叮. 棣栧厛,鎴戜滑瀹氫箟涓涓簩缁存暟缁刴ap,鐢ㄥ畠鏉ヤ繚瀛樿糠瀹殑鍦板浘,鍏朵腑map[x][y] == '#'琛ㄧず鍦(x,y)鍧愭爣涓婄殑鐐规槸澧欏.DrawMap鍑芥暟...
  • 鐢–++缂栧啓鐨勫皬娓告垙婧愪唬鐮
    绛旓細浜斿瓙妫嬬殑浠g爜锛歩nclude<iostream> include<stdio.h> include<stdlib.h> include using namespace std;const int N=15; //15*15鐨勬鐩 const char ChessBoardflag = ' '; //妫嬬洏鏍囧織 const char flag1='o'; //鐜╁1鎴栫數鑴戠殑妫嬪瓙鏍囧織 const char flag2='X'; //鐜╁2鐨勬瀛...
  • 姹鐢–璇█缂栧啓灏忔父鎴忕殑婧愪唬鐮,涓嶇浠涔堝皬娓告垙,婧愪唬鐮佺畝鍗曚簺,閫傚悎鍒濆鑰...
    绛旓細{ int a,b,c,d,s,x,t,i,n,k;s=200,k=1000;x=t=i=1,a=b=c=d=n=0;srand((int)time(0));printf(" 21鐐娓告垙 鈽呮父鎴忚鍒: \n 娓告垙寮濮嬪悗绯荤粺灏嗛殢鏈轰骇鐢1鍒10涔嬮棿鐨勬暟骞剁疮鍔.1.鍦ㄧ偣鏁颁笉澶т簬21鏃讹紝鐐规暟澶ц呰耽,鐐规暟鐩哥瓑绠楀钩灞;2.鑻ヤ竴鏂圭偣鏁板ぇ浜21锛屼竴鏂圭偣鏁板皬浜21锛屽皬浜21...
  • 扩展阅读:c++入门程序代码 ... 输入一串代码玩小游戏 ... 如何自己编程做游戏 ... 新手好玩的c语言代码 ... 小游戏代码可直接玩 ... 100个小游戏代码 ... 免费复制100个代码 ... c语言代码生成器 ... c++必背入门代码 ...

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