Index: test.d ================================================================== --- test.d +++ test.d @@ -7,10 +7,11 @@ class Map { private char[][] data; bool dead = false; + bool cleared = false; this(File input) { foreach(s; input.byLine()) data ~= s.chomp.dup; @@ -50,10 +51,11 @@ int command_R() { return move(0, +1); } int command_L() { return move(0, -1); } int command_U() { return move(-1, 0); } int command_D() { return move(+1, 0); } int wait() { if(dead)return 0; update(); return -1; } + int abort() { if(dead)return 0; cleared=true; return gained*25; } int move(int dy, int dx) { foreach(y,s; data) foreach(x,c; s) if(c == 'R') @@ -68,12 +70,14 @@ int score = 0; if(data[y+dy][x+dx]=='\\') { score += 25; ++gained; } - if(data[y+dy][x+dx]=='O') + if(data[y+dy][x+dx]=='O') { score += gained*50; + cleared = true; + } if(data[y+dy][x+dx]==' ' || data[y+dy][x+dx]=='.' || data[y+dy][x+dx]=='\\' || data[y+dy][x+dx]=='O') { data[y][x]=' '; data[y+dy][x+dx]='R'; @@ -209,13 +213,23 @@ case Keys.W: score += m.wait(); write("W"); stdout.flush(); break; + case Keys.A: + score += m.abort(); + write("A"); + stdout.flush(); + break; default: break; } + if(m.cleared) { + writeln(); + writeln("Score: ", score); + Application.exit(); + } this.text = .text("Score: ", score); invalidate(); } }