From 30a5f910dc22cd9151191f4ad2d5e60965387a9c Mon Sep 17 00:00:00 2001 From: mch <2243739779@qq.com> Date: Tue, 16 May 2023 19:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'2048.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2048.c | 439 --------------------------------------------------------- 1 file changed, 439 deletions(-) delete mode 100644 2048.c diff --git a/2048.c b/2048.c deleted file mode 100644 index e1a4178..0000000 --- a/2048.c +++ /dev/null @@ -1,439 +0,0 @@ -/* - ============================================================================ - Name : 2048.c - Author : Maurits van der Schee - Description : Console version of the game "2048" for GNU/Linux - ============================================================================ - */ - -#define _XOPEN_SOURCE 500 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define SIZE 4 -uint32_t score=0; -uint8_t scheme=0; - -void getColor(uint8_t value, char *color, size_t length) { - uint8_t original[] = {8,255,1,255,2,255,3,255,4,255,5,255,6,255,7,255,9,0,10,0,11,0,12,0,13,0,14,0,255,0,255,0}; - uint8_t blackwhite[] = {232,255,234,255,236,255,238,255,240,255,242,255,244,255,246,0,248,0,249,0,250,0,251,0,252,0,253,0,254,0,255,0}; - uint8_t bluered[] = {235,255,63,255,57,255,93,255,129,255,165,255,201,255,200,255,199,255,198,255,197,255,196,255,196,255,196,255,196,255,196,255}; - uint8_t *schemes[] = {original,blackwhite,bluered}; - uint8_t *background = schemes[scheme]+0; - uint8_t *foreground = schemes[scheme]+1; - if (value > 0) while (value--) { - if (background+2=0;t--) { - if (array[t]!=0) { - if (array[t]!=array[x]) { - // merge is not possible, take next position - return t+1; - } - return t; - } else { - // we should not slide further, return this one - if (t==stop) { - return t; - } - } - } - // we did not find a - return x; -} - -bool slideArray(uint8_t array[SIZE]) { - bool success = false; - uint8_t x,t,stop=0; - - for (x=0;x0) return false; - if (findPairDown(board)) return false; - rotateBoard(board); - if (findPairDown(board)) ended = false; - rotateBoard(board); - rotateBoard(board); - rotateBoard(board); - return ended; -} - -void addRandom(uint8_t board[SIZE][SIZE]) { - static bool initialized = false; - uint8_t x,y; - uint8_t r,len=0; - uint8_t n,list[SIZE*SIZE][2]; - - if (!initialized) { - srand(time(NULL)); - initialized = true; - } - - for (x=0;x0) { - r = rand()%len; - x = list[r][0]; - y = list[r][1]; - n = (rand()%10)/9+1; - board[x][y]=n; - } -} - -void initBoard(uint8_t board[SIZE][SIZE]) { - uint8_t x,y; - for (x=0;x "); - for (i=0;i "); - for (i=0;i