linux控制台下实现2048小游戏

2019-10-14 10:57:09于丽

废话少说,直接奉上代码:

main.c


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

2048.h


#ifndef _2048_H_
#define _2048_H_
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<termios.h>
//#include<unstd.h>
//#include<time/sys.h>
#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]="";
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();