📄 slugsscreen.java
字号:
} else { index = id == 0 ? PLAYER1 : PLAYER2; } } else { switch (tag) { case Item.JET_PACK: index = JET_PACK; break; case Item.SHOVEL: index = SHOVEL; break; case Item.BOOSTER: index = BOOSTER; break; case Item.EXTRA_LIFE: index = EXTRA_LIFE; break; case Item.POISON: index = POISON; break; case Item.WALL: index = WALL; break; case Item.HOUSE: index = HOUSE; break; case Item.PATH1: index = PATH1; break; case Item.PATH2: index = PATH2; break; case Item.GRASS: // fall through case Item.DELETE: index = GRASS; break; case Item.JETPACK_COUNT: if (y == player_id) { // System.out.println("jetpack count is " + x + " for player " + y); setJetpacks(x); } return; case Item.SHOVEL_COUNT: if (y == player_id) { // System.out.println("shovel count is " + x + " for player " + y); setShovels(x); } return; case Item.LIFE_COUNT: if (y == player_id) { // System.out.println("life count is " + x + " for player " + y); setLives(x); } return; case Item.NEW_LEVEL: level_width = x; level_height = y; x_offset = (getWidth() - level_width * 5) / 2; y_offset = (getHeight() - font_offset - level_height * 5) / 2 + 1; buf_g.setColor(grass_green); buf_g.fillRect(0, 0, getWidth(), getHeight()); return; default: throw new RuntimeException("should not reach here"); } } buf_g.drawImage(img_list[index], x * 5 + x_offset, y * 5 + y_offset, Graphics.LEFT | Graphics.TOP); } /** * Repaint this instance */ public void paint(Graphics g) { if (showTitle) { paintTitle(g); showTitle = false; } else if (lives <= 0) { paintGameOver(g); } else { paintGame(g); } } private void paintGameOver(Graphics g) { g.setFont(font); g.setColor(grass_green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(white); g.drawString("G A M E O V E R", getWidth() / 2, getHeight() / 2, Graphics.HCENTER | Graphics.TOP); } private void paintTitle(Graphics g) { String string; int v_offset = 3; int h_offset = 8; int img_v_off = font_offset / 3; int img_h_off = 8; int anchor = Graphics.LEFT | Graphics.TOP; g.setFont(font); g.setColor(grass_green); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(white); g.drawString("-- S L U G S --", getWidth() / 2, v_offset, Graphics.HCENTER | Graphics.TOP); v_offset += font_offset; string = "Find home: "; g.drawString(string, h_offset, v_offset, anchor); g.drawImage(img_list[HOUSE], h_offset + font.stringWidth(string), img_v_off + v_offset, anchor); v_offset += font_offset; g.drawString("Avoid opponent, and", h_offset, v_offset, anchor); v_offset += font_offset * 3 / 4; string = "these: (unless"; g.drawString(string, h_offset, v_offset, anchor); g.drawImage(img_list[WALL], h_offset + font.substringWidth(string, 0, 7) + 0 * img_h_off, img_v_off + v_offset, anchor); g.drawImage(img_list[POISON], h_offset + font.substringWidth(string, 0, 7) + 1 * img_h_off, img_v_off + v_offset, anchor); g.drawImage(img_list[PATH1], h_offset + font.substringWidth(string, 0, 7) + 2 * img_h_off, img_v_off + v_offset, anchor); g.drawImage(img_list[PATH2], h_offset + font.substringWidth(string, 0, 7) + 3 * img_h_off, img_v_off + v_offset, anchor); v_offset += font_offset * 3 / 4; g.drawString("flying or digging)", h_offset, v_offset, anchor); v_offset += font_offset; string = "Fly: + '1'"; g.drawString(string, h_offset, v_offset, anchor); g.drawImage(img_list[JET_PACK], h_offset + font.substringWidth(string, 0, 5), img_v_off + v_offset, anchor); v_offset += font_offset; string = "Dig: + '3'"; g.drawString(string, h_offset, v_offset, anchor); g.drawImage(img_list[SHOVEL], h_offset + font.substringWidth(string, 0, 5), img_v_off + v_offset, anchor); v_offset += font_offset; string = "Extra life: "; g.drawString(string, h_offset, v_offset, anchor); g.drawImage(img_list[EXTRA_LIFE], h_offset + font.stringWidth(string), img_v_off + v_offset, anchor); v_offset += font_offset; string = "Boost speed: "; g.drawString(string, h_offset, v_offset, anchor); g.drawImage(img_list[BOOSTER], h_offset + font.stringWidth(string), img_v_off + v_offset, anchor); } private void paintGame(Graphics g) { long n; int i; int h_offset = 5; int v_offset = 4; int img_h_off = 7; int img_v_off = 3; int anchor = Graphics.LEFT | Graphics.TOP; g.setFont(font); g.drawImage(buf, 0, 0, anchor); fps++; n = System.currentTimeMillis() / 1000; if (n != last) { fps_string = "fps: " + fps; fps = 0; last = n; } g.setColor(white); g.drawString(fps_string, h_offset, v_offset, anchor); // level boundary g.drawRect(x_offset, y_offset, level_width * 5, level_height * 5); v_offset = getHeight() - font_offset; g.drawImage(img_list[EXTRA_LIFE], h_offset, v_offset + img_v_off, anchor); g.drawString(life_string, h_offset + img_h_off, v_offset, anchor); h_offset += 20; g.drawImage(img_list[SHOVEL], h_offset, v_offset + img_v_off, anchor); g.drawString(shovel_string, h_offset + img_h_off, v_offset, anchor); h_offset += 20; g.drawImage(img_list[JET_PACK], h_offset, v_offset + img_v_off, anchor); g.drawString(jetpack_string, h_offset + img_h_off, v_offset, anchor); h_offset += 20; g.drawString(score_string, h_offset, v_offset, anchor); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -