Index: test.d ================================================================== --- test.d +++ test.d @@ -8,15 +8,21 @@ class Map { private char[][] data; bool dead = false; bool cleared = false; + int water = 0; + int flooding = 0; + int water_proof = 10; + int underwater = 0; + int flooding_counter = 0; this(File input) { - foreach(s; input.byLine()) - data ~= s.chomp.dup; + string line; + while( (line=input.readln().chomp()).length ) + data ~= line.dup; int width = 0; foreach(s; data) width = max(width, s.length); @@ -30,10 +36,22 @@ // vertical sentinel char[] sen = new char[width+2]; sen[] = '#'; data = sen.dup ~ data ~ sen; + + // flooding + water = H-1; + string wfws = input.readln().chomp() ~ " "; + wfws ~= input.readln().chomp() ~ " "; + wfws ~= input.readln().chomp(); + string[] wfw = wfws.split(); + if(wfw.length==6) { + water = H-1 - wfw[1].to!int(); + flooding = wfw[3].to!int(); + water_proof = wfw[5].to!int(); + } } @property const { int W() { return data[0].length; } @@ -132,10 +150,29 @@ if(!lambda) next[y][x] = 'O'; } } data = next; + + if(flooding) { + flooding_counter ++; + if(flooding_counter == flooding) { + flooding_counter = 0; + water --; + } + bool wa = false; + for(int y=water; y+1 water_proof) + dead = true; + } + if(!wa) + underwater = 0; + } } } class MyForm : Form { @@ -156,10 +193,11 @@ override void onPaint(PaintEventArgs ev) { int Z = min(this.clientSize.width/(m.W-2), this.clientSize.height/(m.H-2)); Font font = new Font("MS Gothic", Z-4); Graphics g = ev.graphics; + g.fillRectangle(Color(0,233,255), Rect(0,Z*(m.water-1),this.clientSize.width,this.clientSize.height-(Z*(m.water-1)))); for(int y=1; y+1