Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions src/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ string tokenize(const std::vector<int> &arr) {
return out;
}

void printColored(WINDOW* box, int colorPairVal, vector<int>& token) {
wattron(box, COLOR_PAIR(colorPairVal));
mvwaddstr(box, 1, 0, tokenize(token).c_str());
wattroff(box, COLOR_PAIR(colorPairVal));
}

void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
int leny, int lenx) {

Expand All @@ -50,10 +56,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
newwin(line, col, line * 2 + height_adjusting_factor, centering_factor);

if (gamestate[0] == 0) {
mvwaddstr(box1, 1, 0, tokenize(tokenX).c_str());
printColored(box1, 1, tokenX);
}
if (gamestate[0] == 1) {
mvwaddstr(box1, 1, 0, tokenize(tokenO).c_str());
printColored(box1, 2, tokenO);
}
box(box1, 0, 0);
mvwaddch(box1, line - 1, col - 2, '1');
Expand All @@ -63,10 +69,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
col + centering_factor);

if (gamestate[1] == 0) {
mvwaddstr(box2, 1, 0, tokenize(tokenX).c_str());
printColored(box2, 1, tokenX);
}
if (gamestate[1] == 1) {
mvwaddstr(box2, 1, 0, tokenize(tokenO).c_str());
printColored(box2, 2, tokenO);
}
box(box2, 0, 0);
mvwaddch(box2, line - 1, col - 2, '2');
Expand All @@ -76,10 +82,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
col * 2 + centering_factor);

if (gamestate[2] == 0) {
mvwaddstr(box3, 1, 0, tokenize(tokenX).c_str());
printColored(box3, 1, tokenX);
}
if (gamestate[2] == 1) {
mvwaddstr(box3, 1, 0, tokenize(tokenO).c_str());
printColored(box3, 2, tokenO);
}
box(box3, 0, 0);
mvwaddch(box3, line - 1, col - 2, '3');
Expand All @@ -89,10 +95,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
newwin(line, col, line + height_adjusting_factor, centering_factor);

if (gamestate[3] == 0) {
mvwaddstr(box4, 1, 0, tokenize(tokenX).c_str());
printColored(box4, 1, tokenX);
}
if (gamestate[3] == 1) {
mvwaddstr(box4, 1, 0, tokenize(tokenO).c_str());
printColored(box4, 2, tokenO);
}
box(box4, 0, 0);
mvwaddch(box4, line - 1, col - 2, '4');
Expand All @@ -102,10 +108,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
newwin(line, col, line + height_adjusting_factor, col + centering_factor);

if (gamestate[4] == 0) {
mvwaddstr(box5, 1, 0, tokenize(tokenX).c_str());
printColored(box5, 1, tokenX);
}
if (gamestate[4] == 1) {
mvwaddstr(box5, 1, 0, tokenize(tokenO).c_str());
printColored(box5, 2, tokenO);
}
box(box5, 0, 0);
mvwaddch(box5, line - 1, col - 2, '5');
Expand All @@ -115,10 +121,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
col * 2 + centering_factor);

if (gamestate[5] == 0) {
mvwaddstr(box6, 1, 0, tokenize(tokenX).c_str());
printColored(box6, 1, tokenX);
}
if (gamestate[5] == 1) {
mvwaddstr(box6, 1, 0, tokenize(tokenO).c_str());
printColored(box6, 2, tokenO);
}
box(box6, 0, 0);
mvwaddch(box6, line - 1, col - 2, '6');
Expand All @@ -127,10 +133,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
WINDOW *box7 = newwin(line, col, height_adjusting_factor, centering_factor);

if (gamestate[6] == 0) {
mvwaddstr(box7, 1, 0, tokenize(tokenX).c_str());
printColored(box7, 1, tokenX);
}
if (gamestate[6] == 1) {
mvwaddstr(box7, 1, 0, tokenize(tokenO).c_str());
printColored(box7, 2, tokenO);
}
box(box7, 0, 0);
mvwaddch(box7, line - 1, col - 2, '7');
Expand All @@ -140,10 +146,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
newwin(line, col, height_adjusting_factor, col + centering_factor);

if (gamestate[7] == 0) {
mvwaddstr(box8, 1, 0, tokenize(tokenX).c_str());
printColored(box8, 1, tokenX);
}
if (gamestate[7] == 1) {
mvwaddstr(box8, 1, 0, tokenize(tokenO).c_str());
printColored(box8, 2, tokenO);
}
box(box8, 0, 0);
mvwaddch(box8, line - 1, col - 2, '8');
Expand All @@ -153,10 +159,10 @@ void Board::drawBoard(std::vector<int> gamestate, Board *gameBoard, WINDOW *win,
newwin(line, col, height_adjusting_factor, col * 2 + centering_factor);

if (gamestate[8] == 0) {
mvwaddstr(box9, 1, 0, tokenize(tokenX).c_str());
printColored(box9, 1, tokenX);
}
if (gamestate[8] == 1) {
mvwaddstr(box9, 1, 0, tokenize(tokenO).c_str());
printColored(box9, 2, tokenO);
}

box(box9, 0, 0);
Expand Down
4 changes: 4 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ void Game::play() {

if (myToken == 0) {
mvwprintw(infowin, 0, 0, "I go first!");
init_pair(1, COLOR_RED, -1);
init_pair(2, COLOR_GREEN, -1);
} else {
mvwprintw(infowin, 0, 0, "You go first!");
init_pair(1, COLOR_GREEN, -1);
init_pair(2, COLOR_RED, -1);
}
wrefresh(infowin);

Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ int main(int argc, char **argv) {
initscr();
cbreak();

/* Initialize colors */
start_color();
use_default_colors();

while (1) {
vector<int> startingState = {-1, -1, -1, -1, -1, -1, -1, -1, -1};
Game game = Game(startingState);
Expand Down