]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - dab/box.cc
1 /* $NetBSD: box.cc,v 1.2 2005/08/09 02:38:32 christos Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
40 * box.C: Box computations
43 RCSID("$NetBSD: box.cc,v 1.2 2005/08/09 02:38:32 christos Exp $")
47 #include "gamescreen.h"
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
};
58 BOX::BOX(size_t py
, size_t px
, BOARD
& b
) :
61 _centery
= py
* 2 + 1;
62 _centerx
= px
* 2 + 1;
65 void BOX::addcorner(size_t y
, size_t x
)
68 _b
.getScrn()->moveto(y
, x
);
71 sym
= GAMESCREEN::GS_ULCORNER
;
72 else if (y
== _b
.ty() - 1)
73 sym
= GAMESCREEN::GS_LLCORNER
;
75 sym
= GAMESCREEN::GS_LTEE
;
76 } else if (x
== _b
.tx() - 1) {
78 sym
= GAMESCREEN::GS_URCORNER
;
79 else if (y
== _b
.ty() - 1)
80 sym
= GAMESCREEN::GS_LRCORNER
;
82 sym
= GAMESCREEN::GS_RTEE
;
84 sym
= GAMESCREEN::GS_TTEE
;
85 else if (y
== _b
.ty() - 1)
86 sym
= GAMESCREEN::GS_BTEE
;
88 sym
= GAMESCREEN::GS_PLUS
;
90 _b
.getScrn()->addedge(sym
);
97 if (_b
.getScrn() == NULL
)
100 _b
.getScrn()->moveto(_centery
, _centerx
);
101 _b
.getScrn()->addsym(name());
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(static_cast<EDGE
>(e
)));
108 _b
.getScrn()->redraw();
114 return _b
.data(_centery
, _centerx
);
120 _b
.data(_centery
+ edges
[e
].y
, _centerx
+ edges
[e
].x
) = syms
[e
];
126 _b
.data(_centery
+ edges
[e
].y
, _centerx
+ edges
[e
].x
) = ' ';
130 int BOX::isset(int e
) const
132 return _b
.data(_centery
+ edges
[e
].y
, _centerx
+ edges
[e
].x
) != ' ';
136 int& BOX::edge(int e
)
138 return _b
.data(_centery
+ edges
[e
].y
, _centerx
+ edges
[e
].x
);
141 // Count the number of edges set in the box
142 int BOX::count(void) const
146 for (int e
= BOX::first
; e
< BOX::last
; e
++)
147 cnt
+= isset(static_cast<EDGE
>(e
));
152 void BOX::reset(void)
154 for (int e
= BOX::first
; e
< BOX::last
; e
++)
155 clr(static_cast<EDGE
>(e
));