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 6 import dfl.all; 7 7 8 8 class Map 9 9 { 10 10 private char[][] data; 11 11 bool dead = false; 12 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 19 this(File input) 15 20 { 16 - foreach(s; input.byLine()) 17 - data ~= s.chomp.dup; 21 + string line; 22 + while( (line=input.readln().chomp()).length ) 23 + data ~= line.dup; 18 24 19 25 int width = 0; 20 26 foreach(s; data) 21 27 width = max(width, s.length); 22 28 23 29 // space padding and sentinels 24 30 foreach(ref s; data) { ................................................................................ 28 34 s = '#' ~ s ~ '#'; 29 35 } 30 36 31 37 // vertical sentinel 32 38 char[] sen = new char[width+2]; 33 39 sen[] = '#'; 34 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 55 @property const 38 56 { 39 57 int W() { return data[0].length; } 40 58 int H() { return data.length; } 41 59 string toString() { ................................................................................ 130 148 } 131 149 else if(data[y][x]=='L') { 132 150 if(!lambda) 133 151 next[y][x] = 'O'; 134 152 } 135 153 } 136 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 177 class MyForm : Form 141 178 { 142 179 Map m; 143 180 int score; ................................................................................ 154 191 invalidate(); 155 192 } 156 193 override void onPaint(PaintEventArgs ev) 157 194 { 158 195 int Z = min(this.clientSize.width/(m.W-2), this.clientSize.height/(m.H-2)); 159 196 Font font = new Font("MS Gothic", Z-4); 160 197 Graphics g = ev.graphics; 198 + g.fillRectangle(Color(0,233,255), Rect(0,Z*(m.water-1),this.clientSize.width,this.clientSize.height-(Z*(m.water-1)))); 161 199 for(int y=1; y+1<m.H; ++y) 162 200 for(int x=1; x+1<m.W; ++x) { 163 201 if(m.data[y][x]=='*') { 164 202 g.drawText("岩", font, Color(0,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); 165 203 } 166 204 if(m.data[y][x]=='\\') { 167 205 g.drawText("λ", font, Color(0,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z));