Add a buggy implementation
This commit is contained in:
parent
57e15bbaf7
commit
5f50f58ce9
94
2048.c
94
2048.c
|
@ -39,34 +39,74 @@ void game_destroy(Game game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t game_move(Game *game, Direction direction) {
|
uint8_t game_move(Game *game, Direction direction) {
|
||||||
// setting up stuff for my funny two-way for loop
|
// just one direction for testing purposes
|
||||||
// well technically speaking about 4-way because there
|
for (int i = 0; i < game->field_size_y; i++) {
|
||||||
// are two 2-way for loops
|
uint16_t **field = game->field;
|
||||||
/*
|
// move everything on one side
|
||||||
int8_t y_dir = 0;
|
for (int j = 0; j < game->field_size_x - 1; j++) {
|
||||||
int8_t x_dir = 0;
|
// a, b is the same as i and j. It is just flipped when
|
||||||
size_t start_y = 0;
|
// it does not go horizontally so I can access stuff vertically
|
||||||
size_t start_x = 0;
|
int a = i;
|
||||||
switch(direction) {
|
int b = j;
|
||||||
case NoDirection:
|
if (direction == Up || direction == Down) {
|
||||||
return 0;
|
a = j;
|
||||||
case Up:
|
b = i;
|
||||||
y_dir = -1;
|
}
|
||||||
start_y = game->field_size - 1;
|
|
||||||
break;
|
// make it so it can work with different directions
|
||||||
case Down:
|
int directionality = b; // TODO: rename ugly name
|
||||||
y_dir = 1;
|
int movement = 1;
|
||||||
break;
|
if (direction == Left || direction == Up) {
|
||||||
case Left:
|
directionality = game->field_size_x - b - 1;
|
||||||
x_dir = -1;
|
movement = -1;
|
||||||
start_x = game->field_size - 1;
|
}
|
||||||
break;
|
if(field[a][directionality + movement] == 0) {
|
||||||
case Right:
|
field[a][directionality+movement] = field[a][directionality];
|
||||||
x_dir = 1;
|
field[a][directionality] = 0;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
// combine same numbers
|
||||||
|
for (int j = 0; j < game->field_size_x - 1; j++) {
|
||||||
|
int a = i;
|
||||||
|
int b = j;
|
||||||
|
if (direction == Up || direction == Down) {
|
||||||
|
a = j;
|
||||||
|
b = i;
|
||||||
|
}
|
||||||
|
int directionality = b;
|
||||||
|
int movement = 1;
|
||||||
|
if (direction == Left) {
|
||||||
|
directionality = game->field_size_x - b - 1;
|
||||||
|
movement = -1;
|
||||||
|
}
|
||||||
|
if(field[a][directionality + movement] == field[a][directionality]) {
|
||||||
|
field[a][directionality+movement] = field[a][directionality]*2;
|
||||||
|
field[a][directionality] = 0;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move everything again
|
||||||
|
for (int j = 0; j < game->field_size_x - 1; j++) {
|
||||||
|
int a = i;
|
||||||
|
int b = j;
|
||||||
|
if (direction == Up || direction == Down) {
|
||||||
|
a = j;
|
||||||
|
b = i;
|
||||||
|
}
|
||||||
|
int directionality = b;
|
||||||
|
int movement = 1;
|
||||||
|
if (direction == Left) {
|
||||||
|
directionality = game->field_size_x - b - 1;
|
||||||
|
movement = -1;
|
||||||
|
}
|
||||||
|
if(field[a][directionality + movement] == 0) {
|
||||||
|
field[a][directionality+movement] = field[a][directionality];
|
||||||
|
field[a][directionality] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
game_add_block(*game);
|
game_add_block(*game);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue