复制代码 代码如下:
- #include"2048.h"int main(){ start_game(); return 0;}2048.h
登录后复制
复制代码 代码如下:
- #ifndef _2048_h_#define _2048_h_#include#include#include#include//#include//#include#define line 21#define row 22#define arr_l 4#define arr_r 4#define num_color 32#define back 49#define bold 31static int line_location=0;static int row_location=0;static int arr[4][4]={0};static char tmp[5]="\0";static int end_flag=0;static int score=0;static int print_appear_flag=0;static char start_back0[line][row]={ "@@@@@@@@@@@@@@@@@@@@@", "@ @ @ @ @", "@ @ @ @ @", "@ @ @ @ @", "@@@@@@@@@@@@@@@@@@@@@", "@ @ @ @ @", "@ @ @ @ @", "@ @ @ @ @", "@@@@@@@@@@@@@@@@@@@@@", "@ @ @ @ @", "@ @ @ @ @", "@ @ @ @ @", "@@@@@@@@@@@@@@@@@@@@@", "@ @ @ @ @", "@ @ @ @ @", "@ @ @ @ @", "@@@@@@@@@@@@@@@@@@@@@", "@ @", "@ score: @", "@ @", "@@@@@@@@@@@@@@@@@@@@@"};int print_start();char * itoc_2048(int data);int print_num();int mov_left();int swap_if0l();int swap();int put_to(int line, int row);#endif2048.c复制代码 代码如下:#include"2048.h"int start_game(){ system("clear"); printf("\33[?25l"); print_start(); ran_appear(); print_num(); print_score(); print_getchar(); printf("\33[?25h");}int print_getchar(){ struct termios old,new; int ch; tcgetattr(0,&old); tcgetattr(0,&new); new.c_lflag = new.c_lflag &~(icanon |echo); new.c_cc[vtime]=0; new.c_cc[vmin]=1; tcsetattr(0,tcsanow,&new); while(1) { if(end_flag==1) break; ch=getchar(); if(ch=='\33') { ch=getchar(); if(ch=='[') { ch=getchar(); switch(ch) { case 'a': mov_up(); is_full(); break; case 'b': mov_down(); is_full(); break; case 'c': mov_right(); is_full(); break; case 'd': mov_left(); is_full(); break; default: break; } } } if(ch=='q') break; fflush(null); }tcsetattr(0,tcsanow,&old);}int print_start(){ int i,j; for(i=0;i=0;row--) for(line=0;line=0;line--) for(row=0;row
Linux有哪些版本
Linux的版本有:Deepin、UbuntuKylin、Manjaro、LinuxMint、Ubuntu等版本。其中Deepin是国内发展最好的Linux发行版之一;UbuntuKylin是基于Ubuntu的衍生发行版;Manjaro是基于Arch的Linux发行版;LinuxMint默认的Cinnamon桌面类似Windows XP简单易用;Ubuntu则是以桌面应用为主的Linux操作系统。
登录后复制
以上就是linux如何实现2048小游戏的详细内容,更多请关注【创想鸟】其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。