From b9d9035be2a0b958ea62f60f96d88256148cdafc Mon Sep 17 00:00:00 2001 From: pwindas Date: Mon, 11 Jul 2016 10:03:43 -0400 Subject: [PATCH 1/2] Add files via upload --- proposal.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 proposal.txt diff --git a/proposal.txt b/proposal.txt new file mode 100644 index 0000000..e35ce94 --- /dev/null +++ b/proposal.txt @@ -0,0 +1,16 @@ +For my final project, I wish to create the game of 2048. 2048 is a simple game played on phones tablets and computers. It is composed of a 4x4 grid that has numbers filling in the spaces. The game begins by creating two random blocks- either a two or a four- anywhere on the board. After that, you simply combine the same blocks to create a bigger block. Ex: a 2 and a 2 would create a 4, a 4 and a 4 would create an eight and etc. Also, every time you swipe the board (left, right, up or down) a new block spawns in. In terms of the program itself, here's what I have planned: +variables/data types - I will use these throughout the program to create a lot of things. Examples include math equations such as (x*2) and etc. + +input/output - the user will have to input a move (right, left, up, down) and the output will be a completely new board with the new numbers assembled. + +conditional statements - similar to variables, I will be using a lot of conditional statements tthroughout the program. An example could be if (space == 0) { + return 0; +This would tell the program that if there is a block on an edge, and a move is called to move it in the directions of the edge, it won't do anything. + +loops - Loops are going to be really helpful especially when dealing with the movement of the blocks themselves. I will use conditional statements along with loops to assign each block in the grid a variable name and write lines that will give them parameters. I think the hardest part of this program will be to have all the numbers on the board to correctly move. + +functions - As someone with OCD, I'm going to try and make this code really neat and clean. By using functions to organize all parts of program, I hope to keep it easily readable. + +Arrays/Strings - If I dont create an equation to mae the blocks properly multiple, I plan to just make an array or string of the numbers so I can just have them called during the game. + +Advanced data types - In terms of structures and enumerated lists, I don't really know where I'll use them. As I progress in my code, I think I'll reach a point where I'll simply need to use one. If you have any ideas right off the bat though I'm all ears. From 3a81061224876a8a1d73e699fd0ddd1140333a4f Mon Sep 17 00:00:00 2001 From: pwindas Date: Fri, 15 Jul 2016 15:33:33 -0400 Subject: [PATCH 2/2] Add files via upload --- 2048.c | 427 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.txt | 1 + 2 files changed, 428 insertions(+) create mode 100644 2048.c create mode 100644 README.txt diff --git a/2048.c b/2048.c new file mode 100644 index 0000000..f96094e --- /dev/null +++ b/2048.c @@ -0,0 +1,427 @@ +#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) { // this is a function that gives the board itself coloring for each tile. I used the internet for this once I completed the base game. + 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]) { //random tile function + 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