Overview
SHA1 Hash: | c357edc016f6c6af6acb33eb83e4e6ca22805c5b |
---|---|
Date: | 2012-07-14 10:07:03 |
User: | kinaba |
Comment: | Implemented flooding. |
Timelines: | family | ancestors | descendants | both | trunk |
Diffs: | redesign |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [16f0b5784f]
- sym-trunk inherited from [16f0b5784f]
Changes
Modified test.d from [f86b02b80bcf28bb] to [23ef619abd528e8f].
6 import dfl.all; 6 import dfl.all; 7 7 8 class Map 8 class Map 9 { 9 { 10 private char[][] data; 10 private char[][] data; 11 bool dead = false; 11 bool dead = false; 12 bool cleared = false; 12 bool cleared = false; > 13 int water = 0; > 14 int flooding = 0; > 15 int water_proof = 10; > 16 int underwater = 0; > 17 int flooding_counter = 0; 13 18 14 this(File input) 19 this(File input) 15 { 20 { 16 foreach(s; input.byLine()) | 21 string line; > 22 while( (line=input.readln().chomp()).length ) 17 data ~= s.chomp.dup; | 23 data ~= line.dup; 18 24 19 int width = 0; 25 int width = 0; 20 foreach(s; data) 26 foreach(s; data) 21 width = max(width, s.length); 27 width = max(width, s.length); 22 28 23 // space padding and sentinels 29 // space padding and sentinels 24 foreach(ref s; data) { 30 foreach(ref s; data) { ................................................................................................................................................................................ 28 s = '#' ~ s ~ '#'; 34 s = '#' ~ s ~ '#'; 29 } 35 } 30 36 31 // vertical sentinel 37 // vertical sentinel 32 char[] sen = new char[width+2]; 38 char[] sen = new char[width+2]; 33 sen[] = '#'; 39 sen[] = '#'; 34 data = sen.dup ~ data ~ sen; 40 data = sen.dup ~ data ~ sen; > 41 > 42 // flooding > 43 water = H-1; > 44 string wfws = input.readln().chomp() ~ " "; > 45 wfws ~= input.readln().chomp() ~ " "; > 46 wfws ~= input.readln().chomp(); > 47 string[] wfw = wfws.split(); > 48 if(wfw.length==6) { > 49 water = H-1 - wfw[1].to!int(); > 50 flooding = wfw[3].to!int(); > 51 water_proof = wfw[5].to!int(); > 52 } 35 } 53 } 36 54 37 @property const 55 @property const 38 { 56 { 39 int W() { return data[0].length; } 57 int W() { return data[0].length; } 40 int H() { return data.length; } 58 int H() { return data.length; } 41 string toString() { 59 string toString() { ................................................................................................................................................................................ 130 } 148 } 131 else if(data[y][x]=='L') { 149 else if(data[y][x]=='L') { 132 if(!lambda) 150 if(!lambda) 133 next[y][x] = 'O'; 151 next[y][x] = 'O'; 134 } 152 } 135 } 153 } 136 data = next; 154 data = next; > 155 > 156 if(flooding) { > 157 flooding_counter ++; > 158 if(flooding_counter == flooding) { > 159 flooding_counter = 0; > 160 water --; > 161 } > 162 bool wa = false; > 163 for(int y=water; y+1<H; ++y) > 164 for(int x=1; x+1<W; ++x) > 165 if(data[y][x]=='R') { > 166 wa = true; > 167 underwater++; > 168 if(underwater > water_proof) > 169 dead = true; > 170 } > 171 if(!wa) > 172 underwater = 0; > 173 } 137 } 174 } 138 } 175 } 139 176 140 class MyForm : Form 177 class MyForm : Form 141 { 178 { 142 Map m; 179 Map m; 143 int score; 180 int score; ................................................................................................................................................................................ 154 invalidate(); 191 invalidate(); 155 } 192 } 156 override void onPaint(PaintEventArgs ev) 193 override void onPaint(PaintEventArgs ev) 157 { 194 { 158 int Z = min(this.clientSize.width/(m.W-2), this.clientSize.heigh 195 int Z = min(this.clientSize.width/(m.W-2), this.clientSize.heigh 159 Font font = new Font("MS Gothic", Z-4); 196 Font font = new Font("MS Gothic", Z-4); 160 Graphics g = ev.graphics; 197 Graphics g = ev.graphics; > 198 g.fillRectangle(Color(0,233,255), Rect(0,Z*(m.water-1),this.clie 161 for(int y=1; y+1<m.H; ++y) 199 for(int y=1; y+1<m.H; ++y) 162 for(int x=1; x+1<m.W; ++x) { 200 for(int x=1; x+1<m.W; ++x) { 163 if(m.data[y][x]=='*') { 201 if(m.data[y][x]=='*') { 164 g.drawText("岩", font, Color(0,0,0), Rect((x-1)*Z 202 g.drawText("岩", font, Color(0,0,0), Rect((x-1)*Z 165 } 203 } 166 if(m.data[y][x]=='\\') { 204 if(m.data[y][x]=='\\') { 167 g.drawText("λ", font, Color(0,255,0), Rect((x-1) 205 g.drawText("λ", font, Color(0,255,0), Rect((x-1)