Initial commit

This commit is contained in:
David Husicka 2021-11-15 09:57:27 +01:00
commit ce51ffe35f
9 changed files with 149 additions and 0 deletions

0
.gitignore vendored Normal file
View File

17
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64",
"compileCommands": "${workspaceFolder}/builddir/compile_commands.json"
}
],
"version": 4
}

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/builddir/2048",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

24
2048.c Normal file
View File

@ -0,0 +1,24 @@
#include "2048.h"
Game game_init(size_t field_size) {
Game game;
game.field_size = field_size;
game.score = 0;
game.field = malloc(sizeof(uint16_t *) * field_size);
for (size_t i = 0; i < field_size; i++) {
game.field[i] = calloc(field_size, sizeof(uint16_t) * field_size);
}
return game;
}
void game_destroy(Game game) {
for (size_t i = 0; i < game.field_size; i++) {
free(game.field[i]);
}
free(game.field);
game.field = NULL;
}
uint8_t game_move(Game *game, Direction direction) {
return 0;
}

25
2048.h Normal file
View File

@ -0,0 +1,25 @@
#include <stdint.h>
#include <stdlib.h>
#ifndef HEADER_2048
#define HEADER_2048
typedef enum Direction {
up,
down,
right,
left
} Direction;
typedef struct Game
{
uint32_t score;
size_t field_size;
uint16_t **field;
} Game;
Game game_init(size_t field_size);
uint8_t game_move(Game *game, Direction direction);
void game_destroy(Game game);
#endif

16
main.c Normal file
View File

@ -0,0 +1,16 @@
#include "SDL.h"
#include "tui.h"
#include "2048.h"
int main(int argc, char *argv[])
{
Game game;
game = game_init(4);
tui_init();
tui_loop(&game);
tui_destroy();
game_destroy(game);
return 0;
}

12
meson.build Normal file
View File

@ -0,0 +1,12 @@
project('2048', 'c')
sdl2 = dependency('sdl2')
ncurses = dependency('ncurses')
src_2048 = [
'2048.c',
'tui.c',
'main.c',
]
executable('2048', src_2048, dependencies: [sdl2, ncurses])

25
tui.c Normal file
View File

@ -0,0 +1,25 @@
#include "tui.h"
#include <stdio.h>
#include <curses.h>
// entering and leaving screen using ANSI escape sequence
void tui_init() {
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
}
void tui_destroy() {}
void tui_loop(Game *game) {
while(true){
char input = getch();
// up - 3, 107, 56
// down - 2, 106, 50
// left - 4, 104, 52
// right - 5, 108, 54
// fprintf(stderr, "%d", input);
}
}

14
tui.h Normal file
View File

@ -0,0 +1,14 @@
#include "2048.h"
#ifndef HEADER_TUI
#define HEADER_TUI
typedef struct TUI {
} TUI;
void tui_init();
void tui_destroy();
void tui_loop(Game *game);
#endif