Grid made. x displayed

This commit is contained in:
xavi 2026-01-02 16:41:22 -08:00
parent f4a8a340a6
commit d80bdc6f51
9 changed files with 286 additions and 15 deletions

View File

@ -27,7 +27,7 @@ STATIC_LIBS = $(shell find ./ -name "*.a")
CC := gcc
INCLUDE_LIST := $(foreach m,$(SUBMODULES),$(m)/$(INCLUDE_DIR)) $(INCLUDE_DIR) $(TESTS_INCL_DIR)
INCLUDES := $(addprefix -I,$(INCLUDE_LIST))
CFLAGS := -ggdb -Wall -Wextra -MMD -MP -lncurses -fsanitize=address
CFLAGS := -std=c99 -ggdb -Wall -Wextra -MMD -MP -lncurses -fsanitize=address
DFLAGS := -D_DEBUG
# Main Executable Filename

View File

@ -5,10 +5,25 @@
#include <stdint.h>
#define GRIDSIZE 3
#define HEADERSIZE 5
#define FOOTERSIZE 5
extern const char part;
extern const char game_end;
void draw_initial_board(WINDOW*);
typedef struct w_data_t{
WINDOW *w_ptr;
int height;
int width;
}w_data_t;
// gamelogic
int start_tiktaktoe(void);
void get_input(w_data_t *board);
// render
void init_windows(w_data_t *board, w_data_t *header, w_data_t *footer);
void create_grid(w_data_t *currwin);
void draw_board(w_data_t *board, w_data_t *header, w_data_t *footer);
#endif

View File

@ -0,0 +1,2 @@
obj/main.o: src/main.c include/tiktaktoe.h
include/tiktaktoe.h:

Binary file not shown.

View File

@ -0,0 +1,2 @@
obj/tiktaktoe.o: src/tiktaktoe.c include/tiktaktoe.h
include/tiktaktoe.h:

Binary file not shown.

View File

