Check-in [9d983af88c]
Not logged in
Overview
SHA1 Hash:9d983af88c6b1dd870c859839021fcab1b60b77b
Date: 2012-07-15 10:58:08
User: kinaba
Comment:Hige parsing and rendering.
Timelines: family | ancestors | descendants | both | trunk
Diffs: redesign
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Added maps/beard1.map version [bb6926793a51311a]

> 1 ########## > 2 #** \\\\# > 3 #.R.. # > 4 # \ ..*\# > 5 #! ..*!# > 6 #### # # > 7 #\\... # L > 8 #\\.W... # > 9 #\\. # > 10 ########## > 11 > 12 Growth 15 > 13 Razors 0

Added maps/beard2.map version [2e942009c89717d7]

> 1 ############################## > 2 #R...........................# > 3 #.........................W..# > 4 #..\\\\\\\\\\\\\\\\\\\\\\\\..# > 5 #............................# > 6 #..*****.*\...*...*...*****..# > 7 #..*\....*\....*\*..*.\\*\\..# > 8 #..*\....****..!*!......*....# > 9 #..*\....*\....*\*..*...*....# > 10 #..*\....*\...*...*.....*....# > 11 #............................# > 12 #..\\\\\\\\\\\\\\\\\\\\\\\\..# > 13 #................ ..... .....# > 14 #................ W....L# > 15 ############################## > 16 > 17 Growth 25 > 18 Razors 10 > 19 Flooding 20

Added maps/beard3.map version [1dcab340493857d0]

> 1 ################ > 2 #*****#!! 1 # > 3 #..\..# # > 4 #########\\\\ # .\\\. # > 5 #.............# * # > 6 #.. .\\\#..!..#\** # > 7 #.. LW\\#W ..##### #### > 8 #..R\\\\#.. ..*\*\*W...# > 9 #.......A.. ...\.\...\\# > 10 #.......... ** # > 11 ############....\.###### > 12 #.....!# > 13 ######## > 14 > 15 Growth 10 > 16 Trampoline A targets 1

Added maps/beard4.map version [b62967eb47a5f507]

> 1 #################### > 2 #W\\!#\\\**.\#W\\\W# > 3 ##*######..###..\\\# > 4 #.......\.R ###...\# > 5 #####.###.#.......## > 6 #.......#.#\####.### > 7 #\\##\###\#\\#...#.L > 8 #\##\.###.####.#.#.# > 9 #\W#####.....###.W.# > 10 ####\\...\\\...#.#.# > 11 #W*######.######.#.# > 12 #\\\\\\\\\.........# > 13 ############\###\### > 14 #\\.. *..........\\# > 15 #W... #.........##W# > 16 ####################

Modified src/game.d from [1b2e4ad2dae20251] to [06258bf9d419d24b].

