4
* Copyright © 2003 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
27
extend namespace Server {
28
public namespace Show {
29
void show_first_object (file f, &Object o) {
31
File::fprintf (f, " ===");
33
File::fprintf (f, " ");
36
void show_color (file f, Color c, bool active) {
39
case Color.Red: ch = 'r'; break;
40
case Color.Yellow: ch = 'y'; break;
41
case Color.Green: ch = 'g'; break;
42
case Color.Blue: ch = 'b'; break;
43
case Color.Whirl: ch = 'w'; break;
46
ch = Ctype::toupper (ch);
47
File::fprintf (f, "%c", ch);
50
void show_shape (file f, Shape s, bool active) {
53
case Shape.Triangle: ch = 't'; break;
54
case Shape.Square: ch = 's'; break;
55
case Shape.Octagon: ch = 'o'; break;
56
case Shape.Circle: ch = 'c'; break;
57
case Shape.Whirl: ch = 'w'; break;
60
ch = Ctype::toupper (ch);
61
File::fprintf (f, "%c", ch);
64
void show_second_object (file f, &Object o) {
66
File::fprintf (f, "|");
68
File::fprintf (f, " ");
69
union switch (o.robot) {
71
File::fprintf (f, ".");
74
show_color (f, r.color, r.active);
77
union switch (o.target) {
79
File::fprintf (f, "..");
82
show_color (f, t.color, t.active);
83
show_shape (f, t.shape, t.active);
88
void show_last_col (file f, &Object o) {
90
File::fprintf (f, "|");
92
File::fprintf (f, " ");
93
File::fprintf (f, "\n");
96
void show_first_row (file f, &Board b, int row) {
97
for (int col = 0; col < Width; col++)
98
show_first_object (f, &b[col,row]);
99
File::fprintf (f, " \n");
101
void show_second_row (file f, &Board b, int row) {
102
for (int col = 0; col < Width; col++)
103
show_second_object (f, &b[col,row]);
104
show_last_col (f, &b[Width-1,row]);
106
void show_row (file f, &Board b, int row) {
107
show_first_row (f, &b, row);
108
show_second_row (f, &b, row);
110
void show_last_row (file f, &Board b) {
111
for (int col = 0; col < Width; col++)
113
if (b[col,Height-1].walls.below)
114
File::fprintf (f, " ===");
116
File::fprintf (f, " ");
118
File::fprintf (f, " ");
121
public void show (file f, &Board b) {
122
for (int row = 0; row < Height; row++)
123
show_row (f, &b, row);
124
show_last_row (f, &b);