Index: test.d ================================================================== --- test.d +++ test.d @@ -44,24 +44,34 @@ } return result; } } - void command_R() { move(0, +1); } - void command_L() { move(0, -1); } - void command_U() { move(-1, 0); } - void command_D() { move(+1, 0); } - void wait() { update(); } + 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() { update(); return -1; } - void move(int dy, int dx) { + int move(int dy, int dx) { foreach(y,s; data) foreach(x,c; s) if(c == 'R') return move(dy, dx, y, x); + assert(false); } - void move(int dy, int dx, int y, int x) { + int gained = 0; // TODO: atode naosu + int move(int dy, int dx, int y, int x) { + int score = 0; + if(data[y+dy][x+dx]=='\\') { + score += 25; + ++gained; + } + if(data[y+dy][x+dx]=='O') + score += gained*50; + 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'; } else if(dy==0 && data[y+dy][x+dx]=='*' && data[y+2*dy][x+2*dx]==' ') { @@ -68,10 +78,11 @@ data[y][x]=' '; data[y+dy][x+dx]='R'; data[y+2*dy][x+2*dx]='*'; } update(); + return score-1; } void update() { char[][] next; foreach(y,s; data) @@ -112,16 +123,19 @@ } class MyForm : Form { Map m; + int score; + this(Map m) { noMessageFilter(); this.m = m; this.text = "Dark Integers"; this.keyDown ~= &myKey; + this.score = 0; } override void onResize(EventArgs ev) { invalidate(); } override void onPaint(PaintEventArgs ev) @@ -157,31 +171,42 @@ void myKey(Control c, KeyEventArgs ev) { switch(ev.keyCode) { case Keys.DOWN: - m.command_D(); + score += m.command_D(); + write("D"); + stdout.flush(); break; case Keys.UP: - m.command_U(); + score += m.command_U(); + write("U"); + stdout.flush(); break; case Keys.LEFT: - m.command_L(); - break; + score += m.command_L(); + write("L"); + stdout.flush(); + break; case Keys.RIGHT: - m.command_R(); + score += m.command_R(); + write("R"); + stdout.flush(); break; case Keys.W: - m.wait(); + score += m.wait(); + write("W"); + stdout.flush(); break; default: break; } + this.text = .text("Score: ", score); invalidate(); } } void main(string[] args) { Form myForm = new MyForm(new Map(File(args[1]))); Application.run(myForm); }