首先我要装得像高手一样,来假装把系统稍微分析一下。
一般,按照java得开发模式,这种程序一般是分为三个模块来开发。
如下三个:
一个程序运作的主文件,也就是一个midlet的继承;
一
个界面的表示类,也就是一个canvas的继承,界面上应该有些菜单,如new、exit 什么的,那就应该要 implements一个
commandListener消息监听类(大家可以把java的消息监听理解为一个线程,一直像倭寇那样对看得顺眼的东西虎视耽耽,当然这里指的是他所
能触及到的消息,当收到消息的时候,会调用一个抽象函数public void commandAction(Command c,
Displayable d),而这个抽象函数使得我们可以通过对他的实现来处理收到的消息,即消息响应)
最后一个当然就是与界面无关的逻辑单元了,在这里我们定义整个游戏的逻辑,做到逻辑与界面分开。这是我学java的最大收获,呵呵。
来自:低调一贱男, 时间:2003-10-25 23:28:00, ID:2252869 | 编辑
首先正式开始第一讲 <扫雷游戏的逻辑>
我的设想是,扫雷的地图一般是一个矩形,因为,圆形屏幕的手机看起来蛮变态的,没有必要迁就他,所以,我用一个a*b的二维数组就完全可以表示整个地图。
有了地图以后地图里面的类容自然就有一部分是表示地雷啦,既然这样,那不如就这样<废话来的,小朋友不要学>
/**
* 20 标志该位置为地雷
* <=10的数字表示未翻开的方块及周围的地雷数目
* >=10的数字表示已翻开的方块及周围的地雷数目
**/
表示方法就出来了,逻辑也明朗起来了。
我要将某个块翻开,只要将他加上10就可以了。
Java编程第一步,当然是先要class啊
1
2 package games;
3
4
5 import java.util.Random;
6 import java.lang.Math;
7
8 class gamelogic {
9
10 /** 表示一个10*10的棋盘 */
11 private int[][] pan = new int;
12 private Random random;// 一个随机变量,主要作用是用来指定哪些位置为地雷
13 private int BombNum = 0; // 统计地雷总数
14
15
16
17 /** 游戏是否结束 */
18 private boolean GameOver;
19
20
21
22 /*
23 * 接下来就是要初始化地图了,地图首先要扔一个雷在上面啊,不然怎么叫扫雷呢,扔完了地雷以后接下来当然是遍历一次地图(我们还是很仁慈d,我们得告诉扫雷d
24 * 同志,某某位置,有多少雷,比如这样:"01、01、12点中方向有地雷,14点钟方向有幺鸡,2点钟方向有东风之类的啊")。
25 */
26
27 /** 初始化数组,生成地图 */
28 public void InitArray() {
29 for (int i = 0; i < 8; i++) {
30 for (int j = 0; j < 8; j++) {
31 pan[i][j] = 0;
32 }
33 }
34
35 RandomArray();
36 CountBomb();
37 BombNum = Bomb();
38 }
39
40
41 /**
42 * 统计地雷总数
43 *
44 * @return int 返回地雷总数
45 */
46 private int Bomb() {
47 int count = 0;
48 for (int i = 0; i < 8; i++) {
49 for (int j = 0; j < 8; j++) {
50 if (pan[i][j] == 20) {
51 count += 1;
52 }
53 }
54 }
55
56 return count;
57 }
58
59
60 /** 随机决定地雷的位置 */
61 private void RandomArray() {
62 int i, j, k;
63
64 // 先扔15个左右的地雷吧,注意,这里不一定有15个哦,因为随机值可能重复,我不管啦
65 for (int r = 0; r < 15; r++) {
66 k = java.lang.Math.abs(random.nextInt()) % 64; // random.nextInt(100);
67 i = k / 8;
68 j = k % 8;
69 this.pan[i][j] = 20; // 指定该位置为地雷
70 }
71
72 }
73
74
75 /** 统计棋盘上的数据 */
76 private void CountBomb() {
77 for (int i = 0; i < 8; i++) {
78 for (int j = 0; j < 8; j++) {
79 int count = 0;
80
81 // 当需要检测的单元格本身无地雷的情况下,统计周围的地雷个数
82 if (pan[i][j] != 20) {
83 if ( (i - 1 >= 0) && (j - 1 >= 0)) {
84 if (pan[i - 1][j - 1] == 20) {
85 count += 1; // 检测左上方空格是否是地雷
86 }
87 }
88
89 if ( (i - 1 >= 0)) {
90 if (pan[i - 1][j] == 20) {
91 count += 1; // 检测上方空格是否为地雷
92 }
93 }
94
95 if ( (i - 1 >= 0) && (j + 1 <= 7)) {
96 if (pan[i - 1][j + 1] == 20) {
97 count += 1; // 检测右上方是否为地雷
98 }
99 }
100
101 if ( (j - 1 >= 0)) {
102 if (pan[i][j - 1] == 20) {
103 count += 1; // 检测左边是否为地雷
104 }
105 }
106
107 if ( (i >= 0) && (j + 1 <= 7)) {
108 if (pan[i][j + 1] == 20) {
109 count += 1; // 右边
110 }
111 }
112
113 if ( (j - 1 >= 0) && (i + 1 <= 7)) {
114 if (pan[i + 1][j - 1] == 20) {
115 count += 1; // 左下
116 }
117 }
118
119 if ( (i + 1 <= 7)) {
120 if (pan[i + 1][j] == 20) {
121 count += 1; // 下
122 }
123 }
124
125 if ( (j + 1 <= 7) && (i + 1 <= 7)) {
126 if (pan[i + 1][j + 1] == 20) {
127 count += 1; // 右下
128 }
129 }
130
131 pan[i][j] = count;
132 }
133 }
134 }
135 }
136
137
138
139 /**
140 * 检测已经被揭开的位置总和
141 *
142 * @return 返回被揭开的数量
143 */
144 private int countOpen() {
145 int count = 0;
146 for (int i = 0; i < 8; i++) {
147 for (int j = 0; j < 8; j++) {
148 if (pan[i][j] < 20 && pan[i][j] > 9) {
149 count += 1;
150 }
151 }
152 }
153
154 return count;
155 }
156
157
158
159 /**
160 * 检测是否胜利
161 *
162 * @return 是否胜利boolean值
163 */
164 public boolean isWin() {
165 // System.out.println(BombNum +""+ countOpen());
166 if ( (BombNum + countOpen()) == 64) {
167 this.GameOver = true;
168 return true;
169 }
170 else {
171 return false;
172 }
173 }
174
175
176 /**
177 * 选中棋盘上的位置,并翻开
178 *
179 * @param matrix
180 * 位置
181 */
182 public void openpan(int matrix) {
183 switch (getBomb(matrix)) {
184 case 20: // 当选中的位置为地雷,游戏结束
185 setGameOver();
186 break;
187 case 0:
188 isNull(matrix); // 当选中的位置为空,则翻开周围的地图
189 break;
190 default:
191 this.isNotNull(matrix); // 否则,翻开当前位置,并作上翻开的标记
192 }
193 }
194
195
196
197 /**
198 * 当选中的位置为空,则翻开周围的地图
199 *
200 * @param matrix
201 * 位置
202 */
203 private void isNull(int matrix) {
204 int i, j;
205 i = matrix / 8;
206 j = matrix % 8;
207
208 if (pan[i][j] < 9) {
209 pan[i][j] += 10;
210 }
211
212 if ( (i - 1 >= 0) && (j - 1 >= 0)) { // 检测左上方空格是否是空
213 if (pan[i - 1][j - 1] == 0) {
214 isNull( (i - 1) * 8 + (j - 1));
215 }
216 if (pan[i - 1][j - 1] < 9) {
217 pan[i - 1][j - 1] += 10;
218 }
219 }
220
221 if ( (i - 1 >= 0)) { // 检测上方空格是否为空
222 if (pan[i - 1][j] == 0) {
223 isNull( (i - 1) * 8 + j);
224 }
225 if (pan[i - 1][j] < 9) {
226 pan[i - 1][j] += 10;
227 }
228 }
229
230 if ( (i - 1 >= 0) && (j + 1 <= 7)) { // 检测右上方是否为空
231 if (pan[i - 1][j + 1] == 0) {
232 isNull( (i - 1) * 8 + (j + 1));
233 }
234 if (pan[i - 1][j + 1] < 9) {
235 pan[i - 1][j + 1] += 10;
236 }
237 }
238
239 if ( (j - 1 >= 0)) { // 检测左边是否为空
240 if (pan[i][j - 1] == 0) {
241 isNull(i * 8 + (j - 1));
242 }
243 if (pan[i][j - 1] < 9) {
244 pan[i][j - 1] += 10;
245 }
246 }
247
248 if ( (i >= 0) && (j + 1 <= 7)) { // 右边
249 if (pan[i][j + 1] == 0) {
250 isNull(i * 8 + (j + 1));
251 }
252 if (pan[i][j + 1] < 9) {
253 pan[i][j + 1] += 10;
254 }
255 }
256
257 if ( (j - 1 >= 0) && (i + 1 <= 7)) { // 左下
258 if (pan[i + 1][j - 1] == 0) {
259 isNull( (i + 1) * 8 + (j - 1));
260 }
261 if (pan[i + 1][j - 1] < 9) {
262 pan[i + 1][j - 1] += 10;
263 }
264 }
265
266 if ( (i + 1 <= 7)) { // 下
267 if (pan[i + 1][j] == 0) {
268 isNull( (i + 1) * 8 + j);
269 }
270 if (pan[i + 1][j] < 9) {
271 pan[i + 1][j] += 10;
272 }
273 }
274
275 if ( (j + 1 <= 7) && (i + 1 <= 7)) { // 右下
276 if (pan[i + 1][j + 1] == 0) {
277 isNull( (i + 1) * 8 + (j + 1));
278 }
279 if (pan[i + 1][j + 1] < 9) {
280 pan[i + 1][j + 1] += 10;
281 }
282 }
283 }
284
285
286
287 /**
288 * 选中棋盘上的位置,并翻开当前位置
289 *
290 * @param matrix
291 * 位置
292 */
293 private void isNotNull(int matrix) {
294 int i, j;
295 i = matrix / 8;
296 j = matrix % 8;
297 pan[i][j] += 10;
298 }
299
300
301 /**
302 * 取得指定位置的数据
303 *
304 * @param matrix
305 * 位置
306 * @return int 数据
307 */
308 public int getBomb(int matrix) {
309 int i, j;
310 i = matrix / 8;
311 j = matrix % 8;
312 return this.pan[i][j];
313 }
314
315
316 /**
317 * 检测游戏是否结束
318 *
319 * @return boolean 游戏是否结束的状态
320 */
321 public boolean isGameOver() {
322 return GameOver;
323 }
324
325
326 /** 设置游戏结束 */
327 private void setGameOver() {
328 GameOver = true;
329 }
330
331
332 /** 开新局 */
333
334 public void setNewGame() {
335 this.GameOver = false;
336 }
337
338
339 /**
340 * 指定位置是否被揭开
341 *
342 * @param matrix
343 * 位置
344 * @return boolean 返回是否可以被揭开
345 */
346 public boolean isFree(int matrix) {
347 int i, j;
348 i = matrix / 8;
349 j = matrix % 8;
350 return pan[i][j] < 8 || pan[i][j] == 20;
351 }
352
353 }
354
来自:低调一贱男, 时间:2003-10-25 23:46:00, ID:2252881 | 编辑
public void openpan(int matrix) 是整个程序的核心所在,他描述了所有的动作,
1、有可能你踩到屎,踩到屎当然就gameover啦
2、有可能踩到钱,有一大片空地给你玩
3、命好,没有炸死你,继续探索
来自:低调一贱男, 时间:2003-10-25 23:47:00, ID:2252882 | 编辑
呵呵,第一讲先到这里,下次讲界面的实现
来自:低调一贱男, 时间:2003-10-27 17:38:00, ID:2255425 | 编辑
今天考试,所以现在才开始第二讲,见谅,不过好像感兴趣的人不多,所以,我讲完这个例子就停了,如转载请注明 作者
来自:yanyandt2, 时间:2003-10-27 17:45:00, ID:2255447
请问你这个东西我在PC上能实现吗?
我最近也想学java,可是我不知道能用java来做什么。
jbuilder太大,我的机器跑不动,
做网页又不喜欢,
还希望楼主能给迷茫的我指导一下,谢谢!!
来自:低调一贱男, 时间:2003-10-27 17:57:00, ID:2255484 | 编辑
用jbuilder配置j2me比较方便,几乎不用配置,用记事本也可以写,用命令行运行,但是要装j2se,j2ee,然后配置一堆环境变量,然后还要用命令行来编译,审核,运行,一个基本上会死人,这也是我不用的原因,呵呵,具体步骤你到 http://www.cnjm.net/ 上去看看
来自:低调一贱男, 时间:2003-10-28 14:19:00, ID:2257384 | 编辑
呵呵,无人问津就只贴代码算了,搞到我都没有动力
1 //gamecCanvans.java
2 package games;
3 import java.lang.System.*;
4 import java.util.Random;
5 import java.util.Vector;
6 import javax.microedition.midlet.*;
7 import javax.microedition.lcdui.*;
8
9
10
11 /**
12 * 标题: Canvas测试
13 * 描述: 游戏的界面
14 * 版权: 2003
15 * 公司: none
* @author 刘昆
16 * @version 1.0*/
17
18
19 /**游戏动作类*/
20 class gameCanvas extends Canvas
21
22 implements CommandListener {
23
24 /**黑*/
25 private static final int BLACK = 0x00000000;
26
27 /**白*/
28 private static final int WHITE = 0x00FFFFFF;
29
30 /**红*/
31 private static final int RED = 0x00FF0000;
32
33 /**蓝*/
34 private static final int BLUE = 0x000000FF;
35
36 /**没有移动的标志*/
37 private static final int NO_MOVE = -1;
38
39 /**主窗体类*/
40 private final control midlet;
41
42 /**逻辑类*/
43 private final gamelogic game;
44
45 /**退出菜单*/
46 private final Command exitCommand;
47
48 /**重新开始菜单*/
49 private final Command newGameCommand;
50
51 /**随机数*/
52 private final Random random = new Random();
53
54 /**屏幕宽度*/
55 private int screenWidth;
56
57 /**屏幕高度*/
58 private int screenHeight;
59
60
61 /**boardCellSize 正方形单元格的大小,
62 * boardTop 棋盘top的位置,
63 * boardLeft 棋盘left位置*/
64 private int boardCellSize, boardTop, boardLeft;
65
66
67 /**preCursorPosition 前一次光标选择的位置,cursorPosition 当前光标选择的位置*/
68 private int preCursorPosition, cursorPosition;
69
70 /**用于存储被标记的地雷的位置 */
71 private Vector BombVector = new Vector();
72
73 private boolean isRestart;
74
75
76 /**构造器
77 * @param midlet 主窗体类 */
78 public gameCanvas(control midlet) {
79 this.midlet = midlet;
80 game = new gamelogic(random);
81 initializeBoard();
82
83 /**初始化菜单*/
84 exitCommand = new Command("退出", Command.EXIT, 1);
85 newGameCommand = new Command("新游戏", Command.SCREEN, 2);
86 addCommand(exitCommand);
87 addCommand(newGameCommand);
88 setCommandListener(this);
89
90 /**开始游戏*/
91 initialize();
92 }
93
94
95
96 /**添加一个地雷位置标记
97 *@param matrix 位置标记 */
98 private void addBomb(int matrix) {
99 BombVector.addElement(Integer.toString(matrix));
100 }
101
102
103
104 /**删除一个地雷位置标记
105 *@param matrix 位置标记 */
106 private void delBomb(int matrix) {
107 BombVector.removeElement(Integer.toString(matrix));
108 }
109
110
111
112 /**搜索该位置是否被标记
113 * @param matrix 位置标记
114 * @return boolean 该位置是否被记录,false为被记录 */
115 private boolean searchBomb(int matrix) {
116 return BombVector.indexOf(Integer.toString(matrix)) == -1; //-1表示没有找到该位置的信息
117 }
118
119
120 /**初始化屏幕,取得棋盘的初始位置*/
121 private void initializeBoard() {
122 screenWidth = getWidth(); //取得屏幕宽度
123 screenHeight = getHeight(); //取得屏幕高度
124 if (screenWidth > screenHeight) {
125 boardCellSize = (screenHeight - 1) / 8;
126 boardLeft = (screenWidth - (boardCellSize * 8)) / 2;
127 boardTop = 1;
128 }
129 else {
130 boardCellSize = (screenWidth - 1) / 8;
131 boardLeft = 1;
132 boardTop = (screenHeight - boardCellSize * 8) / 2;
133 }
134 }
135
136
137
138 /** 初始化游戏和屏幕. 使游戏重新启动*/
139 private void initialize() {
140 preCursorPosition = cursorPosition = 0;
141 game.setNewGame();
142 game.InitArray();
143 isRestart = true;
144 BombVector.removeAllElements();
145 repaint();
146 }
147
148
149
150 /**重画canvas
151 * @param g 重画的Graphics对象*/
152 public void paint(Graphics g) {
153 game.isWin();
154
155 if (!game.isGameOver()) {
156 paintGame(g);
157 }
158 else {
159 paintGameOver(g);
160 }
161 }
162
163
164
165 /**游戏未结束时的重画动作
166 * @param g 重画的Graphics对象*/
167 private void paintGame(Graphics g) {
168 if (isRestart) {
169 /*清除画板*/
170 g.setColor(0xbbbbbb);
171 g.fillRect(0, 0, screenWidth, screenHeight);
172 drawBoard(g);
173 paintAll(g);
174 //System.out.println("sss");//test
175 drawBombTag(g);
176 }
177
178 drawCursor(g);
179 }
180
181
182
183 /**游戏结束时的重画动作,画出游戏统计结果
184 * @param g 重画的Graphics对象 */
185 private void paintGameOver(Graphics g) {
186 if (game.isGameOver()) {
187 if (game.isWin()) {
188 GameOver(g);
189 }
190 else {
191 for (int i = 0; i < 8; i++) {
192 for (int j = 0; j < 8; j++) {
193 if (game.getBomb(i * 8 + j) == 20) {
194 drawCircle(g, i * 8 + j);
195 }
196 }
197 }
198 }
199 }
200 }
201
202
203
204 /**游戏结束时的重画动作
205 * @param g 重画的Graphics对象 */
206 private void GameOver(Graphics g) {
207
208 String tallyMsg = "你赢了,恭喜!";
209 Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,Font.SIZE_LARGE);
210 int strHeight = font.getHeight();
211 int tallyMsgWidth = font.stringWidth(tallyMsg);
212 int strWidth = tallyMsgWidth;
213
214 /*计算绘制文本的起始位置*/
215 int x = (screenWidth - strWidth) / 2;
216 x = x < 0 ? 0 : x;
217 int y = (screenHeight - 2 * strHeight) / 2;
218 y = y < 0 ? 0 : y;
219
220 /* 清除画板*/
221 g.setColor(WHITE);
222 g.fillRect(0, 0, screenWidth, screenHeight);
223
224 /* 画出文本结果*/
225 g.setColor(RED);
226 g.drawString(tallyMsg, x + 5, (y + 1 + strHeight),
(Graphics.TOP | Graphics.LEFT));
227 }
228
229
230
231 /**监听器响应接口
232 * @param c 命令
233 * @param d 消息源 */
234 public void commandAction(Command c, Displayable d) {
235 if (c == exitCommand) {
236 midlet.quit();
237 }
238 else if (c == newGameCommand) {
239 initialize();
240 }
241 }
242
243
244
245 /** 画圆,表示地雷位置
246 * @param g 图形物件
247 * @param matrix 位置*/
248 private void drawCircle(Graphics g, int matrix) {
249 int x, y;
250 y = matrix / 8;
251 x = matrix % 8;
252 g.setColor(RED);
253 g.fillArc(x * boardCellSize + boardLeft + 3, y * boardCellSize + boardTop + 2,
boardCellSize - 2, boardCellSize - 2, 0, 360);
254 }
255
256
257
258 /** 画叉,表示地雷爆炸
259 * @param g 图形物件
260 * @param x x坐标
261 * @param y y坐标 */
262 private void drawCross(Graphics g, int x, int y) {
263 g.setColor(RED);
264 g.drawLine(x + 1 + boardLeft, y + boardTop,
x + boardCellSize - 4 - 4 + boardLeft,
y + boardCellSize - 5 + boardTop);
265 g.drawLine(x + 1 + boardLeft,
y + boardCellSize - 5 + boardTop,
x + boardCellSize - 4 - 4 + boardLeft, y + boardTop);
266 }
267
268
269
270 /**根据玩家和电脑的移动重画棋盘*/
271 private void doPlayerMove() {
272 if (game.isFree(cursorPosition)) {
273 game.openpan(cursorPosition);
274 }
275 repaint(); //画出移动的图形结果
276 }
277
278
279
280 /**重画所有被揭开的文字
281 * @param g 图形物件 */
282 private void paintAll(Graphics g) {
283 for (int i = 0; i < 8; i++) {
284 for (int j = 0; j < 8; j++) {
285 if (game.getBomb(i * 8 + j) >= 10 && game.getBomb(i * 8 + j) < 20) {
286 paintNum(g, i * 8 + j);
287 }
288 }
289 }
290 }
291
292
293
294 /**画出文字
295 * @param g 图形物件
296 * @param matrix 位置 */
297 private void paintNum(Graphics g, int matrix) {
298 int i, j, s;
299 Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
300 s = game.getBomb(matrix);
301 //System.out.println(s);
302 i = matrix / 8;
303 j = matrix % 8;
304 g.setColor(WHITE);
305 if (this.searchBomb(matrix)) {
306 if (s != 20) {
307 g.drawString(String.valueOf(s - 10),
boardLeft + j * boardCellSize + 5,
boardTop + i * boardCellSize - 2,
(Graphics.TOP | Graphics.LEFT));
308 }
309 }
310 }
311
312
313
314 /**捕获按键消息
315 * @param keyCode 按键代码 */
316 protected void keyPressed(int keyCode) {
317 /**当游戏结束时返回*/
318 if (game.isGameOver()) {
319 return;
320 }
321
322 int gameAction = getGameAction(keyCode);
323
324 switch (gameAction) {
325 case FIRE:
326 if (searchBomb(cursorPosition)) { //如果该位置被做出了地雷标志,则该位置不能被揭开
327 doPlayerMove();
328 }
329 break;
330 case RIGHT:
331 doMoveCursor(1, 0);
332 break;
333 case DOWN:
334 doMoveCursor(0, 1);
335 break;
336 case LEFT:
337 doMoveCursor( -1, 0);
338 break;
339 case UP:
340 doMoveCursor(0, -1);
341 break;
342 default:
343 if (searchBomb(cursorPosition)) {
344 addBomb(cursorPosition);
345 }
346 else {
347 delBomb(cursorPosition);
348 }
349 repaint();
350 break;
351 }
352 }
353
354
355
356 /**画出棋盘上的地雷标志
357 * @param g 图形物件 */
358 private void drawBombTag(Graphics g) {
359 int s, j, k;
360 g.setColor(RED);
361 for (int i = 0; i < BombVector.size(); i++) {
362 s = Integer.parseInt( (String) BombVector.elementAt(i));
363 j = s % 8;
364 k = s / 8;
365 g.drawString("!", boardLeft + j * boardCellSize + 7,
boardTop + k * boardCellSize - 2,
(Graphics.TOP | Graphics.LEFT));
366 }
367 }
368
369
370
371 /**指定棋盘上的坐标
372 * @param dx 左右偏移量x
373 * @param dy 上下偏移量y */
374 private void doMoveCursor(int dx, int dy) {
375
376 int newCursorPosition = cursorPosition + dx + 8 * dy;
377 if ( (newCursorPosition >= 0) && (newCursorPosition < 64)) {
378 preCursorPosition = cursorPosition;
379 cursorPosition = newCursorPosition;
380 repaint();
381 }
382 }
383
384
385
386 /** 在棋盘上画出选择光标
387 * @param g 图形物件 */
388 private void drawCursor(Graphics g) {
389
390 /** 清除之前的选择光标*/
391 g.setColor(0xbbbbbb);
392 g.drawRect( ( (preCursorPosition % 8) * boardCellSize) + 3 + boardLeft,
( (preCursorPosition / 8) * boardCellSize) + 1 + boardTop,
boardCellSize - 2, boardCellSize - 2);
393
394 /**在当前选择位置画出选择光标*/
395 g.setColor(this.BLUE);
396 g.drawRect( ( (cursorPosition % 8) * boardCellSize) + 3 + boardLeft,
( (cursorPosition / 8) * boardCellSize) + 1 + boardTop,
boardCellSize - 2, boardCellSize - 2);
397 }
398
399
400
401 /** 画出空位置
402 * @param g 图形物件 */
403 private void drawNull(Graphics g) {
404
405 /**在当前选择位置画出选择光标*/
406 g.setColor(this.WHITE);
407 g.fillRect( ( (cursorPosition % 8) * boardCellSize) + 3 + boardLeft,
( (cursorPosition / 8) * boardCellSize) + 1 + boardTop,
boardCellSize - 2, boardCellSize - 2);
408 }
409
410
411
412 /**画一个盘
413 * @param g 图形物件 */
414 private void drawBoard(Graphics g) {
415
416 /** 清除盘*/
417 g.setColor(0xbbbbbb);
418 g.fillRect(0, 0, screenWidth, screenHeight);
419
420 /**画盘*/
421 g.setColor(BLACK);
422 for (int i = 0; i < 9; i++) {
423 g.fillRect(boardLeft + 2, boardCellSize * i + boardTop,
(boardCellSize * 8) + 1, 1); /*画四条黑色的横线*/
424 g.fillRect(boardCellSize * i + boardLeft + 2,
boardTop, 1, boardCellSize * 8); /*画四条黑色的竖线*/
425 }
426 }
427 }
428
来自:低调一贱男, 时间:2003-10-28 14:22:00, ID:2257393 | 编辑