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: #include "defs.h"
43: RCSID("$NetBSD: box.cc,v 1.1 2003/12/27 01:16:55 christos Exp $")
44:
45: #include "box.h"
46: #include "board.h"
47: #include "gamescreen.h"
48: #include <curses.h>
49:
50: const POINT BOX::edges[BOX::last] =
51: { { 0, -1 }, { 0, 1 }, { -1, 0 }, { 1, 0 } };
52: const POINT BOX::corners[BOX::last] =
53: { { -1, -1 }, { -1, 1 }, { 1, -1 }, { 1, 1 } };
54: const int BOX::syms[BOX::last] =
55: { GAMESCREEN::GS_HLINE, GAMESCREEN::GS_HLINE,
56: GAMESCREEN::GS_VLINE, GAMESCREEN::GS_VLINE };
57:
58: BOX::BOX(size_t py, size_t px, BOARD& b) :
59: _b(b)
60: {
61: _centery = py * 2 + 1;
62: _centerx = px * 2 + 1;
63: }
64:
65: void BOX::addcorner(size_t y, size_t x)
66: {
67: char sym;
68: _b.getScrn()->moveto(y, x);
69: if (x == 0) {
70: if (y == 0)
71: sym = GAMESCREEN::GS_ULCORNER;
72: else if (y == _b.ty() - 1)
73: sym = GAMESCREEN::GS_LLCORNER;
74: else
75: sym = GAMESCREEN::GS_LTEE;
76: } else if (x == _b.tx() - 1) {
77: if (y == 0)
78: sym = GAMESCREEN::GS_URCORNER;
79: else if (y == _b.ty() - 1)
80: sym = GAMESCREEN::GS_LRCORNER;
81: else
82: sym = GAMESCREEN::GS_RTEE;
83: } else if (y == 0)
84: sym = GAMESCREEN::GS_TTEE;
85: else if (y == _b.ty() - 1)
86: sym = GAMESCREEN::GS_BTEE;
87: else
88: sym = GAMESCREEN::GS_PLUS;
89:
90: _b.getScrn()->addedge(sym);
91: }
92:
93:
94: void BOX::paint(void)
95: {
96: int e;
97: if (_b.getScrn() == NULL)
98: return;
99:
100: _b.getScrn()->moveto(_centery, _centerx);
101: _b.getScrn()->addsym(name());
102:
103: for (e = BOX::first; e < BOX::last; e++) {
104: addcorner(_centery + corners[e].y, _centerx + corners[e].x);
105: _b.getScrn()->moveto(_centery + edges[e].y, _centerx + edges[e].x);
106: _b.getScrn()->addedge(edge((EDGE) e));
107: }
108: _b.getScrn()->redraw();
109: }
110:
111:
112: int& BOX::name(void)
113: {
114: return _b.data(_centery, _centerx);
115: }
116:
117:
118: void BOX::set(int e)
119: {
120: _b.data(_centery + edges[e].y, _centerx + edges[e].x) = syms[e];
121: }
122:
123:
124: void BOX::clr(int e)
125: {
126: _b.data(_centery + edges[e].y, _centerx + edges[e].x) = ' ';
127: }
128:
129:
130: int BOX::isset(int e) const
131: {
132: return _b.data(_centery + edges[e].y, _centerx + edges[e].x) != ' ';
133: }
134:
135:
136: int& BOX::edge(int e)
137: {
138: return _b.data(_centery + edges[e].y, _centerx + edges[e].x);
139: }
140:
141:
142: int BOX::count(void) const
143: {
144: int cnt = 0;
145:
146: for (int e = BOX::first; e < BOX::last; e++)
147: cnt += isset((EDGE) e);
148: return cnt;
149: }
150:
151:
152: void BOX::reset(void)
153: {
154: for (int e = BOX::first; e < BOX::last; e++)
155: clr((EDGE) e);
156: name() = ' ';
157: }