Diff
Not logged in

Differences From Artifact [7e3fd51446530418]:

To Artifact [e32629a48328bd3f]:


5 5 import std.string; 6 6 import dfl.all; 7 7 8 8 class Map 9 9 { 10 10 private char[][] data; 11 11 bool dead = false; 12 + bool cleared = false; 12 13 13 14 this(File input) 14 15 { 15 16 foreach(s; input.byLine()) 16 17 data ~= s.chomp.dup; 17 18 18 19 int width = 0; ................................................................................ 48 49 } 49 50 50 51 int command_R() { return move(0, +1); } 51 52 int command_L() { return move(0, -1); } 52 53 int command_U() { return move(-1, 0); } 53 54 int command_D() { return move(+1, 0); } 54 55 int wait() { if(dead)return 0; update(); return -1; } 56 + int abort() { if(dead)return 0; cleared=true; return gained*25; } 55 57 56 58 int move(int dy, int dx) { 57 59 foreach(y,s; data) 58 60 foreach(x,c; s) 59 61 if(c == 'R') 60 62 return move(dy, dx, y, x); 61 63 assert(false); ................................................................................ 66 68 if(dead) 67 69 return 0; 68 70 int score = 0; 69 71 if(data[y+dy][x+dx]=='\\') { 70 72 score += 25; 71 73 ++gained; 72 74 } 73 - if(data[y+dy][x+dx]=='O') 75 + if(data[y+dy][x+dx]=='O') { 74 76 score += gained*50; 77 + cleared = true; 78 + } 75 79 76 80 if(data[y+dy][x+dx]==' ' || data[y+dy][x+dx]=='.' 77 81 || data[y+dy][x+dx]=='\\' || data[y+dy][x+dx]=='O') { 78 82 data[y][x]=' '; 79 83 data[y+dy][x+dx]='R'; 80 84 } else if(dy==0 && data[y+dy][x+dx]=='*' && data[y+2*dy][x+2*dx]==' ') { 81 85 data[y][x]=' '; ................................................................................ 207 211 stdout.flush(); 208 212 break; 209 213 case Keys.W: 210 214 score += m.wait(); 211 215 write("W"); 212 216 stdout.flush(); 213 217 break; 218 + case Keys.A: 219 + score += m.abort(); 220 + write("A"); 221 + stdout.flush(); 222 + break; 214 223 default: 215 224 break; 216 225 } 226 + if(m.cleared) { 227 + writeln(); 228 + writeln("Score: ", score); 229 + Application.exit(); 230 + } 217 231 this.text = .text("Score: ", score); 218 232 invalidate(); 219 233 } 220 234 } 221 235 222 236 void main(string[] args) 223 237 { 224 238 Form myForm = new MyForm(new Map(File(args[1]))); 225 239 Application.run(myForm); 226 240 }