~ubuntu-branches/ubuntu/saucy/ricochet/saucy-proposed

« back to all changes in this revision

Viewing changes to ricochet-0.1/debian/ricochet/usr/share/ricochet/server-show.5c

  • Committer: Package Import Robot
  • Author(s): Keith Packard
  • Date: 2012-06-11 13:37:57 UTC
  • Revision ID: package-import@ubuntu.com-20120611133757-zn0ukd22vz56ymto
Tags: 0.3
* Improve appearance of board
* Fix user list when removing/adding same user

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id$
3
 
 *
4
 
 * Copyright © 2003 Keith Packard
5
 
 *
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.
15
 
 *
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.
23
 
 */
24
 
 
25
 
autoload Server
26
 
 
27
 
extend namespace Server {
28
 
    public namespace Show {
29
 
        void show_first_object (file f, &Object o) {
30
 
            if (o.walls.above)
31
 
                File::fprintf (f, " ===");
32
 
            else
33
 
                File::fprintf (f, "    ");
34
 
        }
35
 
        
36
 
        void show_color (file f, Color c, bool active) {
37
 
            int ch;
38
 
            switch (c) {
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;
44
 
            }
45
 
            if (active)
46
 
                ch = Ctype::toupper (ch);
47
 
            File::fprintf (f, "%c", ch);
48
 
        }
49
 
 
50
 
        void show_shape (file f, Shape s, bool active) {
51
 
            int ch;
52
 
            switch (s) {
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;
58
 
            }
59
 
            if (active)
60
 
                ch = Ctype::toupper (ch);
61
 
            File::fprintf (f, "%c", ch);
62
 
        }
63
 
        
64
 
        void show_second_object (file f, &Object o) {
65
 
            if (o.walls.left)
66
 
                File::fprintf (f, "|");
67
 
            else
68
 
                File::fprintf (f, " ");
69
 
            union switch (o.robot) {
70
 
            case none:
71
 
                File::fprintf (f, ".");
72
 
                break;
73
 
            case robot r:
74
 
                show_color (f, r.color, r.active);
75
 
                break;
76
 
            }
77
 
            union switch (o.target) {
78
 
            case none:
79
 
                File::fprintf (f, "..");
80
 
                break;
81
 
            case target t:
82
 
                show_color (f, t.color, t.active);
83
 
                show_shape (f, t.shape, t.active);
84
 
                break;
85
 
            }
86
 
        }
87
 
        
88
 
        void show_last_col (file f, &Object o) {
89
 
            if (o.walls.right)
90
 
                File::fprintf (f, "|");
91
 
            else
92
 
                File::fprintf (f, " ");
93
 
            File::fprintf (f, "\n");
94
 
        }
95
 
        
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");
100
 
        }
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]);
105
 
        }
106
 
        void show_row (file f, &Board b, int row) {
107
 
            show_first_row (f, &b, row);
108
 
            show_second_row (f, &b, row);
109
 
        }
110
 
        void show_last_row (file f, &Board b) {
111
 
            for (int col = 0; col < Width; col++)
112
 
            {
113
 
                if (b[col,Height-1].walls.below)
114
 
                    File::fprintf (f, " ===");
115
 
                else
116
 
                    File::fprintf (f, "    ");
117
 
            }
118
 
            File::fprintf (f, " ");
119
 
        }
120
 
 
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);
125
 
        }
126
 
    }
127
 
}