一个J2ME地牢游戏的源码 |
| 作者:J2MEDEV 来源:J2MEDEV 发布时间:2006-7-25 9:06:59 |
|
lack g.setColor(BLACK); g.fillRect(CORNER_X, CORNER_Y + DISP_HEIGHT - TIMER_HEIGHT, DISP_WIDTH, TIMER_HEIGHT); // paint the LayerManager (which paints // all of the interesting graphics): try { myManager.paint(g); } catch (Exception e) { myDungeon.errorMsg(e); } // draw the time g.setColor(WHITE); g.setFont(FONT); g.drawString("Time: " + formatTime(), DISP_WIDTH / 2, CORNER_Y + DISP_HEIGHT - 4, g.BOTTOM | g.HCENTER); // write "Dungeon Completed" when the user finishes a board: if (myGameOver) { myDungeon.setNewCommand(); // clear the top region: g.setColor(WHITE); g.fillRect(CORNER_X, CORNER_Y, DISP_WIDTH, FONT_HEIGHT * 2 + 1); int goWidth = FONT.stringWidth("Dungeon Completed"); g.setColor(BLACK); g.setFont(FONT); g.drawString("Dungeon Completed", (DISP_WIDTH - goWidth) / 2, CORNER_Y + FONT_HEIGHT, g.TOP | g.LEFT); } } /** * a simple utility to make the number of ticks look like a time... */ public String formatTime() { if ((myGameTicks / 16) != myOldGameTicks) { myTimeString = ""; myOldGameTicks = (myGameTicks / 16) + 1; int smallPart = myOldGameTicks % 60; int bigPart = myOldGameTicks / 60; myTimeString += bigPart + ":"; if (smallPart / 10 < 1) { myTimeString += "0"; } myTimeString += smallPart; } return (myTimeString); } //------------------------------------------------------- // game movements /** * update the display. */ void updateScreen() { myGameTicks++; // paint the display try { paint(getGraphics()); flushGraphics(CORNER_X, CORNER_Y, DISP_WIDTH, DISP_HEIGHT); } catch (Exception e) { myDungeon.errorMsg(e); } } /** * Respond to keystrokes. */ public void checkKeys() { if (!myGameOver) { int vertical = 0; int horizontal = 0; // determine which moves the user would like to make: int keyState = getKeyStates(); if ((keyState & LEFT_PRESSED) != 0) { horizontal = -1; } if ((keyState & RIGHT_PRESSED) != 0) { horizontal = 1; } if ((keyState & UP_PRESSED) != 0) { vertical = -1; } if ((keyState & DOWN_PRESSED) != 0) { // if the user presses the down key, // we put down or pick up a key object // or pick up the crown: myManager.putDownPickUp(); } // tell the manager to move the player // accordingly if possible: myManager.requestMove(horizontal, vertical); } } } |
| [] [返回上一页] [打 印] |
|
文章评论 |
