Debian Codegraph @

gcc/testsuite/gm2/examples/map/pass/WriteMap.mod

raw
1 (* Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
2 Free Software Foundation, Inc. *)
3 (* This file is part of GNU Modula-2.
4
5 GNU Modula-2 is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 3, or (at your option) any later
8 version.
9
10 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with gm2; see the file COPYING. If not, write to the Free Software
17 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
18 IMPLEMENTATION MODULE WriteMap ;
19
20
21
22 IMPORT Break ;
23
24 FROM StrIO IMPORT WriteLn, WriteString ;
25
26 FROM NumberIO IMPORT WriteCard ;
27
28 FROM RoomMap IMPORT NoOfRooms, Rooms, DoorStatus ;
29
30
31 (*
32 WriteMapText - writes out the map in textual form.
33 *)
34
35 PROCEDURE WriteMapText ;
36 VAR
37 i: CARDINAL ;
38 BEGIN
39 MakeRoomNumbers ;
40 FOR i := 1 TO NoOfRooms DO
41 IF RoomExists(i)
42 THEN
43 WriteRoom(i)
44 END
45 END ;
46 WriteString('END.') ; WriteLn
47 END WriteMapText ;
48
49
50 (*
51 MakeRoomNumbers - makes room numbers for the rooms that exist.
52 *)
53
54 PROCEDURE MakeRoomNumbers ;
55 VAR
56 i, j: CARDINAL ;
57 BEGIN
58 j := 1 ;
59 FOR i := 1 TO NoOfRooms DO
60 IF RoomExists(i)
61 THEN
62 Rooms[i].RoomNo := j ;
63 INC(j)
64 END
65 END
66 END MakeRoomNumbers ;
67
68
69 (*
70 WriteRoom - writes out the room coordinates.
71 *)
72
73 PROCEDURE WriteRoom (r: CARDINAL) ;
74 VAR
75 i: CARDINAL ;
76 BEGIN
77 WITH Rooms[r] DO
78 WriteString('ROOM') ; WriteCard(RoomNo, 4) ; WriteLn ;
79 WriteString('WALL') ; WriteLn ;
80 FOR i := 1 TO NoOfWalls DO
81 WITH Walls[i] DO
82 WriteCard(X1, 8) ; WriteCard(Y1, 4) ;
83 WriteCard(X2, 4) ; WriteCard(Y2, 4) ; WriteLn
84 END
85 END ;
86 FOR i := 1 TO NoOfDoors DO
87 WriteString('DOOR') ;
88 WITH Doors[i] DO
89 WITH Position DO
90 WriteCard(X1, 4) ; WriteCard(Y1, 4) ;
91 WriteCard(X2, 4) ; WriteCard(Y2, 4)
92 END ;
93 WriteString(' STATUS ') ;
94 WriteStatus(StateOfDoor) ;
95 WriteString(' LEADS TO') ;
96 WriteCard(Rooms[LeadsTo].RoomNo, 4) ; WriteLn
97 END
98 END ;
99 WriteString('END') ; WriteLn
100 END
101 END WriteRoom ;
102
103
104 (*
105 WriteStatus - writes the status of a door.
106 *)
107
108 PROCEDURE WriteStatus (s: DoorStatus) ;
109 BEGIN
110 CASE s OF
111
112 Open : WriteString('OPEN ') |
113 Closed : WriteString('CLOSED') |
114 Secret : WriteString('SECRET')
115
116 ELSE
117 HALT
118 END
119 END WriteStatus ;
120
121
122 (*
123 RoomExists - returns true if a room exists.
124 *)
125
126 PROCEDURE RoomExists (r: CARDINAL) : BOOLEAN ;
127 BEGIN
128 RETURN( Rooms[r].RoomNo#0 )
129 END RoomExists ;
130
131
132 END WriteMap.