Initial Commit

This commit is contained in:
David Vereb 2023-04-02 10:09:17 -04:00
commit 1c24ed4670
4 changed files with 135 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*~
*.o
build/

7
Makefile Normal file
View File

@ -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/

67
Pieces.h Normal file
View File

@ -0,0 +1,67 @@
#ifndef APAD_PIECES_H
#define APAD_PIECES_H
#include <stdint.h>
#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

58
main.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "Pieces.h"
#include <curses.h>
#include <signal.h>
#include <string>
#include <unordered_map>
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);
}