Differences From Artifact [3baab0ddf11cca7d]:
- File
src/game.d
- 2012-07-14 14:22:32 - part of checkin [a0c3529225] on branch trunk - code cleanup (user: kinaba) [annotate]
- 2012-07-14 16:58:31 - part of checkin [b1ce0206cd] on branch trunk - Revert. (user: kinaba) [annotate]
To Artifact [6d5cf776b9d55f93]:
- File
src/game.d
- 2012-07-14 16:46:37 - part of checkin [99d27d1a03] on branch trunk - parser for trampoline. (user: kinaba) [annotate]
43 43 {
44 44 public immutable int base, pace;
45 45 mixin DeriveCreate;
46 46 mixin DeriveCompare;
47 47 mixin DeriveShow;
48 48 Water clone() const { return cast(Water)this; }
49 49
50 - static load(string[string] params)
50 + static load(string[][string] params)
51 51 {
52 52 return new Water(
53 - params.get("Water", "0").to!int(),
54 - params.get("Flooding", "0").to!int()
53 + params.get("Water", ["0"])[0].to!int(),
54 + params.get("Flooding", ["0"])[0].to!int()
55 55 );
56 56 }
57 57
58 58 int level(int number_of_update) const
59 59 {
60 60 return pace ? base+(number_of_update/pace) : base;
61 61 }
................................................................................
88 88
89 89 ////////////////////////////////////////////////////////////////////////////////
90 90
91 91 class Map
92 92 {
93 93 mixin DeriveShow;
94 94
95 - static Map load(string[] raw_data, string[string] params)
95 + static Map load(string[] raw_data, string[][string] params)
96 96 {
97 97 // TODO: choose optimal representation.
98 98 return new Map(raw_data, params);
99 99 }
100 100
101 101 char[][] data;
102 102 Pos robot;
................................................................................
108 108 foreach(s; m.data)
109 109 this.data ~= s.dup;
110 110 this.robot = m.robot.clone();
111 111 this.lift = m.lift.clone();
112 112 this.waterproof = m.waterproof;
113 113 }
114 114
115 - this(string[] raw_data, string[string] params)
115 + this(string[] raw_data, string[][string] params)
116 116 {
117 117 int width = 0;
118 118 foreach(r; raw_data)
119 119 width = max(width, r.length);
120 120 foreach(r; raw_data) {
121 121 this.data ~= r.dup;
122 122 this.data[$-1].length = width;
................................................................................
127 127 for(int x=1; x<=W; ++x) {
128 128 if(this[y,x] == 'R')
129 129 this.robot = new Pos(y,x);
130 130 if(this[y,x] == 'L' || this[y,x] == 'O')
131 131 this.lift = new Pos(y,x);
132 132 }
133 133
134 - this.waterproof = params.get("Waterproof", "5").to!int();
134 + this.waterproof = params.get("Waterproof", ["5"])[0].to!int();
135 135 }
136 136
137 137 const @property {
138 138 int H() { return data.length; }
139 139 int W() { return data[0].length; }
140 140 }
141 141
................................................................................
273 273
274 274 class Game
275 275 {
276 276 mixin DeriveShow;
277 277
278 278 static Game load(File input)
279 279 {
280 - string[] raw_data;
281 - string[string] params;
280 + string[] raw_data;
281 + string[][string] params;
282 282
283 283 // Raw map data; read until empty line.
284 284 for(string line; !(line=input.readln().chomp()).empty; )
285 285 raw_data ~= line;
286 286
287 287 // Additional commands; read until EOF.
288 288 for(string line; !(line=input.readln()).empty; ) {
289 289 string[] ss = line.split();
290 - if( ss.length == 2 )
291 - params[ss[0]] = ss[1];
290 + params[ss[0]] = ss[1..$];
292 291 }
293 292
294 293 return load(raw_data, params);
295 294 }
296 295
297 - static Game load(string[] raw_data, string[string] params)
296 + static Game load(string[] raw_data, string[][string] params)
298 297 {
299 298 return new Game(raw_data, params);
300 299 }
301 300
302 - this(string[] raw_data, string[string] params)
301 + this(string[] raw_data, string[][string] params)
303 302 {
304 303 this.map = Map.load(raw_data, params);
305 304 this.water = Water.load(params);
306 305 }
307 306
308 307 Game clone() const { return new Game(this); }
309 308 this(in Game g) {