求C语言 小游戏设计

作者&投稿:强钧 (若有异议请与网页底部的电邮联系)
求一个用C语言编写的小游戏代码~

#include
#include
#include



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

#defineWIDTH10// 游戏区宽度
#defineHEIGHT22// 游戏区高度
#defineSIZE20// 每个游戏区单位的实际像素

// 定义操作类型
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("游戏结束。
您想重新来一局吗?"), _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 = 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();
}


我写了个贪吃蛇,有单人版,也有双人版

这是单人版:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
#include <malloc.h>
int food[2];
int feng;
int dengji=3;
int speed=150;
struct snake
{
 int x,y,life;
 struct snake *next;
};
void welcome()
{
 system("MODE con: COLS=79 LINES=24");
 system("color 8F");
 printf("欢迎来到贪吃蛇的世界
");
 printf("      By HB
");
 printf("↑ ↓ ← →
");
 printf("上 下 左 右
");
 printf("食物为:★
");
 printf("按空格暂停
");
 printf("按Z(大写)切换等级
");
 printf("等级从5级到1级是从高到低
");
 printf("注意:每次增加的分数=当前等级*10
");
 printf("按任意键开始游戏!
");
 getch();
 system("cls");
}
void gotoxy(int x, int y)
{
 COORD coord;
 coord.X = x;coord.Y = y;
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void makefood(struct snake*p)
{
 int fx;
 struct snake*p1=p;
    srand(time(NULL));
 fx=rand()%77+2;
 if(fx%2==0)
 {
        fx--;
 }
 food[0]=fx;
 food[1]=rand()%22+1;
    while(p!=NULL)
    {
  if(p->x==food[0]&&p->y==food[1])
  {
   makefood(p1);
     }
        p=p->next;
 }
}
void drawmap(struct snake* p)
{
 system("cls");
 printf("你的分数为:%d分    当前等级为:%d级",feng,dengji);
    gotoxy(p->x,p->y);
 printf("◇");
    p=p->next; 
 while(p!=NULL)
 {
  gotoxy(p->x,p->y);
  printf("※");
  p=p->next;
 }
    gotoxy(food[0],food[1]);
 printf("★");
}
struct snake *mvsnake(struct snake *p,int z)
{
 struct snake *p2,*p3;
 int x,y;
 x=p->x;
 y=p->y;
    switch(z)
    {
  case 1:
  {
   x-=2; 
   break;
        }
  case 2:
  {
   x+=2;
   break;
  }
  case 3:
  {
   y--;
   break;
  }
        case 4:
  {
   y++;
   break;
  }
    }
    p2=(struct snake*)malloc(sizeof(struct snake));
 p2->x=x;
 p2->y=y;
    p2->life=1;
 p2->next=p;
    
 if(p2->x>=79||p2->y>=24||p2->x<0||p2->y<1)
 {
  p2->life=0;
 }
 p3=p;
 while(p3!=NULL)
 {
  if(p2->x==p3->x&&p2->y==p3->y)
  {
   p2->life=0;
  }
  p3=p3->next;
 }
 if(p2->x==food[0]&&p2->y==food[1])
 {
  feng+=dengji*10;
  makefood(p2);
 }
 else
 {
  while(p->next->next!=NULL)
  {
   p=p->next;
  }
  p3=p->next;
  p->next=NULL;
  free(p3);
 }
 return p2;
}
int scan(int z)
{
    char ch;
 if(kbhit()){
   ch=getch();
   switch(ch)
   {
    
    case 75:if(z!=2)z=1;break;
    case 77:if(z!=1)z=2;break;
    case 72:if(z!=4)z=3;break;
    case 80:if(z!=3)z=4;break;
    case 32:z=5;break;
    case 'Z':speed-=50;
             dengji++;
             if(speed==0){speed=250;dengji=1;}
       break;
    default :break;
   }
   if(ch==27)z=27;
   fflush(stdin);
  }
 return z;
}
int main(int argc, char *argv[])
{
 welcome();
 loop:system("cls");
    struct snake *snakenext;
 struct snake *snk=(struct snake*)malloc(sizeof(struct snake));
 snk->x=15;
 snk->y=15;
    snk->life=1;
 snk->next=(struct snake*)malloc(sizeof(struct snake));
 snk->next->x=14;
 snk->next->y=snk->y;
 snk->next->next=(struct snake*)malloc(sizeof(struct snake));
 snk->next->next->x=13;
 snk->next->next->y=snk->y;
 snk->next->next->next=NULL;
 int z=2;
 
 makefood(snk);
 while(1)
 {
  int temp_z=z;      
  z=scan(z); 
  if(z==27)exit(0);      
  if(z==5)
  { 
   gotoxy(30,15);             
   printf("暂停");   
   getch();z=temp_z;
  } 
  snk=mvsnake(snk,z);
     if(snk->life==0)break;
  drawmap(snk);
  Sleep(speed); 
 }
    system("cls");
 gotoxy(25,11);
 printf("GAME OVER,你的最终分数为:%d分
",feng);
 gotoxy(25,12);
 printf("按空格重新开始,按其他键结束!
");
 while(snk!=NULL)
 {
  snakenext=snk->next;
  free(snk);
  snk=snakenext;
 }
 Sleep(500);
 char cha;
 cha=getch();
 if(cha==32)
 {
  goto loop;
 }
    return 0;
}

这是双人版:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
#include <malloc.h>
int food[2];
int feng1,feng2;
int speed=150;
int dengji=3;
int chi;
struct snake
{
 int x,y,life;
 struct snake *next;
};
void welcome()
{
 system("MODE con: COLS=79 LINES=24");
 system("color 8F");
 printf("欢迎来到双人贪吃蛇游戏
");
 printf("      By HB
");
 printf("玩家1:□□◇
");
 printf("W S A D(大写)
");
 printf("上 下 左 右
");
 printf("玩家2:■■◆
");
 printf("↑ ↓ ← →
");
 printf("上 下 左 右
");
 printf("食物为:★
");
 printf("按空格暂停
");
 printf("按Z(大写)切换等级
");
 printf("等级从5级到1级是从高到低
");
 printf("注意:每次增加的分数=当前等级*10
");
 printf("按任意键开始游戏!
");
 getch();
 system("cls");
}
void gotoxy(int x, int y)
{
 COORD coord;
 coord.X = x;coord.Y = y;
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void makefood(struct snake *p,struct snake *p2)
{
 int fx;
 struct snake*p1=p;
 struct snake*p3=p2;
    srand(time(NULL));
 fx=rand()%77+2;
 if(fx%2==0)
 {
        fx--;
 }
 food[0]=fx;
 food[1]=rand()%22+1;
    while(p!=NULL&&p2!=NULL)
 {
  if((p->x==food[0]&&p->y==food[1])||(p2->x==food[0]&&p2->y==food[1]))
  {
   makefood(p1,p3);
  }
        p=p->next;
  p2=p2->next;
 }
}
void drawmap(struct snake *p,struct snake *p2)
{
 system("cls");
    printf("玩家1的分数为:%d分         当前等级为:%d级          玩家2的分数为:%d分",feng1,dengji,feng2);
    gotoxy(p->x,p->y);
 printf("◇");
    p=p->next; 
 gotoxy(p2->x,p2->y);
 printf("◆");
    p2=p2->next; 
 while(p!=NULL)
 {
  gotoxy(p->x,p->y);
  printf("□");
  p=p->next;
 }
    while(p2!=NULL)
 {
  gotoxy(p2->x,p2->y);
  printf("■");
  p2=p2->next;
 }
    gotoxy(food[0],food[1]);
 printf("★");
}
struct snake *mvsnake(struct snake *p,struct snake *p4,int z,int i)
{
 struct snake *p2,*p3;
 int x,y;
 x=p->x;
 y=p->y;
    switch(z)
    {
  case 1:
  {
   x-=2; 
   break;
        }
  case 2:
  {
   x+=2;
   break;
  }
  case 3:
  {
   y--;
   break;
  }
        case 4:
  {
   y++;
   break;
  }
    }
    p2=(struct snake*)malloc(sizeof(struct snake));
 p2->x=x;
 p2->y=y;
    p2->life=1;
 p2->next=p;
    
 if(p2->x>=79||p2->y>=24||p2->x<0||p2->y<1)
 {
  p2->life=0;
 }
 p3=p;
 while(p3!=NULL)
 {
  if(p2->x==p3->x&&p2->y==p3->y)
  {
   p2->life=0;
  }
  p3=p3->next;
 }
    
 if(p2->x==food[0]&&p2->y==food[1])
 {
  if(i==1)
  {
   feng1+=dengji*10;
  }
  else if(i==2)
  {
   feng2+=dengji*10;
  }
  makefood(p2,p4);
 }
 else
 {
  while(p->next->next!=NULL)
  {
   p=p->next;
  }
  p3=p->next;
  p->next=NULL;
  free(p3);
 }
 return p2;
}
int scan(int z)
{
    char ch;
 if(kbhit()){
   ch=getch();
   switch(ch)
   {
    
    case 75:
    case 'A':if(z!=2)z=1;break;
    case 77:
    case 'D':if(z!=1)z=2;break;
    case 72:
    case 'W':if(z!=4)z=3;break;
    case 80:
    case 'S':if(z!=3)z=4;break;
    case 32:z=5;break;
    case 'Z':speed-=50;
             dengji++;
             if(speed==0){speed=250;dengji=1;}
       break;
    default :break;
   }
   if(ch==27)z=27;
  }
 return z;
}
int main(int argc, char *argv[])
{
 welcome();
 loop:system("cls");
    struct snake *snakenext;
 struct snake *snk=(struct snake*)malloc(sizeof(struct snake));
 snk->x=15;
 snk->y=15;
    snk->life=1;
 snk->next=(struct snake*)malloc(sizeof(struct snake));
 snk->next->x=14;
 snk->next->y=snk->y;
 snk->next->next=(struct snake*)malloc(sizeof(struct snake));
 snk->next->next->x=13;
 snk->next->next->y=snk->y;
 snk->next->next->next=NULL;
 struct snake *snake2next;
 struct snake *snk2=(struct snake*)malloc(sizeof(struct snake));
 snk2->x=17;
 snk2->y=10;
    snk2->life=1;
 snk2->next=(struct snake*)malloc(sizeof(struct snake));
 snk2->next->x=16;
 snk2->next->y=snk2->y;
 snk2->next->next=(struct snake*)malloc(sizeof(struct snake));
 snk2->next->next->x=15;
 snk2->next->next->y=snk2->y;
 snk2->next->next->next=NULL;
 int z=2;
 int k=2;
    makefood(snk,snk2);
 
 while(1)
 {
  int temp_z=z;      
  z=scan(z);
  k=scan(k);
  if(z==27)exit(0);      
  if(z==5)
  { 
   gotoxy(30,15);             
   printf("暂停");   
   getch();z=temp_z;
  } 
  snk=mvsnake(snk,snk2,z,1);
        snk2=mvsnake(snk2,snk,k,2);
  if(snk->life==0||snk2->life==0)break;
     drawmap(snk,snk2);
  Sleep(speed); 
 }
    system("cls");
 gotoxy(15,11);
 printf("GAME OVER,玩家1的分数为:%d分,玩家2的分数为:%d分
",feng1,feng2);
 gotoxy(33,12);
 if(feng1>feng2)
 {
  printf("玩家1赢了!
");
 }
 else if(feng2>feng1)
 {
  printf("玩家2赢了!
");
 }
 else
 {
  printf("你们打成了平手!
");
 }
    gotoxy(25,13);
 printf("按空格重新开始,按其他键结束!
");
 while(snk!=NULL)
 {
  snakenext=snk->next;
  free(snk);
  snk=snakenext;
 }
 while(snk2!=NULL)
 {
  snake2next=snk2->next;
  free(snk2);
  snk2=snake2next;
 }
 Sleep(500);
 char cha;
 cha=getch();
 if(cha==32)
 {
  goto loop;
 }
    return 0;
}


怎么发给你,游戏虽然小,只是几kb就几千行了

百度一下有的事呢


长阳土家族自治县19849263002: 求助,用C语言做一个小游戏(不要太复杂),最最最基础的C语言就可以,并赋予代码,谢谢! -
钊澜复方: 猜数字 超简单 去掉说明文字,也就十几行 简单说明见注释#include <stdio.h>#include <stdlib.h>#include<time.h> int main() { int i; int a; int t; printf("欢迎玩猜数字小游戏!\n"); printf("玩法介绍:\n"); printf("每次游戏会设置一个数...

长阳土家族自治县19849263002: C语言猜字游戏设计 -
钊澜复方: #include <stdio.h> void main() { int s=5,j; int i,a[4]; printf(" 猜数游戏,您有五次机会.\n\n\n\n"); for(i=0;i<5;i++) { printf("请输入第%d个数:",i+1); scanf("%d",&a[i]); if(a[i]==s) { printf("猜对了!\n"); j=0; break; } else{ if(a[i]>s) { printf("...

长阳土家族自治县19849263002: 求助,用C语言做一个小游戏(什么游戏都行不要太复杂),最最最基础的C语言就可以,并赋予代码,求助大神 -
钊澜复方: 如果不需要图形界面,我倒是有个非常的简单的游戏,请复制中间的代码,建议你看下最后的注释#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h> int main(void) { int num[6], num1[6], num2[6]; int a, b; int number, number...

长阳土家族自治县19849263002: 设计一个猜字游戏的C语言程序 -
钊澜复方: #include<stdio.h>#include<stdlib.h>#include<time.h> main() { int num,n; time_t t; srand((unsigned)time(&t)); num = rand(); while(1) { printf("please input a number:") scanf("%d",&n); if(n>num) { printf("sry, your number is bigger than mine.\n"...

长阳土家族自治县19849263002: 教你如何使用C语言编写简单小游戏 -
钊澜复方: 编写程序,实现如下表所示的5-魔方阵.17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 5-魔方阵 问题分析 所谓“n-魔方阵”,指的是使用1〜n2共n2个自然数排列成一个n*n的方阵,其中n为奇数;该方阵的每行、每列及对...

长阳土家族自治县19849263002: 猜数游戏C语言程序设计 -
钊澜复方: 这道题不难,只要知道怎样用c语言生成1~100的随机数就很好办了!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45附代码如下! #include<stdio.h> #include <...

长阳土家族自治县19849263002: 怎样用C语言编写一个小游戏? -
钊澜复方: 写小游戏用面向对象语言写吧.C写起来很麻烦的.比如C#、C++等的.可以选择其他引擎,比如Unity、UE4等

长阳土家族自治县19849263002: 求设计一个C语言猜数字游戏,一定要是C语言 -
钊澜复方: 把下面的cout是输出. 用C语言的输出就行. #include <time.h> #include <stdlib.h> int main() { int x; cout<<"输入任意数字开始."<<endl; //使用 输入是否为 数字来判断是否继续猜 scanf("%d",&x); while(x) { srand((int)time(0)); int m = rand()...

长阳土家族自治县19849263002: 急!!!求C语言课程设计之打字游戏代码! -
钊澜复方: 给你个.因分少就不改动了, 这个是给别的朋友定过的. 只有练习数字和字母.而且可以调速度,并配着简单的动画哦.如觉得好要加功能, 加我百度好友,再加分.哈哈.#include<time.h> #include<stdlib.h> #include<graphics.h> #include<conio.h> ...

长阳土家族自治县19849263002: 用C语言设计小游戏的程序??急!!! -
钊澜复方: 用c++实现的"贪吃蛇"游戏源码 // greedsnake.cpp #include <bios.h> #include <conio.h> #include <dos.h> #include <graphics.h> #include <stdlib.h> #include <time.h> #include "conf.h" typedef struct node { int x,y; struct node *next; }Node; ...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网