How to Realize 2048 Games in linux

10-25-2023

The copy code code is as follows:

#include"2048.h"int main(){ start_game(); return 0; }2048.h

The copy code code is as follows:

#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]=""; 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 copy code is as follows: # 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; What are the versions of rowLinux? The versions of Linux are Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and so on. Deepin is one of the best developed Linux distributions in China. UbuntuKylin is a derivative distribution based on Ubuntu; Manjaro is a Linux distribution based on Arch; LinuxMint's default Cinnamon desktop is similar to Windows XP and easy to use. Ubuntu is a Linux operating system based on desktop applications.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us