Check-in Differences
Not logged in

Difference From:

[fc9286dad1] uum (user: kinaba, tags: redesign, date: 2012-07-15 12:11:33)

To:

[a03584f1c6] Refactored. (user: kinaba, tags: trunk, date: 2012-07-15 12:01:04)

Modified src/game.d from [fc05481901940844] to [eaa7866c864bed8a].

344 access(new Pos(p.y+dy,p. 344 access(new Pos(p.y+dy,p. 345 } 345 } 346 } 346 } 347 data = next; 347 data = next; 348 return dead; 348 return dead; 349 } 349 } 350 } 350 } > 351 > 352 //////////////////////////////////////////////////////////////////////////////// > 353 /* > 354 class Game > 355 { > 356 mixin DeriveShow; > 357 > 358 static Game load(File input) > 359 { > 360 string[] raw_data; > 361 string[string] params; > 362 > 363 // Raw map data; read until empty line. > 364 for(string line; !(line=input.readln().chomp()).empty; ) > 365 raw_data ~= line; > 366 > 367 // Additional commands; read until EOF. > 368 char[char] trampo; > 369 for(string line; !(line=input.readln()).empty; ) { > 370 string[] ss = line.split(); > 371 if( ss.length == 2 ) > 372 params[ss[0]] = ss[1]; > 373 if( ss.length == 4 && ss[0]=="Trampoline" && ss[2]=="tar > 374 trampo[ss[1][0]] = ss[3][0]; > 375 } > 376 > 377 return load(raw_data, params, trampo); > 378 } > 379 > 380 static Game load(string[] raw_data, string[string] params, char[char] tr > 381 { > 382 return new Game(raw_data, params, trampo); > 383 } > 384 > 385 this(string[] raw_data, string[string] params, char[char] trampo) > 386 { > 387 this.map = Map.load(raw_data, params, trampo); > 388 this.water = Water.load(params); > 389 } > 390 > 391 Game clone() const { return new Game(this); } > 392 this(in Game g) { > 393 map = g.map.clone(); > 394 water = g.water.clone(); > 395 turn = g.turn; > 396 dead = g.dead; > 397 lambda = g.lambda; > 398 cleared = g.cleared; > 399 under_water = g.under_water; > 400 } > 401 > 402 void command(char c) > 403 { > 404 assert(c != 'A'); > 405 if(dead || cleared) > 406 return; > 407 > 408 // TODO: clarify the event order > 409 Tuple!(int,bool) ld = map.command(c, turn); > 410 if( map.cleared() ) { > 411 cleared = true; > 412 } > 413 else { > 414 lambda += ld[0]; > 415 if( ld[1] ) > 416 dead = true; > 417 } > 418 if(!cleared) { > 419 if( map.robot.y <= water_level ) > 420 ++under_water; > 421 else > 422 under_water = 0; > 423 if( under_water > map.waterproof ) > 424 dead = true; > 425 } > 426 turn += 1; > 427 } > 428 > 429 Map map; > 430 Water water; > 431 int turn = 0; > 432 bool dead = false; > 433 int lambda = 0; > 434 int under_water = 0; > 435 bool cleared = false; > 436 // TODO: when adding members, take care of clone(). > 437 // TODO: fix this poor design. > 438 > 439 @property const { > 440 long score() { return lambda*(dead ? 25L : cleared ? 75L : 50L) > 441 int water_level() { return water.level(turn); } > 442 int water_until_rise() { return water.until_rise(turn); } > 443 int hige_until_rise() { return map.hige.until_rise(turn); } > 444 int hp() { return map.waterproof - under_water; } > 445 } > 446 } > 447 */ 351 448 352 //////////////////////////////////////////////////////////////////////////////// 449 //////////////////////////////////////////////////////////////////////////////// 353 450 354 class Game 451 class Game 355 { 452 { 356 public: 453 public: 357 this(File input) 454 this(File input)