a06a38e3e6 2012-07-13 kinaba: import std.algorithm; a06a38e3e6 2012-07-13 kinaba: import std.array; a06a38e3e6 2012-07-13 kinaba: import std.conv; a06a38e3e6 2012-07-13 kinaba: import std.stdio; a06a38e3e6 2012-07-13 kinaba: import std.string; 4bdb07bffb 2012-07-14 kinaba: import std.typecons; b59ee91407 2012-07-13 kinaba: import dfl.all; a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: class Map a06a38e3e6 2012-07-13 kinaba: { a06a38e3e6 2012-07-13 kinaba: private char[][] data; d0766ecd1b 2012-07-13 kinaba: bool dead = false; 246bed04b3 2012-07-13 kinaba: bool cleared = false; c357edc016 2012-07-14 kinaba: int water = 0; c357edc016 2012-07-14 kinaba: int flooding = 0; c357edc016 2012-07-14 kinaba: int water_proof = 10; c357edc016 2012-07-14 kinaba: int underwater = 0; c357edc016 2012-07-14 kinaba: int flooding_counter = 0; a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: this(File input) a06a38e3e6 2012-07-13 kinaba: { c357edc016 2012-07-14 kinaba: string line; c357edc016 2012-07-14 kinaba: while( (line=input.readln().chomp()).length ) c357edc016 2012-07-14 kinaba: data ~= line.dup; a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: int width = 0; a06a38e3e6 2012-07-13 kinaba: foreach(s; data) a06a38e3e6 2012-07-13 kinaba: width = max(width, s.length); a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: // space padding and sentinels a06a38e3e6 2012-07-13 kinaba: foreach(ref s; data) { a06a38e3e6 2012-07-13 kinaba: int p = s.length; a06a38e3e6 2012-07-13 kinaba: s.length = width; a06a38e3e6 2012-07-13 kinaba: s[p..$] = ' '; a06a38e3e6 2012-07-13 kinaba: s = '#' ~ s ~ '#'; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: // vertical sentinel a06a38e3e6 2012-07-13 kinaba: char[] sen = new char[width+2]; a06a38e3e6 2012-07-13 kinaba: sen[] = '#'; a06a38e3e6 2012-07-13 kinaba: data = sen.dup ~ data ~ sen; c357edc016 2012-07-14 kinaba: c357edc016 2012-07-14 kinaba: // flooding c357edc016 2012-07-14 kinaba: water = H-1; 6819168095 2012-07-14 kinaba: while( (line=input.readln()).length ) { 6819168095 2012-07-14 kinaba: string[] ss = line.split(); 6819168095 2012-07-14 kinaba: if(ss.length==2 && ss[0]=="Water") 6819168095 2012-07-14 kinaba: water = H-1 - ss[1].to!int(); 6819168095 2012-07-14 kinaba: else if(ss.length==2 && ss[0]=="Flooding") 6819168095 2012-07-14 kinaba: flooding = ss[1].to!int(); 6819168095 2012-07-14 kinaba: else if(ss.length==2 && ss[0]=="Waterproof") 6819168095 2012-07-14 kinaba: water_proof = ss[1].to!int(); c357edc016 2012-07-14 kinaba: } a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: @property const a06a38e3e6 2012-07-13 kinaba: { a06a38e3e6 2012-07-13 kinaba: int W() { return data[0].length; } a06a38e3e6 2012-07-13 kinaba: int H() { return data.length; } a06a38e3e6 2012-07-13 kinaba: string toString() { a06a38e3e6 2012-07-13 kinaba: string result; a06a38e3e6 2012-07-13 kinaba: foreach(i,s; data) { a06a38e3e6 2012-07-13 kinaba: if(i) result ~= '\n'; a06a38e3e6 2012-07-13 kinaba: result ~= s.idup; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: return result; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: d9fd2b855a 2012-07-14 kinaba: int command_R() { if(dead)return 0; write("R"); return move(0, +1); } d9fd2b855a 2012-07-14 kinaba: int command_L() { if(dead)return 0; write("L"); return move(0, -1); } d9fd2b855a 2012-07-14 kinaba: int command_U() { if(dead)return 0; write("U"); return move(-1, 0); } d9fd2b855a 2012-07-14 kinaba: int command_D() { if(dead)return 0; write("D"); return move(+1, 0); } d9fd2b855a 2012-07-14 kinaba: int wait() { if(dead)return 0; update(); write("W"); return -1; } d9fd2b855a 2012-07-14 kinaba: int abort() { if(dead)return 0; cleared=true; write("A"); return gained*25; } a06a38e3e6 2012-07-13 kinaba: 8f5135c552 2012-07-13 kinaba: int move(int dy, int dx) { a06a38e3e6 2012-07-13 kinaba: foreach(y,s; data) a06a38e3e6 2012-07-13 kinaba: foreach(x,c; s) a06a38e3e6 2012-07-13 kinaba: if(c == 'R') a06a38e3e6 2012-07-13 kinaba: return move(dy, dx, y, x); 8f5135c552 2012-07-13 kinaba: assert(false); a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: 8f5135c552 2012-07-13 kinaba: int gained = 0; // TODO: atode naosu 8f5135c552 2012-07-13 kinaba: int move(int dy, int dx, int y, int x) { d0766ecd1b 2012-07-13 kinaba: if(dead) d0766ecd1b 2012-07-13 kinaba: return 0; 8f5135c552 2012-07-13 kinaba: int score = 0; 8f5135c552 2012-07-13 kinaba: if(data[y+dy][x+dx]=='\\') { 8f5135c552 2012-07-13 kinaba: score += 25; 8f5135c552 2012-07-13 kinaba: ++gained; 8f5135c552 2012-07-13 kinaba: } 246bed04b3 2012-07-13 kinaba: if(data[y+dy][x+dx]=='O') { 8f5135c552 2012-07-13 kinaba: score += gained*50; 246bed04b3 2012-07-13 kinaba: cleared = true; 246bed04b3 2012-07-13 kinaba: } 8f5135c552 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: if(data[y+dy][x+dx]==' ' || data[y+dy][x+dx]=='.' a06a38e3e6 2012-07-13 kinaba: || data[y+dy][x+dx]=='\\' || data[y+dy][x+dx]=='O') { a06a38e3e6 2012-07-13 kinaba: data[y][x]=' '; a06a38e3e6 2012-07-13 kinaba: data[y+dy][x+dx]='R'; a06a38e3e6 2012-07-13 kinaba: } else if(dy==0 && data[y+dy][x+dx]=='*' && data[y+2*dy][x+2*dx]==' ') { a06a38e3e6 2012-07-13 kinaba: data[y][x]=' '; a06a38e3e6 2012-07-13 kinaba: data[y+dy][x+dx]='R'; a06a38e3e6 2012-07-13 kinaba: data[y+2*dy][x+2*dx]='*'; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: update(); 8f5135c552 2012-07-13 kinaba: return score-1; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: void update() { a06a38e3e6 2012-07-13 kinaba: char[][] next; a06a38e3e6 2012-07-13 kinaba: foreach(y,s; data) a06a38e3e6 2012-07-13 kinaba: next ~= s.dup; a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: bool lambda = false; a06a38e3e6 2012-07-13 kinaba: for(int y=1; y+1<H; ++y) a06a38e3e6 2012-07-13 kinaba: for(int x=1; x+1<W; ++x) a06a38e3e6 2012-07-13 kinaba: lambda |= (data[y][x] == '\\'); a06a38e3e6 2012-07-13 kinaba: d0766ecd1b 2012-07-13 kinaba: for(int y=H-2; y>=1; --y) a06a38e3e6 2012-07-13 kinaba: for(int x=1; x+1<W; ++x) { a06a38e3e6 2012-07-13 kinaba: if(data[y][x]=='*') { a06a38e3e6 2012-07-13 kinaba: if(data[y+1][x]==' ') { a06a38e3e6 2012-07-13 kinaba: next[y][x]=' '; a06a38e3e6 2012-07-13 kinaba: next[y+1][x]='*'; d0766ecd1b 2012-07-13 kinaba: if(next[y+2][x]=='R') d0766ecd1b 2012-07-13 kinaba: dead=true; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: else if(data[y+1][x]=='*' && data[y][x+1]==' ' && data[y+1][x+1]==' ') { a06a38e3e6 2012-07-13 kinaba: next[y][x]=' '; a06a38e3e6 2012-07-13 kinaba: next[y+1][x+1]='*'; d0766ecd1b 2012-07-13 kinaba: if(next[y+2][x+1]=='R') d0766ecd1b 2012-07-13 kinaba: dead=true; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: else if(data[y+1][x]=='*' && data[y][x-1]==' ' && data[y+1][x-1]==' ') { a06a38e3e6 2012-07-13 kinaba: next[y][x]=' '; a06a38e3e6 2012-07-13 kinaba: next[y+1][x-1]='*'; d0766ecd1b 2012-07-13 kinaba: if(next[y+2][x-1]=='R') d0766ecd1b 2012-07-13 kinaba: dead=true; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: else if(data[y+1][x]=='\\' && data[y][x+1]==' ' && data[y+1][x+1]==' ') { a06a38e3e6 2012-07-13 kinaba: next[y][x]=' '; a06a38e3e6 2012-07-13 kinaba: next[y+1][x+1]='*'; d0766ecd1b 2012-07-13 kinaba: if(next[y+2][x+1]=='R') d0766ecd1b 2012-07-13 kinaba: dead=true; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: else if(data[y][x]=='L') { a06a38e3e6 2012-07-13 kinaba: if(!lambda) a06a38e3e6 2012-07-13 kinaba: next[y][x] = 'O'; a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: data = next; c357edc016 2012-07-14 kinaba: c357edc016 2012-07-14 kinaba: if(flooding) { c357edc016 2012-07-14 kinaba: flooding_counter ++; c357edc016 2012-07-14 kinaba: if(flooding_counter == flooding) { c357edc016 2012-07-14 kinaba: flooding_counter = 0; c357edc016 2012-07-14 kinaba: water --; c357edc016 2012-07-14 kinaba: } c357edc016 2012-07-14 kinaba: bool wa = false; c357edc016 2012-07-14 kinaba: for(int y=water; y+1<H; ++y) c357edc016 2012-07-14 kinaba: for(int x=1; x+1<W; ++x) c357edc016 2012-07-14 kinaba: if(data[y][x]=='R') { c357edc016 2012-07-14 kinaba: wa = true; c357edc016 2012-07-14 kinaba: underwater++; c357edc016 2012-07-14 kinaba: if(underwater > water_proof) c357edc016 2012-07-14 kinaba: dead = true; c357edc016 2012-07-14 kinaba: } c357edc016 2012-07-14 kinaba: if(!wa) c357edc016 2012-07-14 kinaba: underwater = 0; c357edc016 2012-07-14 kinaba: } c357edc016 2012-07-14 kinaba: } 05e91f8e53 2012-07-14 kinaba: 05e91f8e53 2012-07-14 kinaba: int clever() 05e91f8e53 2012-07-14 kinaba: { 05e91f8e53 2012-07-14 kinaba: if(dead) 05e91f8e53 2012-07-14 kinaba: return 0; 05e91f8e53 2012-07-14 kinaba: int sy,sx; 05e91f8e53 2012-07-14 kinaba: int[] ly,lx; 05e91f8e53 2012-07-14 kinaba: int oy,ox; 05e91f8e53 2012-07-14 kinaba: for(int y=0; y<H; ++y) 05e91f8e53 2012-07-14 kinaba: for(int x=0; x<W; ++x) 05e91f8e53 2012-07-14 kinaba: if(data[y][x]=='R') 05e91f8e53 2012-07-14 kinaba: sy=y, sx=x; 05e91f8e53 2012-07-14 kinaba: else if(data[y][x]=='\\') 05e91f8e53 2012-07-14 kinaba: ly~=y, lx~=x; 05e91f8e53 2012-07-14 kinaba: else if(data[y][x]=='O') 05e91f8e53 2012-07-14 kinaba: oy=y, ox=x; 8c5c274847 2012-07-14 kinaba: if(ly.length==0) { 8c5c274847 2012-07-14 kinaba: auto r = search(sy,sx,oy,ox); 8c5c274847 2012-07-14 kinaba: switch(r[0]) { 8c5c274847 2012-07-14 kinaba: case 'D': return command_D(); 8c5c274847 2012-07-14 kinaba: case 'U': return command_U(); 8c5c274847 2012-07-14 kinaba: case 'L': return command_L(); 8c5c274847 2012-07-14 kinaba: case 'R': return command_R(); 8c5c274847 2012-07-14 kinaba: case 'A': return abort(); 8c5c274847 2012-07-14 kinaba: default: return wait(); 8c5c274847 2012-07-14 kinaba: } 45f53ef26a 2012-07-14 kinaba: } else { 45f53ef26a 2012-07-14 kinaba: Tuple!(char,int)[] cand; 45f53ef26a 2012-07-14 kinaba: for(int i=0; i<ly.length; ++i) { 45f53ef26a 2012-07-14 kinaba: auto r = search(sy,sx,ly[i],lx[i]); 45f53ef26a 2012-07-14 kinaba: cand ~= r; 45f53ef26a 2012-07-14 kinaba: } 45f53ef26a 2012-07-14 kinaba: sort!((Tuple!(char,int) c1, Tuple!(char,int) c2){ 45f53ef26a 2012-07-14 kinaba: if(c1[1] != c2[1]) 45f53ef26a 2012-07-14 kinaba: return c1[1] < c2[1]; 45f53ef26a 2012-07-14 kinaba: return c1[0] < c2[0]; 45f53ef26a 2012-07-14 kinaba: })(cand); 45f53ef26a 2012-07-14 kinaba: switch(cand[0][0]) { 45f53ef26a 2012-07-14 kinaba: case 'D': return command_D(); 45f53ef26a 2012-07-14 kinaba: case 'U': return command_U(); 45f53ef26a 2012-07-14 kinaba: case 'L': return command_L(); 45f53ef26a 2012-07-14 kinaba: case 'R': return command_R(); 45f53ef26a 2012-07-14 kinaba: case 'A': return abort(); 45f53ef26a 2012-07-14 kinaba: default: return wait(); 45f53ef26a 2012-07-14 kinaba: } 8c5c274847 2012-07-14 kinaba: } 05e91f8e53 2012-07-14 kinaba: return wait(); 05e91f8e53 2012-07-14 kinaba: } 8c5c274847 2012-07-14 kinaba: Tuple!(char,int) search(int sy, int sx, int oy, int ox) 05e91f8e53 2012-07-14 kinaba: { 4bdb07bffb 2012-07-14 kinaba: alias Tuple!(int,"y",int,"x") Pt; 4bdb07bffb 2012-07-14 kinaba: Pt[] q = [Pt(oy,ox)]; 45f53ef26a 2012-07-14 kinaba: bool[][] v = new bool[][](H,W); 8c5c274847 2012-07-14 kinaba: for(int step=1; q.length; ++step) { 4bdb07bffb 2012-07-14 kinaba: Pt[] q2; 4bdb07bffb 2012-07-14 kinaba: foreach(p; q) { 4bdb07bffb 2012-07-14 kinaba: int[] dy=[-1,+1,0,0]; 4bdb07bffb 2012-07-14 kinaba: int[] dx=[0,0,-1,+1]; 4bdb07bffb 2012-07-14 kinaba: for(int i=0; i<4; ++i) { 4bdb07bffb 2012-07-14 kinaba: int y = p.y+dy[i]; 4bdb07bffb 2012-07-14 kinaba: int x = p.x+dx[i]; 45f53ef26a 2012-07-14 kinaba: if(v[y][x]) continue; 4bdb07bffb 2012-07-14 kinaba: if(y==sy && x==sx) { 8c5c274847 2012-07-14 kinaba: if(i==0) return tuple('D',step); 8c5c274847 2012-07-14 kinaba: if(i==1) return tuple('U',step); 8c5c274847 2012-07-14 kinaba: if(i==2) return tuple('R',step); 8c5c274847 2012-07-14 kinaba: if(i==3) return tuple('L',step); 8c5c274847 2012-07-14 kinaba: } else if(data[y][x]==' '||data[y][x]=='\\') { 4bdb07bffb 2012-07-14 kinaba: q2 ~= Pt(y,x); 45f53ef26a 2012-07-14 kinaba: v[y][x]=true; 4bdb07bffb 2012-07-14 kinaba: } else if(data[y][x]=='.' && data[y-1][x]!='*') { 4bdb07bffb 2012-07-14 kinaba: q2 ~= Pt(y,x); 45f53ef26a 2012-07-14 kinaba: v[y][x]=true; 4bdb07bffb 2012-07-14 kinaba: } 4bdb07bffb 2012-07-14 kinaba: } 4bdb07bffb 2012-07-14 kinaba: } 4bdb07bffb 2012-07-14 kinaba: q = q2; 4bdb07bffb 2012-07-14 kinaba: } 4bdb07bffb 2012-07-14 kinaba: q = [Pt(oy,ox)]; 45f53ef26a 2012-07-14 kinaba: v = new bool[][](H,W); 8c5c274847 2012-07-14 kinaba: for(int step=1<<10; q.length; ++step) { 4bdb07bffb 2012-07-14 kinaba: Pt[] q2; 4bdb07bffb 2012-07-14 kinaba: foreach(p; q) { 4bdb07bffb 2012-07-14 kinaba: 4bdb07bffb 2012-07-14 kinaba: int[] dy=[-1,+1,0,0]; 4bdb07bffb 2012-07-14 kinaba: int[] dx=[0,0,-1,+1]; 4bdb07bffb 2012-07-14 kinaba: for(int i=0; i<4; ++i) { 4bdb07bffb 2012-07-14 kinaba: int y = p.y+dy[i]; 4bdb07bffb 2012-07-14 kinaba: int x = p.x+dx[i]; 45f53ef26a 2012-07-14 kinaba: if(v[y][x]) continue; 4bdb07bffb 2012-07-14 kinaba: if(y==sy && x==sx) { 8c5c274847 2012-07-14 kinaba: if(i==0) return tuple('D',step); 8c5c274847 2012-07-14 kinaba: if(i==1) return tuple('U',step); 8c5c274847 2012-07-14 kinaba: if(i==2) return tuple('R',step); 8c5c274847 2012-07-14 kinaba: if(i==3) return tuple('L',step); 8c5c274847 2012-07-14 kinaba: } else if(data[y][x]==' '||data[y][x]=='\\') { 4bdb07bffb 2012-07-14 kinaba: q2 ~= Pt(y,x); 45f53ef26a 2012-07-14 kinaba: v[y][x]=true; 4bdb07bffb 2012-07-14 kinaba: } else if(data[y][x]=='.'/* && data[y-1][x]!='*'*/) { 4bdb07bffb 2012-07-14 kinaba: q2 ~= Pt(y,x); 45f53ef26a 2012-07-14 kinaba: v[y][x]=true; 4bdb07bffb 2012-07-14 kinaba: } 4bdb07bffb 2012-07-14 kinaba: } 4bdb07bffb 2012-07-14 kinaba: } 4bdb07bffb 2012-07-14 kinaba: q = q2; 4bdb07bffb 2012-07-14 kinaba: } 8c5c274847 2012-07-14 kinaba: return tuple('A',int.max); 05e91f8e53 2012-07-14 kinaba: } b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: b59ee91407 2012-07-13 kinaba: class MyForm : Form b59ee91407 2012-07-13 kinaba: { b59ee91407 2012-07-13 kinaba: Map m; 8f5135c552 2012-07-13 kinaba: int score; 8f5135c552 2012-07-13 kinaba: b59ee91407 2012-07-13 kinaba: this(Map m) b59ee91407 2012-07-13 kinaba: { b59ee91407 2012-07-13 kinaba: noMessageFilter(); b59ee91407 2012-07-13 kinaba: this.m = m; 7693c375f5 2012-07-14 kinaba: this.text = .text("Score: ", score, " air[",m.water_proof-m.underwater,"]"); b59ee91407 2012-07-13 kinaba: this.keyDown ~= &myKey; 8f5135c552 2012-07-13 kinaba: this.score = 0; b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: override void onResize(EventArgs ev) { b59ee91407 2012-07-13 kinaba: invalidate(); b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: override void onPaint(PaintEventArgs ev) b59ee91407 2012-07-13 kinaba: { 29ace8e5eb 2012-07-13 kinaba: int Z = min(this.clientSize.width/(m.W-2), this.clientSize.height/(m.H-2)); b59ee91407 2012-07-13 kinaba: Font font = new Font("MS Gothic", Z-4); b59ee91407 2012-07-13 kinaba: Graphics g = ev.graphics; c357edc016 2012-07-14 kinaba: g.fillRectangle(Color(0,233,255), Rect(0,Z*(m.water-1),this.clientSize.width,this.clientSize.height-(Z*(m.water-1)))); b59ee91407 2012-07-13 kinaba: for(int y=1; y+1<m.H; ++y) b59ee91407 2012-07-13 kinaba: for(int x=1; x+1<m.W; ++x) { b59ee91407 2012-07-13 kinaba: if(m.data[y][x]=='*') { b59ee91407 2012-07-13 kinaba: g.drawText("岩", font, Color(0,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: if(m.data[y][x]=='\\') { b59ee91407 2012-07-13 kinaba: g.drawText("λ", font, Color(0,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: if(m.data[y][x]=='R') { d0766ecd1b 2012-07-13 kinaba: if(m.dead) d0766ecd1b 2012-07-13 kinaba: g.drawText("Я", font, Color(255,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); d0766ecd1b 2012-07-13 kinaba: else d0766ecd1b 2012-07-13 kinaba: g.drawText("R", font, Color(128,128,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: if(m.data[y][x]=='L') { 4027d34fe8 2012-07-13 kinaba: g.drawText("扉", font, Color(255,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: if(m.data[y][x]=='O') { 4027d34fe8 2012-07-13 kinaba: g.drawText("外", font, Color(255,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: if(m.data[y][x]=='#') { b59ee91407 2012-07-13 kinaba: g.drawText("#", font, Color(0,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: if(m.data[y][x]=='.') { b59ee91407 2012-07-13 kinaba: g.drawText("・", font, Color(128,40,0), Rect((x-1)*Z, (y-1)*Z, Z, Z)); b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: } b59ee91407 2012-07-13 kinaba: void myKey(Control c, KeyEventArgs ev) b59ee91407 2012-07-13 kinaba: { b59ee91407 2012-07-13 kinaba: switch(ev.keyCode) b59ee91407 2012-07-13 kinaba: { b59ee91407 2012-07-13 kinaba: case Keys.DOWN: 8f5135c552 2012-07-13 kinaba: score += m.command_D(); 8f5135c552 2012-07-13 kinaba: stdout.flush(); b59ee91407 2012-07-13 kinaba: break; b59ee91407 2012-07-13 kinaba: case Keys.UP: 8f5135c552 2012-07-13 kinaba: score += m.command_U(); 8f5135c552 2012-07-13 kinaba: stdout.flush(); b59ee91407 2012-07-13 kinaba: break; b59ee91407 2012-07-13 kinaba: case Keys.LEFT: 8f5135c552 2012-07-13 kinaba: score += m.command_L(); 8f5135c552 2012-07-13 kinaba: stdout.flush(); 8f5135c552 2012-07-13 kinaba: break; b59ee91407 2012-07-13 kinaba: case Keys.RIGHT: 8f5135c552 2012-07-13 kinaba: score += m.command_R(); 8f5135c552 2012-07-13 kinaba: stdout.flush(); b59ee91407 2012-07-13 kinaba: break; b59ee91407 2012-07-13 kinaba: case Keys.W: 8f5135c552 2012-07-13 kinaba: score += m.wait(); 246bed04b3 2012-07-13 kinaba: stdout.flush(); 246bed04b3 2012-07-13 kinaba: break; 246bed04b3 2012-07-13 kinaba: case Keys.A: 246bed04b3 2012-07-13 kinaba: score += m.abort(); 05e91f8e53 2012-07-14 kinaba: stdout.flush(); 05e91f8e53 2012-07-14 kinaba: break; 05e91f8e53 2012-07-14 kinaba: case Keys.G: 05e91f8e53 2012-07-14 kinaba: score += m.clever(); 8f5135c552 2012-07-13 kinaba: stdout.flush(); b59ee91407 2012-07-13 kinaba: break; b59ee91407 2012-07-13 kinaba: default: b59ee91407 2012-07-13 kinaba: break; b59ee91407 2012-07-13 kinaba: } 246bed04b3 2012-07-13 kinaba: if(m.cleared) { 246bed04b3 2012-07-13 kinaba: writeln(); 246bed04b3 2012-07-13 kinaba: writeln("Score: ", score); 246bed04b3 2012-07-13 kinaba: Application.exit(); 246bed04b3 2012-07-13 kinaba: } 7693c375f5 2012-07-14 kinaba: this.text = .text("Score: ", score, " air[",m.water_proof-m.underwater,"]"); b59ee91407 2012-07-13 kinaba: invalidate(); a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: } a06a38e3e6 2012-07-13 kinaba: a06a38e3e6 2012-07-13 kinaba: void main(string[] args) a06a38e3e6 2012-07-13 kinaba: { b59ee91407 2012-07-13 kinaba: Form myForm = new MyForm(new Map(File(args[1]))); b59ee91407 2012-07-13 kinaba: Application.run(myForm); a06a38e3e6 2012-07-13 kinaba: }