-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.cpp
66 lines (59 loc) · 1.75 KB
/
print.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <ncurses.h>
#include "board.hpp"
#include "color.hpp"
#include "colormanager.hpp"
#include "print.hpp"
#include "reversi.hpp"
namespace roadagain
{
void print_stone(const Cell& cell, bool coordinate)
{
char stone;
switch (cell.color){
case CellColor::EMPTY:
ColorManager::instance().change_color(ColorManager::BOARD);
stone = ' ';
break;
case CellColor::BLACK:
ColorManager::instance().change_color(ColorManager::BLACK);
stone = 'o';
break;
case CellColor::WHITE:
ColorManager::instance().change_color(ColorManager::WHITE);
stone = 'x';
break;
default:
stone = '\0';
break;
}
mvaddch(cell.point.y * 2 + 1 + Board::START.y, cell.point.x * 3 + 1 + Board::START.x, stone);
addch(stone);
ColorManager::instance().change_color(ColorManager::BOARD);
if (coordinate){
print_coordinate(cell.point);
}
else {
clear_coordinate(cell.point);
}
}
void clear_stone(const Point& p)
{
print_stone(Cell(p, CellColor::EMPTY), false);
}
void print_coordinate(const Point& p)
{
mvaddch(p.y * 2 + 1 + Board::START.y, 0, '1' + p.y);
mvaddch(p.y * 2 + 1 + Board::START.x, Board::END.x + 1, '1' + p.y);
mvaddch(0, p.x * 3 + 1 + Board::START.x, 'a' + p.x);
mvaddch(Board::END.y + 1, p.x * 3 + 2 + Board::START.x, 'a' + p.x);
}
void clear_coordinate(const Point& p)
{
attrset(0);
mvaddch(p.y * 2 + 1 + Board::START.y, 0, ' ');
mvaddch(p.y * 2 + 1 + Board::START.y, Board::END.x + 1, ' ');
mvaddch(0, p.x * 3 + 1 + Board::START.x, ' ');
mvaddch(Board::END.y + 1, p.x * 3 + 2 + Board::START.x, ' ');
ColorManager::instance().change_color(ColorManager::BOARD);
}
} // namespace roadagain