commit 1c24ed4670f03d7029fd2b16e0a89a63621713dc Author: David Vereb Date: Sun Apr 2 10:09:17 2023 -0400 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..26a8599 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.o +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ce5bc1e --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +build/apad: main.cpp + mkdir -p build + clang++ -g -O0 -std=c++17 -o $@ $? -lncurses + +clean: + rm build/apad + rmdir build/ diff --git a/Pieces.h b/Pieces.h new file mode 100644 index 0000000..c6c12a2 --- /dev/null +++ b/Pieces.h @@ -0,0 +1,67 @@ +#ifndef APAD_PIECES_H +#define APAD_PIECES_H + +#include + +#define NUM_PIECES 8 +typedef uint8_t Piece; // only need literally 8, not 8 bits, but hey. + +#define PIECE_ONE 0x0 +/* + * [][][] + * [][][] + */ + +#define PIECE_TWO 0x1 +/* + * [] + * [][] + * [] + * [] + */ + +#define PIECE_TRHEE 0x2 +/* + * [] + * [] + * [] + * [][] + */ + +#define PIECE_FOUR 0x3 +/* + * [][] + * [] + * [][] + */ + +#define PIECE_FIVE 0x4 +/* + * [][] + * [] + * [][] + */ + +#define PIECE_SIX 0x5 +/* + * [][] + * [][][] + */ + +#define PIECE_SEVEN 0x6 +/* + * [][] + * [][] + * [] + */ + +#define PIECE_EIGHT 0x7 +/* + * [] + * [] + * [][][] + */ + +void DrawPiece(const Piece &piece, int y, int x); + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..008fdf6 --- /dev/null +++ b/main.cpp @@ -0,0 +1,58 @@ +#include "Pieces.h" + +#include +#include + +#include +#include + +static void finish(int sig); +void init_colors(); + +int main(int argc, char *argv[]) +{ + initscr(); /* initialize the curses library */ + keypad(stdscr, TRUE); /* enable keyboard mapping */ + nonl(); /* tell curses not to do NL->CR/NL on output */ + cbreak(); /* take input chars one at a time, no wait for \n */ + echo(); /* echo input - in color */ + + if(has_colors()) + init_colors(); + + int num = 0; + while(true) + { + int c = getch(); /* refresh, accept single keystroke of input */ + attrset(COLOR_PAIR(num++ % 8)); + + /* process the command keystroke */ + } + + finish(0); +} + +// NOTE(dev): ALways execute so we don't screw up our terminal. +static void finish(int sig) +{ + endwin(); +} + +void init_colors() +{ + start_color(); + + /* + * Simple color assignment, often all we need. Color pair 0 cannot + * be redefined. This example uses the same value for the color + * pair as for the foreground color, though of course that is not + * necessary: + */ + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_YELLOW, COLOR_BLACK); + init_pair(4, COLOR_BLUE, COLOR_BLACK); + init_pair(5, COLOR_CYAN, COLOR_BLACK); + init_pair(6, COLOR_MAGENTA, COLOR_BLACK); + init_pair(7, COLOR_WHITE, COLOR_BLACK); +}