Differences From Artifact [06258bf9d419d24b]:
- File
src/game.d
- 2012-07-15 01:58:08 - part of checkin [9d983af88c] on branch trunk - Hige parsing and rendering. (user: kinaba) [annotate]
To Artifact [de7a471045510ac0]:
- File
src/game.d
- 2012-07-15 02:04:13 - part of checkin [2b4f8bba2d] on branch trunk - Hige growth implemented. (user: kinaba) [annotate]
234 234 for(int y=1; y<=H; ++y)
235 235 for(int x=1; x<=W; ++x)
236 236 if(this[y,x] == 'L' || this[y,x] == 'O')
237 237 return false;
238 238 return true;
239 239 }
240 240
241 - Tuple!(int,bool) command(char c)
241 + Tuple!(int,bool) command(char c, int turn)
242 242 {
243 - if(c=='R') return move( 0, +1);
244 - if(c=='L') return move( 0, -1);
245 - if(c=='U') return move(+1, 0);
246 - if(c=='D') return move(-1, 0);
247 - if(c=='W') return move( 0, 0);
243 + if(c=='R') return move( 0, +1, turn);
244 + if(c=='L') return move( 0, -1, turn);
245 + if(c=='U') return move(+1, 0, turn);
246 + if(c=='D') return move(-1, 0, turn);
247 + if(c=='W') return move( 0, 0, turn);
248 248 assert(false);
249 249 }
250 250
251 - Tuple!(int, bool) move(int dy, int dx)
251 + Tuple!(int, bool) move(int dy, int dx, int turn)
252 252 {
253 253 int y = robot.y;
254 254 int x = robot.x;
255 255 assert( this[robot] == 'R' );
256 256 int lambda = 0;
257 257 bool dead = false;
258 258 if( '\\' == this[y+dy,x+dx] )
................................................................................
270 270 this[y,x]=' ';
271 271 Pos tp = tr_target[this[y+dy,x+dx]];
272 272 foreach(p; tr_source[this[tp]])
273 273 this[p] = ' ';
274 274 this[tp] = 'R';
275 275 robot = tp;
276 276 }
277 - if( update() )
277 + if( update(turn) )
278 278 dead = true;
279 279 return tuple(lambda,dead);
280 280 }
281 281
282 - bool update()
282 + bool update(int turn)
283 283 {
284 284 bool dead = false;
285 285
286 286 char[][] next;
287 287 foreach(y,s; data)
288 288 next ~= s.dup;
289 289
................................................................................
317 317 dead=true;
318 318 }
319 319 }
320 320 else if(this[p]=='L') {
321 321 if(!lambda)
322 322 access(p) = 'O';
323 323 }
324 + else if(this[p]=='W') {
325 + if( hige.is_growing_turn(turn) )
326 + for(int dy=-1; dy<=+1; ++dy)
327 + for(int dx=-1; dx<=+1; ++dx)
328 + if(this[p.y+dy,p.x+dx] == ' ')
329 + access(new Pos(p.y+dy,p.x+dx)) = 'W';
330 + }
324 331 }
325 332 data = next;
326 333 return dead;
327 334 }
328 335 }
329 336
330 337 ////////////////////////////////////////////////////////////////////////////////
................................................................................
385 392 if(c == 'A')
386 393 {
387 394 exit_bonus = 1;
388 395 return;
389 396 }
390 397
391 398 // TODO: clarify the event order
392 - Tuple!(int,bool) ld = map.command(c);
399 + Tuple!(int,bool) ld = map.command(c, turn);
393 400 if( map.cleared() ) {
394 401 exit_bonus = 2;
395 402 }
396 403 else {
397 404 lambda += ld[0];
398 405 if( ld[1] ) {
399 406 dead = true;