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 class Map 91 class Map 92 { 92 { 93 mixin DeriveShow; 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] tra 96 { 96 { 97 // TODO: choose optimal representation. 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 char[][] data; 101 char[][] data; 102 Pos robot; 102 Pos robot; 103 Pos lift; 103 Pos lift; 104 int waterproof; 104 int waterproof; > 105 Pos[char] tr_target; > 106 Pos[][char] tr_source; 105 107 106 Map clone() const { return new Map(this); } 108 Map clone() const { return new Map(this); } 107 this(in Map m) { 109 this(in Map m) { 108 foreach(s; m.data) 110 foreach(s; m.data) 109 this.data ~= s.dup; 111 this.data ~= s.dup; 110 this.robot = m.robot.clone(); 112 this.robot = m.robot.clone(); 111 this.lift = m.lift.clone(); 113 this.lift = m.lift.clone(); 112 this.waterproof = m.waterproof; 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 int width = 0; 119 int width = 0; 118 foreach(r; raw_data) 120 foreach(r; raw_data) 119 width = max(width, r.length); 121 width = max(width, r.length); 120 foreach(r; raw_data) { 122 foreach(r; raw_data) { 121 this.data ~= r.dup; 123 this.data ~= r.dup; 122 this.data[$-1].length = width; 124 this.data[$-1].length = width; ................................................................................................................................................................................ 126 for(int y=1; y<=H; ++y) 128 for(int y=1; y<=H; ++y) 127 for(int x=1; x<=W; ++x) { 129 for(int x=1; x<=W; ++x) { 128 if(this[y,x] == 'R') 130 if(this[y,x] == 'R') 129 this.robot = new Pos(y,x); 131 this.robot = new Pos(y,x); 130 if(this[y,x] == 'L' || this[y,x] == 'O') 132 if(this[y,x] == 'L' || this[y,x] == 'O') 131 this.lift = new Pos(y,x); 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 this.waterproof = params.get("Waterproof", "5").to!int(); 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 const @property { 152 const @property { 138 int H() { return data.length; } 153 int H() { return data.length; } 139 int W() { return data[0].length; } 154 int W() { return data[0].length; } 140 } 155 } 141 156 ................................................................................................................................................................................ 281 string[string] params; 296 string[string] params; 282 297 283 // Raw map data; read until empty line. 298 // Raw map data; read until empty line. 284 for(string line; !(line=input.readln().chomp()).empty; ) 299 for(string line; !(line=input.readln().chomp()).empty; ) 285 raw_data ~= line; 300 raw_data ~= line; 286 301 287 // Additional commands; read until EOF. 302 // Additional commands; read until EOF. > 303 char[char] trampo; 288 for(string line; !(line=input.readln()).empty; ) { 304 for(string line; !(line=input.readln()).empty; ) { 289 string[] ss = line.split(); 305 string[] ss = line.split(); 290 if( ss.length == 2 ) 306 if( ss.length == 2 ) 291 params[ss[0]] = ss[1]; 307 params[ss[0]] = ss[1]; > 308 if( ss.length == 4 && ss[0]=="Trampoline" && ss[2]=="tar > 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] tr 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 this.water = Water.load(params); 323 this.water = Water.load(params); 306 } 324 } 307 325 308 Game clone() const { return new Game(this); } 326 Game clone() const { return new Game(this); } 309 this(in Game g) { 327 this(in Game g) { 310 map = g.map.clone(); 328 map = g.map.clone(); 311 water = g.water.clone(); 329 water = g.water.clone();

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

5 5 6 class GUI(Solver) : Form, GameObserver 6 class GUI(Solver) : Form, GameObserver 7 { 7 { 8 this(in Game g) 8 this(in Game g) 9 { 9 { 10 this.solver = new Solver(g); 10 this.solver = new Solver(g); 11 setup_size(g.map.W, g.map.H); 11 setup_size(g.map.W, g.map.H); 12 setup_resources(); | 12 setup_resources(g); 13 draw(g); 13 draw(g); 14 } 14 } 15 15 16 private void delegate(char c) fn; 16 private void delegate(char c) fn; 17 void set_fn(F)(F f) { this.fn = f; } 17 void set_fn(F)(F f) { this.fn = f; } 18 18 19 void run(bool automate = false) 19 void run(bool automate = false) ................................................................................................................................................................................ 50 } 50 } 51 51 52 Font font; 52 Font font; 53 Color[char] colors; 53 Color[char] colors; 54 string[char] render; 54 string[char] render; 55 Graphics graphicContext; 55 Graphics graphicContext; 56 56 57 void setup_resources() | 57 void setup_resources(in Game g) 58 { 58 { 59 this.graphicContext = new MemoryGraphics(this.clientSize.width, 59 this.graphicContext = new MemoryGraphics(this.clientSize.width, 60 this.setStyle(ControlStyles.OPAQUE, true); 60 this.setStyle(ControlStyles.OPAQUE, true); 61 this.font = new Font("MS Gothic", cell-2, GraphicsUnit.PIXEL); 61 this.font = new Font("MS Gothic", cell-2, GraphicsUnit.PIXEL); 62 this.backColor = Color(255,255,255); 62 this.backColor = Color(255,255,255); 63 this.colors['#'] = 63 this.colors['#'] = 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 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 this.render['#'] = "■"; 74 this.render['#'] = "■"; 73 this.render['*'] = "✹"; 75 this.render['*'] = "✹"; 74 this.render['.'] = "♒"; 76 this.render['.'] = "♒"; 75 this.render['\\'] = "λ"; 77 this.render['\\'] = "λ"; 76 this.render['R'] = "☃"; 78 this.render['R'] = "☃"; 77 this.render['D'] = "☠"; 79 this.render['D'] = "☠"; 78 this.render['L'] = "☒"; 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 80 this.paint ~= (Control c, PaintEventArgs ev) { 86 this.paint ~= (Control c, PaintEventArgs ev) { 81 graphicContext.copyTo(ev.graphics, Rect(0,0,this.clientS 87 graphicContext.copyTo(ev.graphics, Rect(0,0,this.clientS 82 }; 88 }; 83 } 89 } 84 90 85 void draw(in Game g) 91 void draw(in Game g) 86 { 92 {