Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize 2048 Mini Game under linux console

Shulou Source: shulou.com Published: 2022-06-01 04:00:12 09月13日 Update

Most people do not understand the knowledge points of this article "how to achieve 2048 Mini Game under the linux console", so the editor summarizes the following contents, detailed contents and clear steps, which can be used for reference. I hope you can get something after reading this article. Let's take a look at this "how to achieve 2048 Mini Game under the linux console" article.

Cut the crap and send me the code:

Main.c

The copy code is as follows:

# include "2048.h"

Int main ()

{

Start_game ()

Return 0

}

2048.h

The copy 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 31

Static 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)

# endif

2048.c

The 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 (0djinghold)

Tcgetattr (0djinghnew)

New.c_lflag = new.c_lflag & ~ (icanon | echo)

New.c_ cc [Vtime] = 0

New.c_ cc [vmin] = 1

Tcsetattr (0pr tcsanow.mcsanow.new)

While (1)

{

If (end_flag==1)

Break

Ch=getchar ()

If (ch=='\ 33')

{

Ch=getchar ()

If (ch==' [')

{

Ch=getchar ()

Switch (ch)

{

Case'asides:

Mov_up ()

Is_full ()

Break

Case'baked:

Mov_down ()

Is_full ()

Break

Case'cages:

Mov_right ()

Is_full ()

Break

Case'dcards:

Mov_left ()

Is_full ()

Break

Default:

Break

}

}

}

If (ch=='q')

Break

Fflush (null)

}

Tcsetattr (0rem tcsanowjinghold)

}

Int print_start ()

{

Int i,j

For (iSuppli)

Tags: Code content Mini Game controls articles knowledge articles previous generation value most that is nonsense more steps knowledge points industry information information channels channels help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux MariaDB NVidia Xiaomi