84 assert( 1 == w.level(3) ); 84 assert( 1 == w.level(3) ); 85 assert( 1 == w.level(4) ); 85 assert( 1 == w.level(4) ); 86 assert( 1 == w.level(5) ); 86 assert( 1 == w.level(5) ); 87 } 87 } 88 88 89 //////////////////////////////////////////////////////////////////////////////// 89 //////////////////////////////////////////////////////////////////////////////// 90 90 > 91 class Hige > 92 { > 93 public immutable int pace; > 94 mixin DeriveCreate; > 95 mixin DeriveCompare; > 96 mixin DeriveShow; > 97 Hige clone() const { return cast(Hige)this; } > 98 > 99 static load(string[string] params) > 100 { > 101 return new Hige(params.get("Growth", "25").to!int()); > 102 } > 103 > 104 bool is_growing_turn(int turn) const > 105 { > 106 return pace ? turn%pace == pace-1 : false; > 107 } > 108 > 109 int until_rise(int turn) const > 110 { > 111 return pace ? pace-turn%pace : int.max; > 112 } > 113 } > 114 > 115 //////////////////////////////////////////////////////////////////////////////// > 116 91 class Map 117 class Map 92 { 118 { 93 mixin DeriveShow; 119 mixin DeriveShow; 94 120 95 static Map load(string[] raw_data, string[string] params, char[char] tra 121 static Map load(string[] raw_data, string[string] params, char[char] tra 96 { 122 { 97 // TODO: choose optimal representation. 123 // TODO: choose optimal representation. ................................................................................................................................................................................ 101 char[][] data; 127 char[][] data; 102 Pos robot; 128 Pos robot; 103 Pos lift; 129 Pos lift; 104 int waterproof; 130 int waterproof; 105 // TODO: immutable 131 // TODO: immutable 106 Pos[char] tr_target; 132 Pos[char] tr_target; 107 Pos[][char] tr_source; 133 Pos[][char] tr_source; > 134 const(Hige) hige; > 135 int razor; 108 136 109 Map clone() const { return new Map(this); } 137 Map clone() const { return new Map(this); } 110 this(in Map m) { 138 this(in Map m) { 111 foreach(s; m.data) 139 foreach(s; m.data) 112 this.data ~= s.dup; 140 this.data ~= s.dup; 113 this.robot = m.robot.clone(); 141 this.robot = m.robot.clone(); 114 this.lift = m.lift.clone(); 142 this.lift = m.lift.clone(); 115 this.waterproof = m.waterproof; 143 this.waterproof = m.waterproof; 116 this.tr_target = cast(Pos[char])m.tr_target; 144 this.tr_target = cast(Pos[char])m.tr_target; 117 this.tr_source = cast(Pos[][char])m.tr_source; 145 this.tr_source = cast(Pos[][char])m.tr_source; > 146 this.hige = m.hige.clone(); > 147 this.razor = m.razor; 118 } 148 } 119 149 120 this(string[] raw_data, string[string] params, char[char] trampo) 150 this(string[] raw_data, string[string] params, char[char] trampo) 121 { 151 { 122 int width = 0; 152 int width = 0; 123 foreach(r; raw_data) 153 foreach(r; raw_data) 124 width = max(width, r.length); 154 width = max(width, r.length); ................................................................................................................................................................................ 146 176 147 this.waterproof = params.get("Waterproof", "5").to!int(); 177 this.waterproof = params.get("Waterproof", "5").to!int(); 148 foreach(fr,to; trampo) { 178 foreach(fr,to; trampo) { 149 tr_target[fr] = tr_pos[to]; 179 tr_target[fr] = tr_pos[to]; 150 if(to !in tr_source) tr_source[to] = []; 180 if(to !in tr_source) tr_source[to] = []; 151 tr_source[to] ~= tr_pos[fr]; 181 tr_source[to] ~= tr_pos[fr]; 152 } 182 } > 183 > 184 this.hige = Hige.load(params); > 185 this.razor = params.get("Razors", "0").to!int(); 153 } 186 } 154 187 155 const @property { 188 const @property { 156 int H() { return data.length; } 189 int H() { return data.length; } 157 int W() { return data[0].length; } 190 int W() { return data[0].length; } 158 } 191 } 159 192 ................................................................................................................................................................................ 385 // TODO: when adding members, take care of clone(). 418 // TODO: when adding members, take care of clone(). 386 // TODO: fix this poor design. 419 // TODO: fix this poor design. 387 420 388 @property const { 421 @property const { 389 long score() { return lambda*25L*(1+exit_bonus) - turn; } 422 long score() { return lambda*25L*(1+exit_bonus) - turn; } 390 int water_level() { return water.level(turn); } 423 int water_level() { return water.level(turn); } 391 int water_until_rise() { return water.until_rise(turn); } 424 int water_until_rise() { return water.until_rise(turn); } > 425 int hige_until_rise() { return map.hige.until_rise(turn); } 392 bool cleared() { return exit_bonus>0; } 426 bool cleared() { return exit_bonus>0; } 393 int hp() { return map.waterproof - under_water; } 427 int hp() { return map.waterproof - under_water; } 394 long score_if_abort_now() { return lambda*25*(1+max(1,exit_bonus 428 long score_if_abort_now() { return lambda*25*(1+max(1,exit_bonus 395 } 429 } 396 } 430 } 397 < 398 unittest < 399 { < 400 Game.load(["###","...","#RL"], ["xxx":"yyy"]); < 401 } <

