zoukankan      html  css  js  c++  java
  • 利用ncurses库实现简单飞机小游戏

    #include<stdlib.h>
    #include<ncurses,h>
    #define plane '*'
    
    char plane(int x,int y);
    
    int main()
    {
        int x = 5;
        int y = 10;
        char ch;
        initscr();
        cbreak();
        noecho();
        clear();
    
        do
        {
            clear();
            picture(x,y);
            ch = getch();
            switch(ch)
            {
                case 'w':
                                picture(x,y);
                                y = y - 1;
                                break;
                case 's':
                               picture(x,y);
                               y = y - 1;
                               break; 
                case 'a':
                               picture(x,y);
                               x = x - 1;
                               break; 
                case 'd':
                               picture(x,y);
                               x = x + 1;
                               break; 
            }
        }while(ch != 'q');
        endwin();
        exit(0);
    }
    
    char plane(int x,int y)
    {
        int i;
        for(i = 0;i<y;i++)
        {
            mvprintw(i,x,"%c",'|');
            refresh();
        }
        mvaddch(y,x,PLANE);
        mvaddch(y+1,x-2,PLANE);
        mvaddch(y+1,x-1,PLANE);
        mvaddch(y+1,x,PLANE);
        mvaddch(y+1,x+1,PLANE);
        mvaddch(y+1,x+2,PLANE);
        mvaddch(y+2,x-1,PLANE);
        mvaddch(y+2,x+1,PLANE);
    }

    目前只实现了一个移动的飞机,还不算一个游戏,后续会对代码进行改进。

    参考博客:https://www.imooc.com/article/24381

  • 相关阅读:
    Maya 与 Matlab 数据互联插件使用教程
    代码可视化算法流程
    sql 至少含有
    sql update limit1
    c# windows service 程序
    c#和.net区别
    c#数据库乱码
    c#事件实质
    c#非界面线程控制控件
    mysql唯一查询
  • 原文地址:https://www.cnblogs.com/zhongllmm/p/14281541.html
Copyright © 2011-2022 走看看