Check-in [b8acb5f918]
Not logged in
Overview
SHA1 Hash:b8acb5f9182b5bae8e0750f43e6e9fabe30ca367
Date: 2012-07-15 02:20:35
User: kinaba
Comment:trampoline 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

Modified src/game.d from [3baab0ddf11cca7d] to [a105238bfa87f17a].

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, char[char] trampo) 96 96 { 97 97 // TODO: choose optimal representation. 98 - return new Map(raw_data, params); 98 + return new Map(raw_data, params, trampo); 99 99 } 100 100 101 101 char[][] data; 102 102 Pos robot; 103 103 Pos lift; 104 104 int waterproof; 105 + Pos[char] tr_target; 106 + Pos[][char] tr_source; 105 107 106 108 Map clone() const { return new Map(this); } 107 109 this(in Map m) { 108 110 foreach(s; m.data) 109 111 this.data ~= s.dup; 110 112 this.robot = m.robot.clone(); 111 113 this.lift = m.lift.clone(); 112 114 this.waterproof = m.waterproof; 113 115 } 114 116 115 - this(string[] raw_data, string[string] params) 117 + this(string[] raw_data, string[string] params, char[char] trampo) 116 118 { 117 119 int width = 0; 118 120 foreach(r; raw_data) 119 121 width = max(width, r.length); 120 122 foreach(r; raw_data) { 121 123 this.data ~= r.dup; 122 124 this.data[$-1].length = width; ................................................................................ 126 128 for(int y=1; y<=H; ++y) 127 129 for(int x=1; x<=W; ++x) { 128 130 if(this[y,x] == 'R') 129 131 this.robot = new Pos(y,x); 130 132 if(this[y,x] == 'L' || this[y,x] == 'O') 131 133 this.lift = new Pos(y,x); 132 134 } 135 + 136 + Pos[char] tr_pos; 137 + for(int y=1; y<=H; ++y) 138 + for(int x=1; x<=W; ++x) { 139 + char c = this[y,x]; 140 + if('1'<=c && c<='9' || 'A'<=c&&c<='I') 141 + tr_pos[c] = new Pos(y,x); 142 + } 133 143 134 144 this.waterproof = params.get("Waterproof", "5").to!int(); 145 + foreach(fr,to; trampo) { 146 + tr_target[fr] = tr_pos[to]; 147 + if(to !in tr_source) tr_source[to] = []; 148 + tr_source[to] ~= tr_pos[to]; 149 + } 135 150 } 136 151 137 152 const @property { 138 153 int H() { return data.length; } 139 154 int W() { return data[0].length; } 140 155 } 141 156 ................................................................................ 281 296 string[string] params; 282 297 283 298 // Raw map data; read until empty line. 284 299 for(string line; !(line=input.readln().chomp()).empty; ) 285 300 raw_data ~= line; 286 301 287 302 // Additional commands; read until EOF. 303 + char[char] trampo; 288 304 for(string line; !(line=input.readln()).empty; ) { 289 305 string[] ss = line.split(); 290 306 if( ss.length == 2 ) 291 307 params[ss[0]] = ss[1]; 308 + if( ss.length == 4 && ss[0]=="Trampoline" && ss[2]=="targets" ) 309 + trampo[ss[1][0]] = ss[3][0]; 292 310 } 293 311 294 - return load(raw_data, params); 312 + return load(raw_data, params, trampo); 295 313 } 296 314 297 - static Game load(string[] raw_data, string[string] params) 315 + static Game load(string[] raw_data, string[string] params, char[char] trampo = null) 298 316 { 299 - return new Game(raw_data, params); 317 + return new Game(raw_data, params, trampo); 300 318 } 301 319 302 - this(string[] raw_data, string[string] params) 320 + this(string[] raw_data, string[string] params, char[char] trampo) 303 321 { 304 - this.map = Map.load(raw_data, params); 322 + this.map = Map.load(raw_data, params, trampo); 305 323 this.water = Water.load(params); 306 324 } 307 325 308 326 Game clone() const { return new Game(this); } 309 327 this(in Game g) { 310 328 map = g.map.clone(); 311 329 water = g.water.clone();

Modified src/gui.d from [6f9d0f82c55a2152] to [89822443381424ce].

5 5 6 6 class GUI(Solver) : Form, GameObserver 7 7 { 8 8 this(in Game g) 9 9 { 10 10 this.solver = new Solver(g); 11 11 setup_size(g.map.W, g.map.H); 12 - setup_resources(); 12 + setup_resources(g); 13 13 draw(g); 14 14 } 15 15 16 16 private void delegate(char c) fn; 17 17 void set_fn(F)(F f) { this.fn = f; } 18 18 19 19 void run(bool automate = false) ................................................................................ 50 50 } 51 51 52 52 Font font; 53 53 Color[char] colors; 54 54 string[char] render; 55 55 Graphics graphicContext; 56 56 57 - void setup_resources() 57 + void setup_resources(in Game g) 58 58 { 59 59 this.graphicContext = new MemoryGraphics(this.clientSize.width, this.clientSize.height); 60 60 this.setStyle(ControlStyles.OPAQUE, true); 61 61 this.font = new Font("MS Gothic", cell-2, GraphicsUnit.PIXEL); 62 62 this.backColor = Color(255,255,255); 63 63 this.colors['#'] = 64 64 this.colors['.'] = Color(255,191,127); ................................................................................ 65 65 this.colors['*'] = Color(255,127,127); 66 66 this.colors['R'] = Color(128,128,0); 67 67 this.colors['D'] = Color(255,0,0); 68 68 this.colors['\\'] = 69 69 this.colors['L'] = 70 70 this.colors['O'] = Color(127,255,127); 71 71 this.colors['W'] = Color(204,229,255); 72 + foreach(char c; 'A'..'J') this.colors[c] = Color(142,142,255); 73 + foreach(char c; '1'..':') this.colors[c] = Color(255,142,255); 72 74 this.render['#'] = "■"; 73 75 this.render['*'] = "✹"; 74 76 this.render['.'] = "♒"; 75 77 this.render['\\'] = "λ"; 76 78 this.render['R'] = "☃"; 77 79 this.render['D'] = "☠"; 78 80 this.render['L'] = "☒"; 79 - this.render['O'] = "☐"; 81 + foreach(c,tp; g.map.tr_target) { 82 + char d = g.map[tp]; 83 + this.render[c] = [cast(dchar)('㋀'+d-'1')].to!string(); 84 + } 85 + foreach(char c; '1'..':') this.render[c] = [cast(dchar)('㏠'+c-'1')].to!string(); 80 86 this.paint ~= (Control c, PaintEventArgs ev) { 81 87 graphicContext.copyTo(ev.graphics, Rect(0,0,this.clientSize.width,this.clientSize.height)); 82 88 }; 83 89 } 84 90 85 91 void draw(in Game g) 86 92 {