Diff
Not logged in

Differences From Artifact [7e3fd51446530418]:

To Artifact [e32629a48328bd3f]:


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