@ -1,30 +1,79 @@
#include "tiktaktoe.h"
const char part = '-';
const char game_end = 0;
int start_tiktaktoe(void){
WINDOW *board = NULL;
w_data_t header;
w_data_t board;
w_data_t footer;
initscr();
draw_initial_board(board);
init_windows(&board, &header, &footer);
getch();
while (!game_end){
get_input(&board);
draw_board(&board, &header, &footer);
}
wgetch(board.w_ptr);
endwin();
return 0;
}
void draw_initial_board(WINDOW *board){
void get_input(w_data_t *w){
char s = wgetch(w->w_ptr);
if (s == 'w'){
mvwprintw(w->w_ptr, w->height / 2, w->width / 2, "x");
}
}
void init_windows(w_data_t *board, w_data_t *header, w_data_t *footer){
const int board_size = LINES - HEADERSIZE - FOOTERSIZE;
header->w_ptr = newwin(HEADERSIZE,0,0,0);
board->w_ptr = newwin(board_size,0,HEADERSIZE,0);
footer->w_ptr = newwin(FOOTERSIZE,0,HEADERSIZE + board_size,0);
getmaxyx(header->w_ptr, header->height, header->width);
getmaxyx(board->w_ptr, board->height, board->width);
getmaxyx(footer->w_ptr, footer->height, footer->width);
box(header->w_ptr, 0, 0);
box(footer->w_ptr, 0, 0);
box(board->w_ptr, 0, 0);
create_grid(board);
wrefresh(header->w_ptr);
wrefresh(board->w_ptr);
wrefresh(footer->w_ptr);
}
void create_grid(w_data_t *currwin){
int buffer = 10;
int hline_pos = 0;
int vline_pos = 0;
board = newwin(0,0,0,0);
for (int i = 0; i < GRIDSIZE - 1; i++){
hline_pos += LINES/GRIDSIZE;
mvwhline(board, hline_pos,0,0,COLS);
vline_pos += COLS/GRIDSIZE;
mvwvline(board, 0,vline_pos,0,LINES);
hline_pos += currwin->height/GRIDSIZE;
mvwhline(currwin->w_ptr, hline_pos, buffer,0,currwin->width - 2 * buffer);
}
for (int i = 0; i < GRIDSIZE - 1; i++){
vline_pos += currwin->width/GRIDSIZE;
mvwvline(currwin->w_ptr, buffer / 2,vline_pos,0,currwin->height - buffer);
}
wrefresh(board);
wgetch(board);
}
void draw_board(w_data_t *board, w_data_t *header, w_data_t *footer){
create_grid(board);
getmaxyx(header->w_ptr, header->height, header->width);
getmaxyx(board->w_ptr, board->height, board->width);
getmaxyx(footer->w_ptr, footer->height, footer->width);
wrefresh(header->w_ptr);
wrefresh(board->w_ptr);
wrefresh(footer->w_ptr);
}

203
c_projects/tiktaktoe/tags Normal file
View File

@ -0,0 +1,203 @@
!_TAG_EXTRA_DESCRIPTION anonymous /Include tags for non-named objects like lambda/
!_TAG_EXTRA_DESCRIPTION fileScope /Include tags of file scope/
!_TAG_EXTRA_DESCRIPTION inputFile /Include an entry for the base file name of every input file/
!_TAG_EXTRA_DESCRIPTION pseudo /Include pseudo tags/
!_TAG_EXTRA_DESCRIPTION subparser /Include tags generated by subparsers/
!_TAG_FIELD_DESCRIPTION epoch /the last modified time of the input file (only for F\/file kind tag)/
!_TAG_FIELD_DESCRIPTION file /File-restricted scoping/
!_TAG_FIELD_DESCRIPTION input /input file/
!_TAG_FIELD_DESCRIPTION name /tag name/
!_TAG_FIELD_DESCRIPTION pattern /pattern/
!_TAG_FIELD_DESCRIPTION typeref /Type and name of a variable or typedef/
!_TAG_FIELD_DESCRIPTION!C++ name /aliased names/
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_KIND_DESCRIPTION!C L,label /goto labels/
!_TAG_KIND_DESCRIPTION!C d,macro /macro definitions/
!_TAG_KIND_DESCRIPTION!C e,enumerator /enumerators (values inside an enumeration)/
!_TAG_KIND_DESCRIPTION!C f,function /function definitions/
!_TAG_KIND_DESCRIPTION!C g,enum /enumeration names/
!_TAG_KIND_DESCRIPTION!C h,header /included header files/
!_TAG_KIND_DESCRIPTION!C l,local /local variables/
!_TAG_KIND_DESCRIPTION!C m,member /struct, and union members/
!_TAG_KIND_DESCRIPTION!C p,prototype /function prototypes/
!_TAG_KIND_DESCRIPTION!C s,struct /structure names/
!_TAG_KIND_DESCRIPTION!C t,typedef /typedefs/
!_TAG_KIND_DESCRIPTION!C u,union /union names/
!_TAG_KIND_DESCRIPTION!C v,variable /variable definitions/
!_TAG_KIND_DESCRIPTION!C++ L,label /goto labels/
!_TAG_KIND_DESCRIPTION!C++ M,module /modules/
!_TAG_KIND_DESCRIPTION!C++ P,partition /partitions/
!_TAG_KIND_DESCRIPTION!C++ c,class /classes/
!_TAG_KIND_DESCRIPTION!C++ d,macro /macro definitions/
!_TAG_KIND_DESCRIPTION!C++ e,enumerator /enumerators (values inside an enumeration)/
!_TAG_KIND_DESCRIPTION!C++ f,function /function definitions/
!_TAG_KIND_DESCRIPTION!C++ g,enum /enumeration names/
!_TAG_KIND_DESCRIPTION!C++ h,header /included header files/
!_TAG_KIND_DESCRIPTION!C++ l,local /local variables/
!_TAG_KIND_DESCRIPTION!C++ m,member /class, struct, and union members/
!_TAG_KIND_DESCRIPTION!C++ n,namespace /namespaces/
!_TAG_KIND_DESCRIPTION!C++ p,prototype /function prototypes/
!_TAG_KIND_DESCRIPTION!C++ s,struct /structure names/
!_TAG_KIND_DESCRIPTION!C++ t,typedef /typedefs/
!_TAG_KIND_DESCRIPTION!C++ u,union /union names/
!_TAG_KIND_DESCRIPTION!C++ v,variable /variable definitions/
!_TAG_KIND_DESCRIPTION!D M,module /modules/
!_TAG_KIND_DESCRIPTION!D T,template /templates/
!_TAG_KIND_DESCRIPTION!D V,version /version statements/
!_TAG_KIND_DESCRIPTION!D X,mixin /mixins/
!_TAG_KIND_DESCRIPTION!D a,alias /aliases/
!_TAG_KIND_DESCRIPTION!D c,class /classes/
!_TAG_KIND_DESCRIPTION!D e,enumerator /enumerators (values inside an enumeration)/
!_TAG_KIND_DESCRIPTION!D f,function /function definitions/
!_TAG_KIND_DESCRIPTION!D g,enum /enumeration names/
!_TAG_KIND_DESCRIPTION!D i,interface /interfaces/
!_TAG_KIND_DESCRIPTION!D m,member /class, struct, and union members/
!_TAG_KIND_DESCRIPTION!D n,namespace /namespaces/
!_TAG_KIND_DESCRIPTION!D s,struct /structure names/
!_TAG_KIND_DESCRIPTION!D u,union /union names/
!_TAG_KIND_DESCRIPTION!D v,variable /variable definitions/
!_TAG_KIND_DESCRIPTION!Make I,makefile /makefiles/
!_TAG_KIND_DESCRIPTION!Make m,macro /macros/
!_TAG_KIND_DESCRIPTION!Make t,target /targets/
!_TAG_OUTPUT_EXCMD mixed /number, pattern, mixed, or combineV2/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_VERSION 1.1 /current.age/
!_TAG_PARSER_VERSION!C 1.1 /current.age/
!_TAG_PARSER_VERSION!C++ 2.2 /current.age/
!_TAG_PARSER_VERSION!D 0.0 /current.age/
!_TAG_PARSER_VERSION!Make 1.1 /current.age/
!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/
!_TAG_PROC_CWD /home/xtro/current_projects/code/c/tiktaktoe/c_projects/tiktaktoe/ //
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
!_TAG_PROGRAM_VERSION 6.2.1 /v6.2.1/
!_TAG_ROLE_DESCRIPTION!C!function foreigndecl /declared in foreign languages/
!_TAG_ROLE_DESCRIPTION!C!header local /local header/
!_TAG_ROLE_DESCRIPTION!C!header system /system header/
!_TAG_ROLE_DESCRIPTION!C!macro undef /undefined/
!_TAG_ROLE_DESCRIPTION!C!struct foreigndecl /declared in foreign languages/
!_TAG_ROLE_DESCRIPTION!C++!header exported /exported with "exported imported ..."/
!_TAG_ROLE_DESCRIPTION!C++!header imported /imported with "imported ..."/
!_TAG_ROLE_DESCRIPTION!C++!header local /local header/
!_TAG_ROLE_DESCRIPTION!C++!header system /system header/
!_TAG_ROLE_DESCRIPTION!C++!macro undef /undefined/
!_TAG_ROLE_DESCRIPTION!C++!module imported /imported with "imported ..."/
!_TAG_ROLE_DESCRIPTION!C++!module partOwner /used for specifying a partition/
!_TAG_ROLE_DESCRIPTION!C++!partition imported /imported with "imported ..."/
!_TAG_ROLE_DESCRIPTION!Make!makefile included /included/
!_TAG_ROLE_DESCRIPTION!Make!makefile optional /optionally included/
$(INCLUDE_DIR) Makefile /^$(SRC_DIR) $(OBJ_DIR) $(TESTS_DIR) $(INCLUDE_DIR) $(SUBMODULES_DIR):$/;" t
$(OBJ_DIR) Makefile /^$(SRC_DIR) $(OBJ_DIR) $(TESTS_DIR) $(INCLUDE_DIR) $(SUBMODULES_DIR):$/;" t
$(OBJ_DIR)/%.o Makefile /^$(OBJ_DIR)\/%.o: $(SRC_DIR)\/%.c$/;" t
$(OBJ_DIR)/%.o Makefile /^$(OBJ_DIR)\/%.o: $(TESTS_DIR)\/%.c $(OBJ)$/;" t
$(PROJECT_NAME) Makefile /^$(PROJECT_NAME): $(MAIN:%.c=$(OBJ_DIR)\/%.o) $(OBJ) check_submods$/;" t
$(PROJECT_NAME).a Makefile /^$(PROJECT_NAME).a: $(PROJECT_OBJ) check_submods$/;" t
$(SRC_DIR) Makefile /^$(SRC_DIR) $(OBJ_DIR) $(TESTS_DIR) $(INCLUDE_DIR) $(SUBMODULES_DIR):$/;" t
$(SRC_DIR)/$(MAIN) Makefile /^$(SRC_DIR)\/$(MAIN):$/;" t
$(SUBMODULES_DIR) Makefile /^$(SRC_DIR) $(OBJ_DIR) $(TESTS_DIR) $(INCLUDE_DIR) $(SUBMODULES_DIR):$/;" t
$(SUBMODULE_SLIB) Makefile /^$(SUBMODULE_SLIB): $/;" t
$(TESTS:$(TESTS_DIR)/%.c=%) Makefile /^$(TESTS:$(TESTS_DIR)\/%.c=%): %: $(OBJ_DIR)\/%.o $(OBJ) check_submods$/;" t
$(TESTS_DIR) Makefile /^$(SRC_DIR) $(OBJ_DIR) $(TESTS_DIR) $(INCLUDE_DIR) $(SUBMODULES_DIR):$/;" t
% Makefile /^$(TESTS:$(TESTS_DIR)\/%.c=%): %: $(OBJ_DIR)\/%.o $(OBJ) check_submods$/;" t
CC Makefile /^CC := gcc$/;" m
CFLAGS Makefile /^CFLAGS := -std=c99 -ggdb -Wall -Wextra -MMD -MP -lncurses -fsanitize=address$/;" m
DEPENDENCIES Makefile /^DEPENDENCIES := $(OBJ:%.o=%.d)$/;" m
DFLAGS Makefile /^DFLAGS := -D_DEBUG$/;" m
END tests/include/test.h /^typedef enum {START, END} header_opt;$/;" e enum:__anon431ebd300103
FAIL tests/include/test.h /^typedef enum {PASS, FAIL}rc_opt;$/;" e enum:__anon431ebd300203
FOOTERSIZE include/tiktaktoe.h /^#define FOOTERSIZE /;" d
GRIDSIZE include/tiktaktoe.h /^#define GRIDSIZE /;" d
HEADERSIZE include/tiktaktoe.h /^#define HEADERSIZE /;" d
INCLUDES Makefile /^INCLUDES := $(addprefix -I,$(INCLUDE_LIST))$/;" m
INCLUDE_DIR Makefile /^INCLUDE_DIR := include$/;" m
INCLUDE_LIST Makefile /^INCLUDE_LIST := $(foreach m,$(SUBMODULES),$(m)\/$(INCLUDE_DIR)) $(INCLUDE_DIR) $(TESTS_INCL_DIR)$/;" m
MAIN Makefile /^MAIN := main.c$/;" m
Makefile Makefile 1;" F epoch:1767240744
OBJ Makefile /^OBJ := $(SRC:$(SRC_DIR)\/%.c=$(OBJ_DIR)\/%.o)$/;" m
OBJ_DIR Makefile /^OBJ_DIR := obj$/;" m
PASS tests/include/test.h /^typedef enum {PASS, FAIL}rc_opt;$/;" e enum:__anon431ebd300203
PROJECT_NAME Makefile /^PROJECT_NAME := tiktaktoe$/;" m
PROJECT_OBJ Makefile /^PROJECT_OBJ := $(OBJ_DIR)\/$(PROJECT_NAME).o$/;" m
SRC Makefile /^SRC := $(filter-out $(SRC_DIR)\/$(MAIN), $(wildcard $(SRC_DIR)\/*.c))$/;" m
SRC_DIR Makefile /^SRC_DIR := src$/;" m
START tests/include/test.h /^typedef enum {START, END} header_opt;$/;" e enum:__anon431ebd300103
STATIC_LIBS Makefile /^STATIC_LIBS = $(shell find .\/ -name "*.a")$/;" m
SUBBARE Makefile /^SUBBARE := $(SUBMODULES:$(SUBMODULES_DIR)\/%=%)$/;" m
SUBMODULES Makefile /^SUBMODULES := $(wildcard $(SUBMODULES_DIR)\/*)$/;" m
SUBMODULES_DIR Makefile /^SUBMODULES_DIR := submodules$/;" m
SUBMODULE_SLIB Makefile /^SUBMODULE_SLIB := $(foreach m,$(SUBBARE),$(SUBMODULES_DIR)\/$(m)\/$(m).a)$/;" m
TEST tests/include/test.h /^#define TEST(/;" d
TEST tests/test.c /^TEST(fail){$/;" f
TEST tests/test.c /^TEST(segfault){$/;" f
TEST tests/test.c /^TEST(success){$/;" f
TESTS Makefile /^TESTS := $(wildcard $(TESTS_DIR)\/*.c)$/;" m
TESTS_DIR Makefile /^TESTS_DIR := tests$/;" m
TESTS_INCL_DIR Makefile /^TESTS_INCL_DIR := $(TESTS_DIR)\/include$/;" m
TIKTAKTOE_H include/tiktaktoe.h /^#define TIKTAKTOE_H$/;" d
X_GREEN tests/include/test.h /^#define X_GREEN /;" d
X_RED tests/include/test.h /^#define X_RED /;" d
X_RST tests/include/test.h /^#define X_RST /;" d
X_YELLOW tests/include/test.h /^#define X_YELLOW /;" d
__anon431ebd300103 tests/include/test.h /^typedef enum {START, END} header_opt;$/;" g
__anon431ebd300203 tests/include/test.h /^typedef enum {PASS, FAIL}rc_opt;$/;" g
all Makefile /^all: $(PROJECT_NAME)$/;" t
bmaxx include/tiktaktoe.h /^ int bmaxx;$/;" m struct:w_data_t typeref:typename:int
bmaxx src/tiktaktoe.c /^ int bmaxx = 0;$/;" l function:draw_board typeref:typename:int file:
bmaxy include/tiktaktoe.h /^ int bmaxy;$/;" m struct:w_data_t typeref:typename:int
bmaxy src/tiktaktoe.c /^ int bmaxy = 0;$/;" l function:draw_board typeref:typename:int file:
board src/tiktaktoe.c /^ w_data_t* board = NULL;$/;" l function:start_tiktaktoe typeref:typename:w_data_t * file:
board_size src/tiktaktoe.c /^ const int board_size = LINES - HEADERSIZE - FOOTERSIZE;$/;" l function:init_windows typeref:typename:const int file:
buffer src/tiktaktoe.c /^ int buffer = 10;$/;" l function:draw_board typeref:typename:int file:
check_submods Makefile /^check_submods: $(SUBMODULE_SLIB)$/;" t
clean Makefile /^clean:$/;" t
cpid tests/include/test.h /^ pid_t cpid = fork();$/;" l function:run_child typeref:typename:pid_t file:
dirs Makefile /^dirs: $(SRC_DIR) $(OBJ_DIR) $(TESTS_DIR) $(INCLUDE_DIR) $(SUBMODULES_DIR) $(SRC_DIR)\/$(MAIN)$/;" t
draw_board include/tiktaktoe.h /^void draw_board(w_data_t *board, w_data_t *header, w_data_t *footer);$/;" p typeref:typename:void
draw_board src/tiktaktoe.c /^void draw_board(w_data_t *board, w_data_t *header, w_data_t *footer){$/;" f typeref:typename:void
errors tests/include/test.h /^ int errors = 0;$/;" l function:run_tests typeref:typename:int file:
footer src/tiktaktoe.c /^ w_data_t* footer = NULL;$/;" l function:start_tiktaktoe typeref:typename:w_data_t * file:
head tests/include/test.h /^static testnode* head = NULL;$/;" v typeref:typename:testnode *
header src/tiktaktoe.c /^ w_data_t* header = NULL;$/;" l function:start_tiktaktoe typeref:typename:w_data_t * file:
header_opt tests/include/test.h /^typedef enum {START, END} header_opt;$/;" t typeref:enum:__anon431ebd300103
help Makefile /^help:$/;" t
hline_pos src/tiktaktoe.c /^ int hline_pos = 0;$/;" l function:draw_board typeref:typename:int file:
i tests/test.c /^ int i = 1;$/;" l function:TEST typeref:typename:int file:
init_windows src/tiktaktoe.c /^void init_windows(w_data_t *board, w_data_t *header, w_data_t *footer){$/;" f typeref:typename:void
main src/main.c /^int main(){$/;" f typeref:typename:int
main tests/test.c /^int main(void){$/;" f typeref:typename:int
main.c src/main.c 1;" F epoch:1766803538
main.d obj/main.d 1;" F epoch:1766865434
name tests/include/test.h /^ char* name;$/;" m struct:testnode typeref:typename:char *
next tests/include/test.h /^ struct testnode* next;$/;" m struct:testnode typeref:struct:testnode *
op tests/include/test.h /^ int (*op)(void);$/;" m struct:testnode typeref:typename:int (*)(void)
part src/tiktaktoe.c /^const char part = '-';$/;" v typeref:typename:const char
ppass_fail tests/include/test.h /^static void ppass_fail(rc_opt rc){$/;" f typeref:typename:void
presult tests/include/test.h /^static int presult(int status){$/;" f typeref:typename:int
ptest_headers tests/include/test.h /^static void ptest_headers(header_opt option){$/;" f typeref:typename:void
ptr tests/include/test.h /^static testnode* ptr = NULL;$/;" v typeref:typename:testnode *
rc tests/include/test.h /^ int rc = WEXITSTATUS(status);$/;" l function:presult typeref:typename:int file:
rc tests/include/test.h /^ int rc = ptr->op();$/;" l function:run_child typeref:typename:int file:
rc_opt tests/include/test.h /^typedef enum {PASS, FAIL}rc_opt;$/;" t typeref:enum:__anon431ebd300203
run_child tests/include/test.h /^static int run_child(){$/;" f typeref:typename:int
run_tests tests/include/test.h /^static int run_tests(){$/;" f typeref:typename:int
start_tiktaktoe include/tiktaktoe.h /^int start_tiktaktoe(void);$/;" p typeref:typename:int
start_tiktaktoe src/tiktaktoe.c /^int start_tiktaktoe(void){$/;" f typeref:typename:int
status tests/include/test.h /^ int status;$/;" l function:run_child typeref:typename:int file:
tail tests/include/test.h /^static testnode* tail = NULL;$/;" v typeref:typename:testnode *
test.c tests/test.c 1;" F epoch:1766557221
test.h tests/include/test.h 1;" F epoch:1766556714
testnode tests/include/test.h /^typedef struct testnode{$/;" s
testnode tests/include/test.h /^}testnode;$/;" t typeref:struct:testnode
tiktaktoe.c src/tiktaktoe.c 1;" F epoch:1767390945
tiktaktoe.d obj/tiktaktoe.d 1;" F epoch:1767390946
tiktaktoe.h include/tiktaktoe.h 1;" F epoch:1767390908
total_tests tests/include/test.h /^ int total_tests = 0;$/;" l function:run_tests typeref:typename:int file:
vline_pos src/tiktaktoe.c /^ int vline_pos = 0;$/;" l function:draw_board typeref:typename:int file:
w_data_t include/tiktaktoe.h /^typedef struct w_data_t{$/;" s
w_data_t include/tiktaktoe.h /^}w_data_t;$/;" t typeref:struct:w_data_t
w_ptr include/tiktaktoe.h /^ WINDOW *w_ptr;$/;" m struct:w_data_t typeref:typename:WINDOW *
x tests/test.c /^ int* x = NULL;$/;" l function:TEST typeref:typename:int * file:
y tests/test.c /^ int y = *x;$/;" l function:TEST typeref:typename:int file:

BIN
c_projects/tiktaktoe/tiktaktoe Executable file

Binary file not shown.