Modified src/gui.d from [19a06a471eb23a83] to [3be06eef4f2a58fa].

64 this.colors['.'] = Color(255,191,127); 64 this.colors['.'] = Color(255,191,127); 65 this.colors['*'] = Color(255,127,127); 65 this.colors['*'] = Color(255,127,127); 66 this.colors['R'] = Color(128,128,0); 66 this.colors['R'] = Color(128,128,0); 67 this.colors['d'] = Color(255,0,0); 67 this.colors['d'] = Color(255,0,0); 68 this.colors['\\'] = 68 this.colors['\\'] = 69 this.colors['L'] = 69 this.colors['L'] = 70 this.colors['O'] = Color(127,255,127); 70 this.colors['O'] = Color(127,255,127); > 71 this.colors['w'] = Color(204,229,255); 71 this.colors['W'] = Color(204,229,255); | 72 this.colors['W'] = > 73 this.colors['!'] = Color(159,159,159); 72 foreach(char c; 'A'..'J') this.colors[c] = Color(142,142,255); 74 foreach(char c; 'A'..'J') this.colors[c] = Color(142,142,255); 73 foreach(char c; '1'..':') this.colors[c] = Color(255,142,255); 75 foreach(char c; '1'..':') this.colors[c] = Color(255,142,255); 74 this.render['#'] = "■"; 76 this.render['#'] = "■"; 75 this.render['*'] = "✹"; 77 this.render['*'] = "✹"; 76 this.render['.'] = "♒"; 78 this.render['.'] = "♒"; 77 this.render['\\'] = "λ"; 79 this.render['\\'] = "λ"; 78 this.render['R'] = "☃"; 80 this.render['R'] = "☃"; 79 this.render['d'] = "☠"; 81 this.render['d'] = "☠"; 80 this.render['L'] = "☒"; 82 this.render['L'] = "☒"; 81 this.render['O'] = "☐"; 83 this.render['O'] = "☐"; > 84 this.render['W'] = "ꔣ"; > 85 this.render['!'] = "✄"; 82 foreach(c,tp; g.map.tr_target) { 86 foreach(c,tp; g.map.tr_target) { 83 char d = g.map[tp]; 87 char d = g.map[tp]; 84 this.render[c] = [cast(dchar)('☢'+d-'1')].to!string();/* | 88 this.render[c] = [cast(dchar)('☢'+d-'1')].to!string(); 85 } 89 } 86 foreach(char c; '1'..':') this.render[c] = [cast(dchar)('☢'+c-'1 90 foreach(char c; '1'..':') this.render[c] = [cast(dchar)('☢'+c-'1 87 this.paint ~= (Control c, PaintEventArgs ev) { 91 this.paint ~= (Control c, PaintEventArgs ev) { 88 graphicContext.copyTo(ev.graphics, Rect(0,0,this.clientS 92 graphicContext.copyTo(ev.graphics, Rect(0,0,this.clientS 89 }; 93 }; 90 } 94 } 91 95 ................................................................................................................................................................................ 95 int scrH = this.clientSize.height; 99 int scrH = this.clientSize.height; 96 100 97 // Fill bg. 101 // Fill bg. 98 graphicContext.fillRectangle(this.backColor, Rect(0,0,scrW,scrH) 102 graphicContext.fillRectangle(this.backColor, Rect(0,0,scrW,scrH) 99 103 100 // Fill water. 104 // Fill water. 101 int w = g.water_level(); 105 int w = g.water_level(); 102 graphicContext.fillRectangle(this.colors['W'], Rect(0, scrH-cell | 106 graphicContext.fillRectangle(this.colors['w'], Rect(0, scrH-cell 103 107 104 // Paint map. 108 // Paint map. 105 for(int y=1; y<=g.map.H; ++y) 109 for(int y=1; y<=g.map.H; ++y) 106 for(int x=1; x<=g.map.W; ++x) { 110 for(int x=1; x<=g.map.W; ++x) { 107 Rect r = Rect(cell*(x-1), scrH-cell*y, cell, cell); 111 Rect r = Rect(cell*(x-1), scrH-cell*y, cell, cell); 108 char c = g.map[y,x]; 112 char c = g.map[y,x]; 109 if( c != ' ' ) { 113 if( c != ' ' ) { ................................................................................................................................................................................ 110 if( c == 'R' && g.dead ) 114 if( c == 'R' && g.dead ) 111 c = 'd'; 115 c = 'd'; 112 graphicContext.drawText(this.render[c], font, th 116 graphicContext.drawText(this.render[c], font, th 113 } 117 } 114 } 118 } 115 119 116 // Update textual info. 120 // Update textual info. > 121 this.text = .text( > 122 "Score: ", g.score, > 123 " Air: ", g.hp, 117 this.text = .text("Score: ", g.score, " Air: ", g.hp, " Tide: ", | 124 " Tide: ", g.water_until_rise, > 125 " Wadler: ", g.hige_until_rise, > 126 " Razor: ", g.map.razor); 118 invalidate(); 127 invalidate(); 119 } 128 } 120 129 121 private: 130 private: 122 void setup_keyhandling() 131 void setup_keyhandling() 123 { 132 { 124 noMessageFilter(); 133 noMessageFilter();

Modified src/util.d from [783554bf667412ed] to [0665970b47ba63ed].

19 this.tupleof = params; 19 this.tupleof = params; 20 } 20 } 21 } 21 } 22 22 23 template DeriveCompare() 23 template DeriveCompare() 24 { 24 { 25 override: 25 override: 26 bool opEquals(Object rhs) | 26 bool opEquals(Object rhs) const 27 { 27 { 28 return tuple(this.tupleof) == tuple((cast(typeof(this))rhs).tupl 28 return tuple(this.tupleof) == tuple((cast(typeof(this))rhs).tupl 29 } 29 } 30 30 31 int opCmp(Object rhs) | 31 int opCmp(Object rhs) const 32 { 32 { 33 return tuple(this.tupleof).opCmp(tuple((cast(typeof(this))rhs).t 33 return tuple(this.tupleof).opCmp(tuple((cast(typeof(this))rhs).t 34 } 34 } 35 35 36 hash_t toHash() | 36 hash_t toHash() const 37 { 37 { 38 hash_t v = 0; 38 hash_t v = 0; 39 foreach(mem; this.tupleof) { 39 foreach(mem; this.tupleof) { 40 v *= 11; 40 v *= 11; 41 static if(__traits(compiles, v^=mem)) 41 static if(__traits(compiles, v^=mem)) 42 v ^= mem; 42 v ^= mem; 43 else 43 else ................................................................................................................................................................................ 46 return v; 46 return v; 47 } 47 } 48 } 48 } 49 49 50 template DeriveShow() 50 template DeriveShow() 51 { 51 { 52 override: 52 override: 53 string toString() | 53 string toString() const 54 { 54 { 55 string str = text(typeof(this).stringof, "("); 55 string str = text(typeof(this).stringof, "("); 56 foreach(i,mem; this.tupleof) { 56 foreach(i,mem; this.tupleof) { 57 if(i) str ~= ", "; 57 if(i) str ~= ", "; 58 str = text(str, this.tupleof[i].stringof[5..$], ":", me 58 str = text(str, this.tupleof[i].stringof[5..$], ":", me 59 } 59 } 60 return str ~ ")"; 60 return str ~ ")"; 61 } 61 } 62 } 62 }