精华内容
下载资源
问答
  • C语言简易小游戏【flappy bird】#include #include #include#include "interface.h"char interf[M][N] = {{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,...

    C语言简易版小游戏【flappy bird】

    #include

    #include

    #include

    #include "interface.h"

    char interf[M][N] = {{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32 },

    { 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32 },

    { 38,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 },

    { 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

    { 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 }, };

    //初始界面矩阵,ASCII码中“ ”是32,“&”是38表示小鸟,“#”是35用来画柱子

    int num = 0;//用于计数输出并排两列黑柱子同一位置

    int black;//黑方块位置

    int p= M/2 ;//小鸟初始位置

    int score = 0;//分数

    /*初始化界面*/

    void InitialInterface(void)

    {

    printf("\n          作者:xhyang,博客地址:http://blog.csdn.net/weixin_39449570\n");

    printf("            按\"w\"使小鸟跳起来,别落地,顺利穿过尽可能多的柱子!\n");

    for (int i = 0; i < M; i++)

    {

    printf("            ");

    for (int j = 0; j < N; j++)

    {

    printf("%c", interf[i][j]);

    }

    printf("\n");

    }

    }

    /*更新界面各个柱子*/

    void newinterface(void)

    {

    if (interf[0][1] == 35 && num==0)//当矩阵第二列为黑色方块时,计算出下一次黑柱子上半部分的位置

    {

    black = 5 + rand() % 5;

    num = 2;//黑柱子是两列#组成,第二列与第一列位置一样,用num保证两列位置一致

    }

    for (int i = 0; i < M; i++)

    {

    for (int j = 0; j < N - 1; j++)

    {

    interf[i][j] = interf[i][j + 1];

    }

    if (interf[0][0] == 35 && (i < black || i>(black + 5)))//此时上面的第二列变成了第一列,更新下一个黑柱子,有了黑柱子上半部分位置+5即是下半部分的起始位置

    {

    interf[i][N-1] = 35;

    }

    else

    {

    interf[i][N-1] = 32;

    }

    }

    if (num > 0)

    num--;

    }

    /*更新小鸟位置*/

    void birdmove(void)

    {

    for (int a = 0; a < 3; a++)

    {

    if (a  == 2 && p > 0)//减缓鸟的速度,使按键上跳速度是下落的4倍

    {

    p = p + 1;

    }

    if (_kbhit())

    {

    if (_getch() == 'w' || _getch() == 'W')

    {

    p = p - 3;

    }

    }

    }

    }

    /*计分*/

    void scoring(void)

    {

    if (p > 20 || interf[p][0] == 35)

    {

    system("cls");

    printf("\n\n            游戏结束!\n\n");

    printf("            最终得分:%d\n\n\n", score);

    system("pause");

    }

    if (interf[0][0] == 35 && interf[0][1] == 32 )

    score++;

    }

    /*重画界面*/

    void draw(void)

    {

    system("cls");

    printf("\n          作者:xhyang,博客地址:http://blog.csdn.net/weixin_39449570\n");

    printf("            按\"w\"使小鸟跳起来,别落地,顺利穿过尽可能多的柱子!\n");

    for (int i = 0; i < M; i++)

    {

    printf("            ");

    for (int j = 0; j < N; j++)

    {

    if (i == p && j == 0 && interf[p][0] != 35)

    printf("%c", 38);

    else

    printf("%c", interf[i][j]);

    }

    printf("\n");

    }

    printf("            得分:%d \n", score);

    }

    本文由IT教学网整理发布,转载请注明出处:http://www.itjx.com/ziyuan/yuanma/553.html

    展开全文
  • C语言小游戏源码

    2021-05-19 12:45:48
    在此提供C语言小游戏源码,包括扫雷游戏,贪吃蛇游戏,时钟等。运行时只要把红色部分改为自己电脑上TC目录的BGI分目录即可。//扫雷游戏#include #include #include #define LEFTPRESS 0xff01#define LEFTCLICK 0xff...

    在此提供C语言小游戏源码,包括扫雷游戏,贪吃蛇游戏,时钟等。

    运行时只要把红色部分改为自己电脑上TC目录的BGI分目录即可。

    //扫雷游戏

    #include

    #include

    #include

    #define LEFTPRESS 0xff01

    #define LEFTCLICK 0xff10

    #define LEFTDRAG 0xff19

    #define MOUSEMOVE 0xff08

    struct

    {

    int num;

    int roundnum;

    int flag;

    }Mine[10][10];

    int gameAGAIN=0;

    int gamePLAY=0;

    int mineNUM;

    char randmineNUM[3];

    int Keystate;

    int MouseExist;

    int MouseButton;

    int MouseX;

    int MouseY;

    void Init(void);

    void MouseOn(void);

    void MouseOff(void);

    void MouseSetXY(int,int);

    int LeftPress(void);

    int RightPress(void);

    void MouseGetXY(void);

    void Control(void);

    void GameBegain(void);

    void DrawSmile(void);

    void DrawRedflag(int,int);

    void DrawEmpty(int,int,int,int);

    void GameOver(void);

    void GameWin(void);

    int MineStatistics(int,int);

    int ShowWhite(int,int);

    void GamePlay(void);

    void Close(void);

    void main(void)

    {

    Init();

    Control();

    Close();

    }

    void Init(void)

    {

    int gd=DETECT,gm;

    initgraph(&gd,&gm,"D:\\tc20\\BGI");

    }

    void Close(void)

    {

    closegraph();

    }

    void MouseOn(void)

    {

    _AX=0x01;

    geninterrupt(0x33);

    }

    void MouseOff(void)

    {

    _AX=0x02;

    geninterrupt(0x33);

    }

    void MouseSetXY(int x,int y)

    {

    _CX=x;

    _DX=y;

    _AX=0x04;

    geninterrupt(0x33);

    }

    int LeftPress(void)

    {

    _AX=0x03;

    geninterrupt(0x33);

    return(_BX&1);

    }

    int RightPress(void)

    {

    _AX=0x03;

    geninterrupt(0x33);

    return(_BX&2);

    }

    void MouseGetXY(void)

    {

    _AX=0x03;

    geninterrupt(0x33);

    MouseX=_CX;

    MouseY=_DX;

    }

    void Control(void)

    {

    int gameFLAG=1;

    while(1)

    {

    if(gameFLAG)

    {

    GameBegain();

    GamePlay();

    if(gameAGAIN==1)

    {

    gameAGAIN=0;

    continue;

    }

    }

    MouseOn();

    gameFLAG=0;

    if(LeftPress())

    {

    MouseGetXY();

    if(MouseX>280&&MouseX<300&&MouseY>65&&MouseY<85)

    {

    gameFLAG=1;

    continue;

    }

    }

    if(kbhit())

    break;

    }

    MouseOff();

    }

    void DrawSmile(void)

    {

    setfillstyle(SOLID_FILL,YELLOW);

    fillellipse(290,75,10,10);

    setcolor(YELLOW);

    setfillstyle(SOLID_FILL,BLACK);

    fillellipse(285,75,2,2);

    fillellipse(295,75,2,2);

    setcolor(BLACK);

    bar(287,80,293,81);

    }

    void DrawRedflag(int i,int j)

    {

    setcolor(7);

    setfillstyle(SOLID_FILL,RED);

    bar(198+j*20,95+i*20,198+j*20+5,95+i*20+5);

    setcolor(BLACK);

    line(198+j*20,95+i*20,198+j*20,95+i*20+10);

    }

    void DrawEmpty(int i,int j,int mode,int color)

    {

    setcolor(color);

    setfillstyle(SOLID_FILL,color);

    if(mode==0)

    bar(200+j*20-8,100+i*20-8,200+j*20+8,100+i*20+8);

    else

    if(mode==1)

    bar(200+j*20-7,100+i*20-7,200+j*20+7,100+i*20+7);

    }

    void GameBegain(void)

    {

    int i,j;

    cleardevice();

    if(gamePLAY!=1)

    {

    MouseSetXY(290,70);

    MouseX=290;

    MouseY=70;

    }

    gamePLAY=1;

    mineNUM=0;

    setfillstyle(SOLID_FILL,7);

    bar(190,60,390,290);

    for(i=0;i<10;i++)

    for(j=0;j<10;j++)

    DrawEmpty(i,j,0,8);

    setcolor(7);

    DrawSmile();

    randomize();//__page_break__

    for(i=0;i<10;i++)

    for(j=0;j<10;j++)

    {

    Mine[i][j].num=random(8);

    if(Mine[i][j].num==1)

    mineNUM++;

    else

    Mine[i][j].num=2;

    Mine[i][j].flag=0;

    }

    sprintf(randmineNUM,"%d",mineNUM);

    setcolor(1);

    settextstyle(0,0,2);

    outtextxy(210,70,randmineNUM);

    mineNUM=100-mineNUM;

    MouseOn();

    }

    void GameOver(void)

    {

    int i,j;

    setcolor(0);

    for(i=0;i<10;i++)

    for(j=0;j<10;j++)

    if(Mine[i][j].num==1)

    {

    DrawEmpty(i,j,0,RED);

    setfillstyle(SOLID_FILL,BLACK);

    fillellipse(200+j*20,100+i*20,7,7);

    }

    }

    void GameWin(void)

    {

    setcolor(11);

    settextstyle(0,0,2);

    outtextxy(230,30,"YOU WIN!");

    }

    int MineStatistics(int i,int j)

    {

    int nNUM=0;

    if(i==0&&j==0)

    {

    if(Mine[0][1].num==1)

    nNUM++;

    if(Mine[1][0].num==1)

    nNUM++;

    if(Mine[1][1].num==1)

    nNUM++;

    }

    else

    if(i==0&&j==9)

    {

    if(Mine[0][8].num==1)

    nNUM++;

    if(Mine[1][9].num==1)

    nNUM++;

    if(Mine[1][8].num==1)

    nNUM++;

    }

    else

    if(i==9&&j==0)

    {

    if(Mine[8][0].num==1)

    nNUM++;

    if(Mine[9][1].num==1)

    nNUM++;

    if(Mine[8][1].num==1)

    nNUM++;

    }

    else

    if(i==9&&j==9)

    {

    if(Mine[9][8].num==1)

    nNUM++;

    if(Mine[8][9].num==1)

    nNUM++;

    if(Mine[8][8].num==1)

    nNUM++;

    }

    else if(j==0)

    {

    if(Mine[i][j+1].num==1)

    nNUM++;

    if(Mine[i+1][j].num==1)

    nNUM++;

    if(Mine[i-1][j].num==1)

    nNUM++;

    if(Mine[i-1][j+1].num==1)

    nNUM++;

    if(Mine[i+1][j+1].num==1)

    nNUM++;

    }

    else if(j==9)

    {

    if(Mine[i][j-1].num==1)

    nNUM++;

    if(Mine[i+1][j].num==1)

    nNUM++;

    if(Mine[i-1][j].num==1)

    nNUM++;

    if(Mine[i-1][j-1].num==1)

    nNUM++;

    if(Mine[i+1][j-1].num==1)

    nNUM++;

    }

    else if(i==0)

    {

    if(Mine[i+1][j].num==1)

    nNUM++;

    if(Mine[i][j-1].num==1)

    nNUM++;

    if(Mine[i][j+1].num==1)

    nNUM++;

    if(Mine[i+1][j-1].num==1)

    nNUM++;

    if(Mine[i+1][j+1].num==1)

    nNUM++;

    }

    else if(i==9)

    {

    if(Mine[i-1][j].num==1)

    nNUM++;

    if(Mine[i][j-1].num==1)

    nNUM++;

    if(Mine[i][j+1].num==1)

    nNUM++;

    if(Mine[i-1][j-1].num==1)

    nNUM++;

    if(Mine[i-1][j+1].num==1)

    nNUM++;

    }

    else

    {

    if(Mine[i-1][j].num==1)

    nNUM++;

    if(Mine[i-1][j+1].num==1)

    nNUM++;

    if(Mine[i][j+1].num==1)

    nNUM++;

    if(Mine[i+1][j+1].num==1)

    nNUM++;

    if(Mine[i+1][j].num==1)

    nNUM++;

    if(Mine[i+1][j-1].num==1)

    nNUM++;

    if(Mine[i][j-1].num==1)

    nNUM++;

    if(Mine[i-1][j-1].num==1)

    nNUM++;

    }//__page_break__

    return (nNUM);

    }

    int ShowWhite(int i,int j)

    {

    if(Mine[i][j].flag==1||Mine[i][j].num==0)

    return;

    mineNUM--;

    if(Mine[i][j].roundnum==0&&Mine[i][j].num!=1)

    {

    DrawEmpty(i,j,1,7);

    Mine[i][j].num=0;

    }

    else

    if(Mine[i][j].roundnum!=0)

    {

    DrawEmpty(i,j,0,8);

    sprintf(randmineNUM,"%d",Mine[i][j].roundnum);

    setcolor(RED);

    outtextxy(195+j*20,95+i*20,randmineNUM);

    Mine[i][j].num=0;

    return ;

    }

    if(i!=0&&Mine[i-1][j].num!=1)

    ShowWhite(i-1,j);

    if(i!=0&&j!=9&&Mine[i-1][j+1].num!=1)

    ShowWhite(i-1,j+1);

    if(j!=9&&Mine[i][j+1].num!=1)

    ShowWhite(i,j+1);

    if(j!=9&&i!=9&&Mine[i+1][j+1].num!=1)

    ShowWhite(i+1,j+1);

    if(i!=9&&Mine[i+1][j].num!=1)

    ShowWhite(i+1,j);

    if(i!=9&&j!=0&&Mine[i+1][j-1].num!=1)

    ShowWhite(i+1,j-1);

    if(j!=0&&Mine[i][j-1].num!=1)

    ShowWhite(i,j-1);

    if(i!=0&&j!=0&&Mine[i-1][j-1].num!=1)

    ShowWhite(i-1,j-1);

    }

    void GamePlay(void)

    {

    int i,j,Num;

    for(i=0;i<10;i++)

    for(j=0;j<10;j++)

    Mine[i][j].roundnum=MineStatistics(i,j);

    while(!kbhit())

    {

    if(LeftPress())

    {

    MouseGetXY();

    if(MouseX>280&&MouseX<300&&MouseY>65&&MouseY<85)

    {

    MouseOff();

    gameAGAIN=1;

    break;

    }

    if(MouseX>190&&MouseX<390&&MouseY>90&&MouseY<290)

    {

    j=(MouseX-190)/20;

    i=(MouseY-90)/20;

    if(Mine[i][j].flag==1)

    continue;

    if(Mine[i][j].num!=0)

    {

    if(Mine[i][j].num==1)

    {

    MouseOff();

    GameOver();

    break;

    }

    else

    {

    MouseOff();

    Num=MineStatistics(i,j);

    if(Num==0)

    ShowWhite(i,j);

    else

    {

    sprintf(randmineNUM,"%d",Num);

    setcolor(RED);

    outtextxy(195+j*20,95+i*20,randmineNUM);

    mineNUM--;

    }

    MouseOn();

    Mine[i][j].num=0;

    if(mineNUM<1)

    {

    GameWin();

    break;

    }

    }

    }

    }

    }

    if(RightPress())

    {

    MouseGetXY();

    if(MouseX>190&&MouseX<390&&MouseY>90&&MouseY<290)

    {

    j=(MouseX-190)/20;

    i=(MouseY-90)/20;

    MouseOff();

    if(Mine[i][j].flag==0&&Mine[i][j].num!=0)

    {

    DrawRedflag(i,j);

    Mine[i][j].flag=1;

    }

    else

    if(Mine[i][j].flag==1)

    {

    DrawEmpty(i,j,0,8);

    Mine[i][j].flag=0;

    }

    }

    MouseOn();

    sleep(1);

    }

    }

    }

    //时钟

    #include

    #include

    #include

    #define pi 3.1415926

    #define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;

    #define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;

    #define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)

    void init()

    {int i,l,x1,x2,y1,y2;

    setbkcolor(0);

    circle(300,240,200);

    circle(300,240,205);

    circle(300,240,5);

    for(i=0;i<60;i++)

    {if(i%5==0) l=15;

    else l=5;

    x1=200*cos(i*6*pi/180)+300;

    y1=200*sin(i*6*pi/180)+240;

    x2=(200-l)*cos(i*6*pi/180)+300;

    y2=(200-l)*sin(i*6*pi/180)+240;

    line(x1,y1,x2,y2);

    }

    }

    main()

    {

    int x,y;

    int gd=VGA,gm=2;

    unsigned char h,m,s;

    struct time t[1];

    initgraph(&gd,&gm,"d:\\tc20\\BGI");

    init();

    setwritemode(1);

    gettime(t);

    h=t[0].ti_hour;

    m=t[0].ti_min;

    s=t[0].ti_sec;

    setcolor(7);

    d(150,h,30);

    setcolor(14);

    d(170,m,6);

    setcolor(4);

    d(190,s,6);

    while(!kbhit())

    {while(t[0].ti_sec==s)

    gettime(t);

    sound(400);

    delay(70);

    sound(200);

    delay(30);

    nosound();

    setcolor(4);

    d(190,s,6);

    s=t[0].ti_sec;

    d(190,s,6);

    if (t[0].ti_min!=m)

    {

    setcolor(14);

    d(170,m,6);

    m=t[0].ti_min;

    d(170,m,6);

    }

    if (t[0].ti_hour!=h)

    { setcolor(7);

    d(150,h,30);

    h=t[0].ti_hour;

    d(150,h,30);

    sound(1000);

    delay(240);

    nosound();

    delay(140);

    sound(2000);

    delay(240);

    nosound();

    }

    }

    getch();

    closegraph();

    }

    //贪吃蛇

    #define N 200

    #include

    #include

    #include

    #define LEFT 0x4b00

    #define RIGHT 0x4d00

    #define DOWN 0x5000

    #define UP 0x4800

    #define ESC 0x011b

    int i,key;

    int score=0;

    int gamespeed=50000;

    struct Food

    {

    int x;

    int y;

    int yes;

    }food;

    struct Snake

    {

    int x[N];

    int y[N];

    int node;

    int direction;

    int life;

    }snake;

    void Init(void);

    void Close(void);

    void DrawK(void);

    void GameOver(void);

    void GamePlay(void);

    void PrScore(void);

    void main(void)

    {

    Init();

    DrawK();

    GamePlay();

    Close();

    }

    void Init(void)

    {

    int gd=DETECT,gm;

    initgraph(&gd,&gm,"D:\\tc20\\BGI");

    cleardevice();

    }

    void DrawK(void)

    {

    setcolor(11);

    setlinestyle(SOLID_LINE,0,THICK_WIDTH);

    for(i=50;i<=600;i+=10)

    {

    rectangle(i,40,i+10,49);

    rectangle(i,451,i+10,460);

    }

    for(i=40;i<=450;i+=10)

    {

    rectangle(50,i,59,i+10);

    rectangle(601,i,610,i+10);

    }

    }

    void GamePlay(void)

    {

    randomize();

    food.yes=1;

    snake.life=0;

    snake.direction=1;

    snake.x[0]=100;snake.y[0]=100;

    snake.x[1]=110;snake.y[1]=100;

    snake.node=2;

    PrScore();

    while(1)

    {

    while(!kbhit())

    {

    if(food.yes==1)

    {

    food.x=rand()%400+60;

    food.y=rand()%350+60;

    while(food.x%10!=0)

    food.x++;

    while(food.y%10!=0)

    food.y++;

    food.yes=0;

    }

    if(food.yes==0)

    {

    setcolor(GREEN);

    rectangle(food.x,food.y,food.x+10,food.y-10);

    }

    for(i=snake.node-1;i>0;i--)

    {

    snake.x[i]=snake.x[i-1];

    snake.y[i]=snake.y[i-1];

    }

    switch(snake.direction)

    {

    case 1:snake.x[0]+=10;break;

    case 2: snake.x[0]-=10;break;

    case 3: snake.y[0]-=10;break;

    case 4: snake.y[0]+=10;break;

    }

    for(i=3;i

    {

    if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])

    {

    GameOver();

    snake.life=1;

    break;

    }

    }

    if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||

    snake.y[0]>455)

    {

    GameOver();

    snake.life=1;

    }

    if(snake.life==1)

    break;

    if(snake.x[0]==food.x&&snake.y[0]==food.y)

    {

    setcolor(0);

    rectangle(food.x,food.y,food.x+10,food.y-10);

    snake.x[snake.node]=-20;snake.y[snake.node]=-20;

    snake.node++;

    food.yes=1;

    score+=10;

    PrScore();

    }

    setcolor(4);

    for(i=0;i

    rectangle(snake.x[i],snake.y[i],snake.x[i]+10,

    snake.y[i]-10);

    delay(gamespeed);

    setcolor(0);

    rectangle(snake.x[snake.node-1],snake.y[snake.node-1],

    snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);

    }

    if(snake.life==1)

    break;

    key=bioskey(0);

    if(key==ESC)

    break;

    else

    if(key==UP&&snake.direction!=4)

    snake.direction=3;

    else

    if(key==RIGHT&&snake.direction!=2)

    snake.direction=1;

    else

    if(key==LEFT&&snake.direction!=1)

    snake.direction=2;

    else

    if(key==DOWN&&snake.direction!=3)

    snake.direction=4;

    }

    }

    void GameOver(void)

    {

    cleardevice();

    PrScore();

    setcolor(RED);

    settextstyle(0,0,4);

    outtextxy(200,200,"GAME OVER");

    getch();

    }

    void PrScore(void)

    {

    char str[10];

    setfillstyle(SOLID_FILL,YELLOW);

    bar(50,15,220,35);

    setcolor(6);

    settextstyle(0,0,2);

    sprintf(str,"score:%d",score);

    outtextxy(55,20,str);

    }

    void Close(void)

    {

    getch();

    closegraph();

    }

    //鼠标控制

    #include

    #include

    #include

    #include

    #include

    #include "graphics.h"

    #define R 15

    void initgr(void)

    {

    int gd = DETECT, gm = 0;

    initgraph(&gd, &gm, "D:\\TC20\\BGI");

    }

    void getmouse(int *x,int *y,int *key)

    {

    union REGS inregs,outregs;

    inregs.x.ax=3;

    int86(0x33,&inregs,&outregs);

    *x=outregs.x.cx;

    *y=outregs.x.dx;

    *key=outregs.x.bx;

    }

    void visbilemouse()

    {

    union REGS inregs,outregs;

    inregs.x.ax=0x01;

    int86(0x33,&inregs,&outregs);

    }

    void mouse(int *x,int *y,int *z)

    {

    int a=0,b=0,c=0,a_old=0,b_old=0;

    int *ball;

    ball=malloc(imagesize(a,b,a+R,b+R));

    getimage(a,b,a+R,b+R,ball);

    while(c==0)

    {

    getmouse(&a,&b,&c);

    if(a<0) a=0;

    if(b<0) b=0;

    if(a>getmaxx()-R) a=getmaxx()-R;

    if(b>getmaxy()-R) b=getmaxy()-R;

    if(a!=a_old || b!=b_old)

    {

    putimage(a_old,b_old,ball,0);

    getimage(a,b,a+R,b+R,ball);

    setcolor(GREEN);

    setlinestyle(0,0,1);

    line(a,b,a+R,b+R/2);

    line(a,b,a+R/2,b+R);

    line(a+R,b+R/2,a+R/2,b+R);

    line(a+R*3/4,b+R*3/4,a+R,b+R);

    }

    a_old=a;b_old=b;

    }

    *x=a;*y=b;*z=c;

    putimage(a,b,ball,0);

    free(ball);

    }

    void main()

    {

    int x,y,z;

    initgr();

    visbilemouse();

    do

    {

    setcolor(WHITE);

    rectangle(175,8,220,25);

    outtextxy(180,10,"exit");

    mouse(&x,&y,&z);

    if(z==1)

    {

    setlinestyle(0,0,1);

    setcolor(12);

    circle(x,y,1);

    }

    if(z==2)

    {setfillstyle(1,BLACK);

    bar(0,0,getmaxx(),getmaxy());

    }

    }while(x<175 || x>220 ||

    y<8 || y>25);

    closegraph();

    }

    本源码整理于互联网

    展开全文
  • C语言贪吃蛇经典小游戏

    千次阅读 2021-05-19 13:21:30
    一、贪吃蛇小游戏简介:用上下左右控制蛇的方向,寻找吃的东西,每吃一口就能得到一定的积分,而且蛇的身子会越吃越长,身子越长玩的难度就越大,不能碰墙,也不能咬到自己的身体,等到了一定的分数,就能过关。...

    一、贪吃蛇小游戏简介:

    用上下左右控制蛇的方向,寻找吃的东西,每吃一口就能得到一定的积分,而且蛇的身子会越吃越长,身子越长玩的难度就越大,不能碰墙,也不能咬到自己的身体,等到了一定的分数,就能过关。

    二、函数框架

    87268eeeb7940971538d86ea80a0373f.png

    三、数据结构

    typedef struct Snake

    {

    size_t x; //行

    size_t y; //列

    struct Snake* next;

    }Snake, *pSnake;

    定义蛇的结构体,利用单链表来表示蛇,每个结点为蛇身体的一部分。

    四、代码实现(vs2010  c语言)

    1.Snake.h

    #ifndef __SNAKE_H__

    #define __SNAKE_H__

    #include

    #include

    #include

    #include

    #include

    #include

    //标识地图大小

    #define ROW_MAP 10 //地图的行

    #define COL_MAP 20 //地图的列

    #define SUCCESS_SCORE 10//通关分数

    enum Direction //蛇行走的方向

    {

    R, //右

    L, //左

    U, //上

    D //下

    }Direction;

    enum State

    {

    ERROR_SELF, //咬到自己

    ERROR_WALL, //撞到墙

    NORMAL, //正常状态

    SUCCESS //通关

    }State;

    typedef struct Snake

    {

    size_t x; //行

    size_t y; //列

    struct Snake* next;

    }Snake, *pSnake;

    void StartGame();

    void RunGame();

    void EndGame();

    #endif

    2.Snake.c

    #include "Snake.h"

    pSnake head = NULL; //定义蛇头指针

    pSnake Food = NULL; //定义食物指针

    int sleeptime = 500;//间隔时间,用来控制速度

    int Score = 0; //总分

    int everyScore = 1; //每步得分

    //定义游戏中用到的符号

    const char food = '#';

    const char snake = '*';

    void Pos(int x, int y) //控制输出光标

    {

    COORD pos; //pos为结构体

    pos.X = x; //控制列

    pos.Y = y; //控制行

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);//读取标准输出句柄来控制光标为pos

    }

    void Face()

    {

    system("color 0C");

    printf("*******************************************************\n");

    printf("* Welcome to Snake Game! *\n");

    printf("* *\n");

    printf("* ->开始游戏请按 enter键 *\n");

    printf("* ->退出游戏请按 esc键 *\n");

    printf("* ->暂停游戏请按 space键 *\n");

    printf("* ->通过上下左右键来控制蛇的移动 *\n");

    printf("* ->通过F1键减速 F2键加速 *\n");

    printf("*******************************************************\n");

    }

    void Map() //初始化地图

    {

    int i = 0;

    for(i = 0; i

    {

    Pos(i, 0);

    printf("■");

    Pos(i, ROW_MAP-1);

    printf("■");

    }

    for(i = 0; i

    {

    Pos(0, i);

    printf("■");

    Pos(COL_MAP-2, i);

    printf("■");

    }

    }

    void PrintSnake() //打印蛇

    {

    pSnake cur = head;

    while(cur)

    {

    Pos(cur->y, cur->x);

    printf("%c", snake);

    cur = cur->next;

    }

    }

    void InitSnake() //初始化蛇身

    {

    int initNum = 3;

    int i = 0;

    pSnake cur;

    head = (pSnake)malloc(sizeof(Snake));

    head->x = 5;

    head->y = 10;

    head->next = NULL;

    cur = head;

    for(i = 1; i < initNum; i++)

    {

    pSnake newNode = (pSnake)malloc(sizeof(Snake));

    newNode->x = 5+i;

    newNode->y = 10;

    newNode->next = NULL;

    cur->next = newNode;

    cur = cur->next;

    }

    PrintSnake();

    }

    void CreateFood() //在地图上随机产生一个食物

    {

    pSnake cur = head;

    Food = (pSnake)malloc(sizeof(Snake));

    //产生x~y的随机数 k=rand()%(Y-X+1)+X;

    srand((unsigned)time(NULL));

    Food->x = rand()%(ROW_MAP-2 - 1 + 1)+1;

    Food->y = rand()%(COL_MAP-3 - 2 + 1)+2;

    Food->next = NULL;

    while(cur) //检查食物是否与蛇身重合

    {

    if(cur->x == Food->x && cur->y == Food->y)

    {

    free(Food);

    Food = NULL;

    CreateFood();

    return;

    }

    cur = cur->next;

    }

    Pos(Food->y, Food->x);

    printf("%c", food);

    }

    void StartGame() //游戏开始的所有设置

    {

    Face();

    system("pause");

    if(GetAsyncKeyState(VK_RETURN))

    {

    system("cls");

    Pos(COL_MAP+5, 1);

    printf("当前分数/通关分数:");

    Pos(COL_MAP+20, 1);

    printf("%d/%d", Score, SUCCESS_SCORE);

    Pos(COL_MAP+5, 2);

    printf("当前分每步得分:");

    Pos(COL_MAP+20, 2);

    printf("%d", everyScore);

    Pos(COL_MAP+5, 3);

    printf("\n");

    Pos(COL_MAP+5, 4);

    printf("速度越快 得分越高哦!!\n");

    Map();

    InitSnake();

    CreateFood();

    }

    else if(GetAsyncKeyState(VK_ESCAPE))

    {

    exit(0);

    }

    }

    int IsCrossWall() //判断是否碰到墙

    {

    if(head->x <= 0 || head->x >= ROW_MAP-1

    ||head->y <= 1 || head->y >= COL_MAP-2)

    {

    State = ERROR_WALL;

    return 0;

    }

    return 1;

    }

    int IsEatSelf(pSnake newHead) //判断是否咬到自己

    {

    pSnake cur = head;

    assert(newHead);

    while(cur)

    {

    if(cur->x == newHead->x && cur->y == newHead->y)

    {

    State = ERROR_SELF;

    return 0;

    }

    cur = cur->next;

    }

    return 1;

    }

    int IsFood(pSnake pos) //判断该位置是不是食物

    {

    assert(pos);

    if(pos->x == Food->x && pos->y == Food->y)

    {

    return 1;

    }

    return 0;

    }

    void SnakeMove() //蛇移动一次

    {

    pSnake newHead = NULL;

    newHead = (pSnake)malloc(sizeof(Snake));

    if(Direction == R)

    {

    newHead->x = head->x;

    newHead->y = head->y+1;

    newHead->next = head;

    }

    else if(Direction == L)

    {

    newHead->x = head->x;

    newHead->y = head->y-1;

    newHead->next = head;

    }

    else if(Direction == U)

    {

    newHead->x = head->x-1;

    newHead->y = head->y;

    newHead->next = head;

    }

    else if(Direction == D)

    {

    newHead->x = head->x+1;

    newHead->y = head->y;

    newHead->next = head;

    }

    if(IsFood(newHead))

    {

    head = newHead;

    PrintSnake();

    CreateFood();

    Score += everyScore;

    Pos(COL_MAP+20, 1);

    printf("%d/%d", Score, SUCCESS_SCORE);

    if(Score >= SUCCESS_SCORE)

    {

    State = SUCCESS;

    }

    }

    else

    {

    if(IsCrossWall() && IsEatSelf(newHead))

    {

    pSnake cur = NULL;

    head = newHead;

    cur = head;

    //删除蛇尾并打印

    while(cur->next->next != NULL)

    {

    Pos(cur->y, cur->x);

    printf("%c", snake);

    cur = cur->next;

    }

    Pos(cur->y, cur->x);

    printf("%c", snake);

    Pos(cur->next->y, cur->next->x);

    printf(" "); //打印空格来覆盖频幕上的蛇尾

    free(cur->next);

    cur->next = NULL;

    }

    else

    {

    free(newHead);

    newHead = NULL;

    }

    }

    }

    void Pause()

    {

    while(1)

    {

    Sleep(sleeptime);

    if(GetAsyncKeyState(VK_SPACE))

    {

    break;

    }

    }

    }

    void ControlSnake() //用键盘控制游戏

    {

    if(GetAsyncKeyState(VK_UP) && Direction!=D)

    {

    Direction = U;

    }

    else if(GetAsyncKeyState(VK_DOWN) && Direction!=U)

    {

    Direction = D;

    }

    else if(GetAsyncKeyState(VK_LEFT) && Direction!=R)

    {

    Direction = L;

    }

    else if(GetAsyncKeyState(VK_RIGHT) && Direction!=L)

    {

    Direction = R;

    }

    else if(GetAsyncKeyState(VK_F1))

    {

    if(sleeptime != 500)

    {

    sleeptime = 500;

    everyScore = 1;

    Pos(COL_MAP+20, 2);

    printf("%d", everyScore);

    }

    }

    else if(GetAsyncKeyState(VK_F2))

    {

    if(sleeptime != 300)

    {

    sleeptime = 300;

    everyScore = 2;

    Pos(COL_MAP+20, 2);

    printf("%d", everyScore);

    }

    }

    else if(GetAsyncKeyState(VK_SPACE))

    {

    Pause();

    }

    else if(GetAsyncKeyState(VK_ESCAPE))

    {

    exit(0);

    }

    }

    void StateGame() //判断游戏失败或成功

    {

    if(State == ERROR_SELF)

    {

    system("cls");

    printf("很遗憾,蛇咬到自己,游戏失败!\n");

    }

    else if(State == ERROR_WALL)

    {

    system("cls");

    printf("很遗憾,蛇碰到墙壁,游戏失败!\n");

    }

    else if(State == SUCCESS)

    {

    system("cls");

    printf("恭喜您,已通关!!!\n");

    }

    }

    void RunGame()

    {

    Direction = R; //蛇初始行走方向为右

    State = NORMAL;//游戏初始为正常状态

    while(1)

    {

    ControlSnake();

    SnakeMove();

    if(State != NORMAL)

    {

    StateGame();

    break;

    }

    Sleep(sleeptime);

    }

    }

    void EndGame() //释放链表并恢复默认值

    {

    pSnake cur = head;

    while(cur)

    {

    pSnake del = cur;

    cur = cur->next;

    free(del);

    del = NULL;

    }

    head = NULL;

    if(Food != NULL)

    {

    free(Food);

    Food = NULL;

    }

    Score = 0;

    everyScore = 1;

    sleeptime = 500;

    }

    3.Test.c

    #include "Snake.h"

    int main()

    {

    while(1)

    {

    StartGame();

    RunGame();

    EndGame();

    }

    system("pause");

    return 0;

    }

    五、运行界面展示

    1.欢迎界面

    1c66302ba75c46aaa713f7507e21baaf.png

    2.游戏界面

    e21f67a94a949299241eb5155e5e2fb6.png

    小小的c语言项目,用来练手,仅供参考哦!!

    谢谢阅读,如有问题,欢迎提出。

    更多有趣的经典小游戏实现专题,分享给大家:

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    展开全文
  • c语言简单小游戏-扫雷本文实例为大家分享了C语言实现扫雷小游戏的具体代码,供大家参考,具体内容如下#define _CRT_SECURE_NO_WARNINGS#include #include #include /*用 C 语言写一个简单的扫雷游戏*/// 1....

    这篇文章主要为大家详细介绍了C语言实现简单扫雷小游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

    3203486a920be1065edfaeef43f332a0.png

    c语言简单小游戏-扫雷

    本文实例为大家分享了C语言实现扫雷小游戏的具体代码,供大家参考,具体内容如下#define _CRT_SECURE_NO_WARNINGS

    #include

    #include

    #include

    /*

    用 C 语言写一个简单的扫雷游戏

    */

    // 1.写一个游戏菜单 Menu()

    // 2.开始游戏

    // 1.初始化二维数组 Init_Interface()

    // 2.打印游戏界面 Print_Interface()

    // 3.玩家掀起指定位置 Play() --> 指定输入坐标(判断合法性)

    // 1.判断该位置是否是雷

    // 2.判断是否掀掉所有空地

    // 3.如果掀开的是空地,则判断该空地周围是否有雷

    // 1.如果周围有雷,则统计周围雷的个数

    // 2.如果周围没有雷,则掀开周围除了雷的所有空地,并且统计所掀开空地周围雷的个数

    // 4.更新地图

    // 5.继续 3 的循环

    //定义全局变量:

    //定义扫雷地图的长和宽

    #define MAX_ROW 9

    #define MAX_COL 9

    //定义默认的雷数

    #define DEFAULT_MINE 9

    //定义两个二维数组,分别存放初始地图和雷阵

    char show_map[MAX_ROW + 2][MAX_COL + 2];

    char mine_map[MAX_ROW + 2][MAX_COL + 2];

    //写一个游戏菜单

    int Menu() {

    printf("=========\n");

    printf("1.开始游戏\n");

    printf("0.结束游戏\n");

    printf("=========\n");

    printf("请选择游戏菜单选项:");

    int choice = 0;

    while (1) {

    scanf("%d", &choice);

    if (choice != 0 && choice != 1) {

    printf("您的输入有误, 请重新输入\n");

    continue;

    }

    break;

    }

    return choice;

    }

    //开始游戏

    //初始化数组

    void Init_Interface() {

    for (int row = 0; row < MAX_ROW + 2; row++) {

    for (int col = 0; col < MAX_COL + 2; col++) {

    show_map[row][col] = '*';

    }

    }

    for (int row = 0; row < MAX_ROW + 2; row++) {

    for (int col = 0; col < MAX_COL + 2; col++) {

    mine_map[row][col] = '0';

    }

    }

    int mine_count = DEFAULT_MINE;

    while (mine_count > 0) {

    int row = rand() % MAX_ROW + 1;

    int col = rand() % MAX_COL + 1;

    if (mine_map[row][col] == '1') { //将雷设置为 1

    //此处已经有雷

    continue;

    }

    mine_count--;

    mine_map[row][col] = '1';

    }

    }

    //打印初始界面

    void Print_Interface(char map[MAX_ROW + 2][MAX_COL + 2]) {

    printf(" ");

    for (int col = 1; col <= MAX_COL; col++) {

    printf("%d ", col);

    }

    printf("\n ");

    for (int col = 1; col <= MAX_COL; col++) {

    printf("--");

    }

    printf("\n");

    for (int row = 1; row <= MAX_ROW ; row++) {

    printf("%02d |", row);

    for (int col = 1; col <= MAX_COL; col++) {

    printf("%c ", map[row][col]);

    }

    printf("\n");

    }

    }

    //写一个统计周围雷数个数的函数

    int Around_Mine_count(int row, int col) {

    return (mine_map[row - 1][col - 1] - '0'

    + mine_map[row - 1][col] - '0'

    + mine_map[row - 1][col + 1] - '0'

    + mine_map[row][col - 1] - '0'

    + mine_map[row][col + 1] - '0'

    + mine_map[row + 1][col - 1] - '0'

    + mine_map[row + 1][col] - '0'

    + mine_map[row + 1][col + 1] - '0');

    }

    //写一个判断该位置周围是否有雷的函数

    int No_Mine(int row, int col) {

    if (Around_Mine_count(row, col) == 0) {

    return 1;

    }

    return 0;

    }

    //写一个掀开该位置周围空地的函数

    void Open_Blank(int row, int col) {

    show_map[row - 1][col - 1] = '0' + Around_Mine_count(row - 1, col - 1);

    show_map[row - 1][col] = '0' + Around_Mine_count(row - 1, col);

    show_map[row - 1][col + 1] = '0' + Around_Mine_count(row - 1, col + 1);

    show_map[row][col - 1] = '0' + Around_Mine_count(row, col - 1);

    show_map[row][col + 1] = '0' + Around_Mine_count(row, col + 1);

    show_map[row + 1][col - 1] = '0' + Around_Mine_count(row + 1, col - 1);

    show_map[row + 1][col] = '0' + Around_Mine_count(row + 1, col);

    show_map[row + 1][col + 1] = '0' + Around_Mine_count(row + 1, col + 1);

    }

    //写一个判断游戏结束的函数

    int Success_Sweep(char show_map[MAX_ROW + 2][MAX_COL + 2]) {

    int count = 0;

    for (int row = 1; row <= MAX_ROW; row++) {

    for (int col = 1; col <= MAX_COL; col++) {

    if (show_map[row][col] == '*') {

    count++;

    }

    }

    }

    if (count == DEFAULT_MINE) {

    return 1;

    }

    return 0;

    }

    //开始游戏

    void StartGame() {

    while (1) {

    printf("请输入您要掀开的坐标:");

    int row = 0;

    int col = 0;

    while (1) {

    scanf("%d %d", &row, &col);

    if (row < 1 || row > MAX_ROW || col < 1 || col > MAX_COL) {

    printf("您的输入有误,请重新输入!\n");

    continue;

    }

    if (show_map[row][col] != '*') {

    printf("该位置已被掀开,请重新选择\n");

    continue;

    }

    break;

    }

    //判断该地方是否有雷

    if (mine_map[row][col] == '1') {

    Print_Interface(mine_map);

    printf("该地方有雷,游戏结束!!!\n");

    break;

    }

    if (No_Mine(row, col)) {

    show_map[row][col] = '0';

    Open_Blank(row, col);

    }

    show_map[row][col] = '0' + Around_Mine_count(row, col);

    //判断是否掀开所有空地

    if (Success_Sweep(show_map) == 1) {

    Print_Interface(mine_map);

    printf("您已成功扫雷!!!\n");

    break;

    }

    system("cls");

    //更新地图

    Print_Interface(show_map);

    }

    }

    int main() {

    if (Menu() == 0) {

    exit(0);

    }

    srand((unsigned int)time(NULL));

    Init_Interface();

    Print_Interface(show_map);

    StartGame();

    system("pause");

    return 0;

    }

    效果图:

    18567cbcaf589379a20f36d1227a3825.png

    数字代表周围雷的个数

    更多C语言教程,推荐观看C语言视频教程!

    展开全文
  • 四个c语言小游戏

    千次阅读 2021-11-22 19:37:41
    C语言小游戏0、前言1、普普通通的五子棋2、好难操作的贪吃蛇3、简单到炸的自制迷宫4、不忍直视的双人飞机对战 0、前言 1、我使用的是编译软件是vc6.0 2、如果代码无法运行,你可以尝试吧文件xxx.c改为xxx.cpp 3、四...
  • if (ch { printf("你猜了\n"); } else if (ch>n) { printf("你猜大了\n"); } if (ch == n) { printf("恭喜你猜对了\n"); break; } } break; default: printf("退出游戏\n"); break; } } system("pause"); return ...
  • c语言经典游戏代码

    千次阅读 2021-05-20 01:10:20
    //C语言多线程-主角和怪物#include#include#define bool int //定义int变量为bool变量,bool不是真就是假int a=0,b=20;//主角的坐标int x=1,y=0;//怪物的坐标int i=1;//i值为真HANDLE hMutex;//1.坐标void ...
  • puts("游戏结束,按任意键继续"); system("pause"); return 0; } if(z!=0) { puts("请选择是否挖矿!"); puts(""); puts("输入1开始挖矿,输入0停止挖矿"); scanf("%d",&z); } } puts("您拥有的钱数:"); printf("%...
  • C语言的应用 小游戏为例贪吃蛇游戏设计姓 名:学 号:班 级: 103511指导老师: 张 印2012年05月29日《c语言程序设计》课程期末论文 PAGE I目 录TOC \o "1-4" \u 1选题背景 PAGEREF _Toc326074128 \h 12.设计介绍 ...
  • 现在说一下其中一个最简单程序:弹跳小球―――――――――――――――LINE――――――――――――――――首先我们知道,在窗口的坐标系原点是在窗口左上角的,如图所示然后我们如果想在这个坐标系里面的...
  • #include #include #include #include #define Height 31 //迷宫的高度,必须为奇数#define Width 25 //迷宫的宽度,必须为奇数#define Wall 1#define Road 0#define Start 2#define End 3#define Esc 5#define Up 1...
  • 玩转c语言——c语言小游戏 迷宫小游戏(附源码)

    千次阅读 多人点赞 2021-10-02 08:35:24
    要制作迷宫小游戏,我们要利用二维数组搭建场景,制作一个简易的迷宫 #include<stdio.h> #include<stdlib.h> #include<windows.h> #include<conio.h>//小游戏所需的所有头文件 int main...
  • C语言简单小游戏【猜数字】

    千次阅读 2021-11-09 08:29:26
    实现该小游戏所用到的知识点 1.分支与循环语句 if switch选择语句的使用 while do while循环语句的使用 2.函数 会用time时间戳来设定随机值 //time()中不要()中的参数,而这个参数需要指针,所以可以NULL(空...
  • 进入游戏 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h> #include <Windows.h> #define _CRT_SECURE_NO_WARNINGS ...
  • 小时候,在学校和伙伴除了互相追逐着玩闹玩游戏以外,相信很多伙伴们也有和朋友在课堂上拿一张纸玩井字棋的美好回忆。(如下图酱紫啦~) 那今天呢,我们就用C语言制作一款简易的井字棋来练习一下对代码的感觉...
  • C语言编写的迷宫小游戏 源代C语言编写的迷宫小游戏 源代码#include #include #include #include #include #define N 20/*迷宫的大小,可改变*/int oldmap[N][N];/*递归用的数组,用全局变量节约时间*/int yes=0;/*yes...
  • PAGE / NUMPAGES纯真童趣的...作为游戏玩家的我们,是不是想设计一个属于自己的游戏呢???? 爱玩是人的天性,而C语言是我们计算机专业都要学习的一门基础 学科.一般来说,是比较枯燥的.那么,我们能不能通过编一些游...
  • c语言小游戏程序——弹跳小球

    千次阅读 2021-11-24 17:34:46
    在说一下其中一个最简单程序:弹跳小球 (易懂,容易学会) 首先我们知道,在窗口的坐标系原点是在窗口左上角的,如图所示 然后我们如果想在这个坐标系里面的某个点上画出一个小球,那么它的坐标系应该...
  • 五子棋简单功能实现,供大家参考,具体内容如下游戏功能演示代码如下:#include #include #include #include // 棋盘char board[15][15];// 棋子坐标char kx = 7 , ky = 7;// 角色char role = "@";// 显示棋盘void ...
  • --基于C语言小游戏设计.doc级丌密公本科生毕业(学位)论文基于c语言的爪游软设计李俊佶(2009061322)TOC \o "1-5" \h \z 指导教师姓名:叶晶晶 职称:单位:物理与电子科学系专业名称:电子信息工程 论文提交日期:...
  • C语言可以写哪些小游戏?C语言可以编手机游戏。你叫他去死不过我这有贪吃蛇的代码,你倒可以看看(用TC编译一定过(#包括#包括#包括#包括#包括#定义输入7181#定义ESC 283#定义UP 18432#定义向下20480#定义左19200#定义...
  • /*自己改游戏的速度*/ int speed;/*飞碟移动速度*/ int col;/*中心坐标*/ int score=0;/*得分*/ char key_state[128],key_pressed[128];/*键盘操作用的变量*/ void Init();/*初始*/ void Close();/*关闭*/ void Play...
  • C语言文字小游戏制作

    2021-05-23 10:26:22
    你们想想,如果一个游戏游戏不能跟玩家交流是不是很无聊,一个劲输出让你像看故事一样。可能现在学了之后觉得没用,不过不用担心,学了就一定有用。你们都玩过游戏吧?不管手机游戏还是电脑游戏,都是一样的,就拿...
  • [c]代码库#include#include#include#include#include/// 游戏活动区域#define GAME_W 20#define GAME_H 14/// 方向#define UP 72#define DOWN 80#define LEFT 75#define RIGHT 77#define gotoxyInGameAndPrint(x...
  • 扫雷游戏对我们来说并不陌生设计思路:1)初始化雷阵;2)打印雷阵;3)设置雷的位置(有系统调用rand()函数产生)4)统计点击处雷的个数5)排雷;具体步骤:1.初始化雷阵的时候需要初始化两个矩阵,如下://初始化雷盘//...
  • 如何用 c 语言编写小游戏精品 word 文档 值得下载 值得拥有 纯真童趣的《泡泡堂》 , 还有武林情仇 ,笑傲江湖的《剑侠情缘 online 》. 它是 e 时代常谈的话题 , 是交互 式娱乐的主力军 , 是一种 高层次的综合艺术 , ...
  • } if (number2 ) { printf("\n猜了!\n"); scanf("%d", &number2); } if (number2 > number1) { printf("\n猜大了!\n"); scanf("%d", &number2); } } } while(choice == 2) { return 0; } system("pause"); return...
  • c语言编写小游戏系列教程之移动游戏人物,C_C++,自学去.pdf2015/1/22 【新提醒】c语言编写小游戏系列教程之移动游戏人物,C/C++,自学去设为首页 收藏本站admin在线|每日签到|我的 |设置|消息| 提醒(2) | 门户管理|管理...
  • 游戏界面如下:首先,先画出整个小游戏实现的流程图,如下:思路很简单,整个游戏界面是由一个大的char类型数组构成,更新数组的值然后不停的打印出来就形成了动态效果。由上图看,大循环是保证游戏一直不断的进行...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 40,717
精华内容 16,286
关键字:

c语言简单小游戏

c语言 订阅