Differences From Artifact [53cab87f74c4871d]:
- File
test.d
- 2012-07-13 13:17:25 - part of checkin [a06a38e3e6] on branch trunk - Hand playable. (user: kinaba) [annotate]
To Artifact [b27a6df805fe9112]:
- File
test.d
- 2012-07-13 14:16:22 - part of checkin [b59ee91407] on branch trunk - GUI version. (user: kinaba) [annotate]
1 1 import std.algorithm;
2 2 import std.array;
3 3 import std.conv;
4 4 import std.stdio;
5 5 import std.string;
6 +import dfl.all;
6 7
7 8 class Map
8 9 {
9 10 private char[][] data;
10 11
11 12 this(File input)
12 13 {
................................................................................
106 107 next[y][x] = 'O';
107 108 }
108 109 }
109 110 data = next;
110 111 }
111 112 }
112 113
113 -void main(string[] args)
114 +class MyForm : Form
114 115 {
115 - Map m = new Map(File(args[1]));
116 - for(;;) {
117 - writeln(m);
118 - write("> ");
119 - string s = readln();
120 - if(s.length == 0)
116 + Map m;
117 + this(Map m)
118 + {
119 + noMessageFilter();
120 + this.m = m;
121 + this.text = "Dark Integers";
122 + this.keyDown ~= &myKey;
123 + }
124 + override void onResize(EventArgs ev) {
125 + invalidate();
126 + }
127 + override void onPaint(PaintEventArgs ev)
128 + {
129 + int Z = min(this.clientSize.width, this.clientSize.height) / max(m.W-2, m.H-2);
130 + Font font = new Font("MS Gothic", Z-4);
131 + Graphics g = ev.graphics;
132 + for(int y=1; y+1<m.H; ++y)
133 + for(int x=1; x+1<m.W; ++x) {
134 + if(m.data[y][x]=='*') {
135 + g.drawText("岩", font, Color(0,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z));
136 + }
137 + if(m.data[y][x]=='\\') {
138 + g.drawText("λ", font, Color(0,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z));
139 + }
140 + if(m.data[y][x]=='R') {
141 + g.drawText("R", font, Color(128,128,0), Rect((x-1)*Z, (y-1)*Z, Z, Z));
142 + }
143 + if(m.data[y][x]=='L') {
144 + g.drawText("L", font, Color(255,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z));
145 + }
146 + if(m.data[y][x]=='O') {
147 + g.drawText("O", font, Color(255,255,0), Rect((x-1)*Z, (y-1)*Z, Z, Z));
148 + }
149 + if(m.data[y][x]=='#') {
150 + g.drawText("#", font, Color(0,0,0), Rect((x-1)*Z, (y-1)*Z, Z, Z));
151 + }
152 + if(m.data[y][x]=='.') {
153 + g.drawText("・", font, Color(128,40,0), Rect((x-1)*Z, (y-1)*Z, Z, Z));
154 + }
155 + }
156 + }
157 + void myKey(Control c, KeyEventArgs ev)
158 + {
159 + switch(ev.keyCode)
160 + {
161 + case Keys.DOWN:
162 + m.command_D();
163 + break;
164 + case Keys.UP:
165 + m.command_U();
166 + break;
167 + case Keys.LEFT:
168 + m.command_L();
169 + break;
170 + case Keys.RIGHT:
171 + m.command_R();
172 + break;
173 + case Keys.W:
174 + m.wait();
175 + break;
176 + default:
121 177 break;
122 - s = s.chomp().toUpper();
123 - if(s=="R")m.command_R();
124 - if(s=="L")m.command_L();
125 - if(s=="U")m.command_U();
126 - if(s=="D")m.command_D();
127 - if(s=="W")m.wait();
178 + }
179 + invalidate();
128 180 }
181 +}
129 182
183 +void main(string[] args)
184 +{
185 + Form myForm = new MyForm(new Map(File(args[1])));
186 + Application.run(myForm);
130 187 }