天涯明月刀-java游戏程序
现在去找任务使者,他会给你第一个任务。g.drawString("1. " + skillNames[selectedCharacter] + " (消耗10点气)", 70, HEIGHT - 120);g.drawString("当前任务: 消灭土匪 (" + (3 - enemies.size()) + "/3)", WIDTH - 250, 20);private String[] cha
以下是一个简化版的天涯明月刀风格游戏程序,使用Java Swing实现。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
public class MoonlightBladeGame extends JPanel implements ActionListener, KeyListener {
// 游戏常量
private static final int WIDTH = 800;
private static final int HEIGHT = 600;
private static final int PLAYER_SIZE = 40;
private static final int NPC_SIZE = 35;
private static final int ENEMY_SIZE = 35;
private static final int SKILL_RANGE = 100;
// 游戏状态
private enum GameState { MAIN_MENU, CHARACTER_SELECT, PLAYING, BATTLE, DIALOG, GAME_OVER }
private GameState gameState = GameState.MAIN_MENU;
// 游戏元素
private Player player;
private ArrayList<NPC> npcs;
private ArrayList<Enemy> enemies;
private ArrayList<Effect> effects;
private HashMap<String, Boolean> keysPressed;
private Random random;
private Timer timer;
// 游戏数据
private int playerHealth;
private int playerMaxHealth;
private int playerQi;
private int playerMaxQi;
private int playerLevel;
private int experience;
private int gold;
private int selectedCharacter;
private String currentDialog;
private int currentQuest;
// 图像资源(简化版使用颜色和形状代替)
private Color[] characterColors = {Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW};
private String[] characterNames = {"太白弟子", "天香弟子", "神威弟子", "唐门弟子"};
private String[] skillNames = {"剑舞九天", "回风落雁", "云台三落", "飞燕逐月"};
public MoonlightBladeGame() {
setPreferredSize(new Dimension(WIDTH, HEIGHT));
setBackground(new Color(30, 30, 50)); // 深蓝色背景,类似夜空
setFocusable(true);
addKeyListener(this);
random = new Random();
keysPressed = new HashMap<>();
initGame();
timer = new Timer(30, this);
timer.start();
}
private void initGame() {
player = new Player(WIDTH / 2, HEIGHT / 2);
npcs = new ArrayList<>();
enemies = new ArrayList<>();
effects = new ArrayList<>();
playerHealth = 100;
playerMaxHealth = 100;
playerQi = 50;
playerMaxQi = 50;
playerLevel = 1;
experience = 0;
gold = 0;
selectedCharacter = 0;
currentQuest = 0;
// 初始化NPC
npcs.add(new NPC(100, 100, "门派导师", "欢迎来到江湖,少侠请先选择你的门派。"));
npcs.add(new NPC(700, 500, "任务使者", "帮我消灭附近的土匪,我会给你丰厚的奖励。"));
npcs.add(new NPC(200, 400, "药店老板", "需要恢复气血吗?我这里有好药。"));
// 初始化敌人
spawnEnemies(3);
}
private void spawnEnemies(int count) {
for (int i = 0; i < count; i++) {
int x, y;
boolean validPosition;
do {
validPosition = true;
x = random.nextInt(WIDTH - ENEMY_SIZE);
y = random.nextInt(HEIGHT - ENEMY_SIZE);
// 确保敌人不会生成在玩家附近
if (Math.abs(x - player.x) < 150 && Math.abs(y - player.y) < 150) {
validPosition = false;
}
// 确保敌人不会相互重叠
for (Enemy enemy : enemies) {
if (Math.abs(x - enemy.x) < 50 && Math.abs(y - enemy.y) < 50) {
validPosition = false;
break;
}
}
} while (!validPosition);
enemies.add(new Enemy(x, y, "土匪", 30, 5));
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
switch (gameState) {
case MAIN_MENU:
drawMainMenu(g);
break;
case CHARACTER_SELECT:
drawCharacterSelect(g);
break;
case PLAYING:
drawGameWorld(g);
break;
case BATTLE:
drawBattle(g);
break;
case DIALOG:
drawDialog(g);
break;
case GAME_OVER:
drawGameOver(g);
break;
}
}
private void drawMainMenu(Graphics g) {
// 绘制背景
g.setColor(new Color(10, 10, 30));
g.fillRect(0, 0, WIDTH, HEIGHT);
// 绘制月亮
g.setColor(Color.YELLOW);
g.fillOval(WIDTH - 150, 50, 80, 80);
// 绘制标题
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.BOLD, 48));
g.drawString("天涯明月刀", WIDTH / 2 - 150, HEIGHT / 2 - 100);
// 绘制菜单选项
g.setFont(new Font("楷体", Font.PLAIN, 24));
g.drawString("按 Enter 键开始游戏", WIDTH / 2 - 120, HEIGHT / 2);
g.drawString("按 C 键选择角色", WIDTH / 2 - 100, HEIGHT / 2 + 40);
g.drawString("按 ESC 键退出", WIDTH / 2 - 80, HEIGHT / 2 + 80);
// 绘制版本信息
g.setFont(new Font("楷体", Font.PLAIN, 14));
g.drawString("江湖再起 • 剑指天涯", WIDTH / 2 - 70, HEIGHT - 50);
}
private void drawCharacterSelect(Graphics g) {
// 绘制背景
g.setColor(new Color(20, 20, 40));
g.fillRect(0, 0, WIDTH, HEIGHT);
// 绘制标题
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.BOLD, 36));
g.drawString("选择你的门派", WIDTH / 2 - 120, 80);
// 绘制角色选项
int startY = 150;
for (int i = 0; i < characterNames.length; i++) {
// 绘制角色框
if (i == selectedCharacter) {
g.setColor(new Color(100, 100, 200, 100));
g.fillRect(WIDTH / 2 - 150, startY + i * 80 - 10, 300, 70);
}
// 绘制角色颜色标识
g.setColor(characterColors[i]);
g.fillRect(WIDTH / 2 - 120, startY + i * 80, 40, 40);
// 绘制角色名称
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.PLAIN, 20));
g.drawString(characterNames[i], WIDTH / 2 - 60, startY + i * 80 + 25);
// 绘制角色技能
g.setFont(new Font("楷体", Font.PLAIN, 14));
g.drawString("绝技: " + skillNames[i], WIDTH / 2 - 60, startY + i * 80 + 45);
}
// 绘制操作提示
g.setFont(new Font("楷体", Font.PLAIN, 16));
g.drawString("使用 ↑ ↓ 键选择角色,按 Enter 键确认", WIDTH / 2 - 160, HEIGHT - 100);
g.drawString("按 ESC 键返回主菜单", WIDTH / 2 - 100, HEIGHT - 70);
}
private void drawGameWorld(Graphics g) {
// 绘制背景 - 简单的地面
g.setColor(new Color(50, 70, 40));
g.fillRect(0, HEIGHT / 2, WIDTH, HEIGHT / 2);
// 绘制一些简单的环境元素
g.setColor(new Color(80, 50, 30));
g.fillRect(100, HEIGHT / 2 - 50, 30, 50); // 树
g.fillRect(600, HEIGHT / 2 - 70, 40, 70); // 建筑
// 绘制NPC
g.setColor(Color.CYAN);
for (NPC npc : npcs) {
g.fillRect(npc.x, npc.y, NPC_SIZE, NPC_SIZE);
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.PLAIN, 12));
g.drawString(npc.name, npc.x, npc.y - 5);
}
// 绘制敌人
g.setColor(Color.RED);
for (Enemy enemy : enemies) {
g.fillRect(enemy.x, enemy.y, ENEMY_SIZE, ENEMY_SIZE);
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.PLAIN, 12));
g.drawString(enemy.name, enemy.x, enemy.y - 5);
// 绘制敌人血条
g.setColor(Color.RED);
g.fillRect(enemy.x, enemy.y - 15, ENEMY_SIZE, 5);
g.setColor(Color.GREEN);
g.fillRect(enemy.x, enemy.y - 15, (int)(ENEMY_SIZE * (enemy.health / 30.0)), 5);
}
// 绘制玩家
g.setColor(characterColors[selectedCharacter]);
g.fillRect(player.x, player.y, PLAYER_SIZE, PLAYER_SIZE);
// 绘制特效
for (Effect effect : effects) {
g.setColor(effect.color);
g.fillOval(effect.x, effect.y, effect.size, effect.size);
}
// 绘制UI
drawUI(g);
}
private void drawBattle(Graphics g) {
// 绘制战斗背景
g.setColor(new Color(40, 20, 20));
g.fillRect(0, 0, WIDTH, HEIGHT);
// 绘制敌人
if (!enemies.isEmpty()) {
Enemy enemy = enemies.get(0); // 假设只与一个敌人战斗
g.setColor(Color.RED);
g.fillRect(WIDTH / 2 - ENEMY_SIZE / 2, HEIGHT / 3, ENEMY_SIZE * 2, ENEMY_SIZE * 2);
// 绘制敌人血条
g.setColor(Color.RED);
g.fillRect(WIDTH / 2 - 100, HEIGHT / 3 - 30, 200, 10);
g.setColor(Color.GREEN);
g.fillRect(WIDTH / 2 - 100, HEIGHT / 3 - 30, (int)(200 * (enemy.health / 30.0)), 10);
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.PLAIN, 20));
g.drawString(enemy.name, WIDTH / 2 - 50, HEIGHT / 3 - 40);
}
// 绘制玩家
g.setColor(characterColors[selectedCharacter]);
g.fillRect(WIDTH / 2 - PLAYER_SIZE / 2, HEIGHT * 2 / 3, PLAYER_SIZE, PLAYER_SIZE);
// 绘制玩家血条和气条
g.setColor(Color.RED);
g.fillRect(WIDTH / 2 - 100, HEIGHT * 2 / 3 + PLAYER_SIZE + 10, 200, 10);
g.setColor(Color.GREEN);
g.fillRect(WIDTH / 2 - 100, HEIGHT * 2 / 3 + PLAYER_SIZE + 10, (int)(200 * (playerHealth / (double)playerMaxHealth)), 10);
g.setColor(Color.BLUE);
g.fillRect(WIDTH / 2 - 100, HEIGHT * 2 / 3 + PLAYER_SIZE + 25, 200, 10);
g.setColor(Color.CYAN);
g.fillRect(WIDTH / 2 - 100, HEIGHT * 2 / 3 + PLAYER_SIZE + 25, (int)(200 * (playerQi / (double)playerMaxQi)), 10);
// 绘制技能选项
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.PLAIN, 18));
g.drawString("技能选择:", 50, HEIGHT - 150);
g.drawString("1. " + skillNames[selectedCharacter] + " (消耗10点气)", 70, HEIGHT - 120);
g.drawString("2. 普通攻击", 70, HEIGHT - 90);
g.drawString("3. 防御", 70, HEIGHT - 60);
// 绘制操作提示
g.drawString("按对应数字键选择技能,按ESC退出战斗", WIDTH / 2 - 180, HEIGHT - 30);
}
private void drawDialog(Graphics g) {
// 绘制游戏世界背景
drawGameWorld(g);
// 绘制对话框
g.setColor(new Color(0, 0, 0, 200));
g.fillRect(50, HEIGHT - 150, WIDTH - 100, 100);
g.setColor(Color.WHITE);
g.drawRect(50, HEIGHT - 150, WIDTH - 100, 100);
// 绘制对话内容
g.setFont(new Font("楷体", Font.PLAIN, 16));
String[] lines = splitString(currentDialog, 60);
for (int i = 0; i < lines.length; i++) {
g.drawString(lines[i], 70, HEIGHT - 130 + i * 25);
}
// 绘制提示
g.drawString("按空格键继续", WIDTH - 150, HEIGHT - 60);
}
private void drawGameOver(Graphics g) {
g.setColor(new Color(30, 0, 0));
g.fillRect(0, 0, WIDTH, HEIGHT);
g.setColor(Color.RED);
g.setFont(new Font("楷体", Font.BOLD, 48));
g.drawString("江湖再见", WIDTH / 2 - 120, HEIGHT / 2 - 50);
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.PLAIN, 24));
g.drawString("等级: " + playerLevel, WIDTH / 2 - 50, HEIGHT / 2);
g.drawString("经验: " + experience, WIDTH / 2 - 50, HEIGHT / 2 + 40);
g.drawString("金币: " + gold, WIDTH / 2 - 50, HEIGHT / 2 + 80);
g.setFont(new Font("楷体", Font.PLAIN, 18));
g.drawString("按R键重新开始游戏", WIDTH / 2 - 100, HEIGHT / 2 + 140);
}
private void drawUI(Graphics g) {
// 绘制顶部状态栏
g.setColor(new Color(0, 0, 0, 150));
g.fillRect(0, 0, WIDTH, 60);
// 绘制角色信息
g.setColor(Color.WHITE);
g.setFont(new Font("楷体", Font.PLAIN, 14));
g.drawString(characterNames[selectedCharacter], 20, 20);
g.drawString("等级: " + playerLevel, 20, 40);
// 绘制血条
g.setColor(Color.RED);
g.fillRect(150, 10, 200, 15);
g.setColor(Color.GREEN);
g.fillRect(150, 10, (int)(200 * (playerHealth / (double)playerMaxHealth)), 15);
g.setColor(Color.WHITE);
g.drawRect(150, 10, 200, 15);
g.drawString("气血: " + playerHealth + "/" + playerMaxHealth, 360, 25);
// 绘制气条
g.setColor(Color.BLUE);
g.fillRect(150, 35, 200, 15);
g.setColor(Color.CYAN);
g.fillRect(150, 35, (int)(200 * (playerQi / (double)playerMaxQi)), 15);
g.setColor(Color.WHITE);
g.drawRect(150, 35, 200, 15);
g.drawString("内力: " + playerQi + "/" + playerMaxQi, 360, 50);
// 绘制经验值和金币
g.drawString("经验: " + experience, 500, 20);
g.drawString("金币: " + gold, 500, 40);
// 绘制任务提示
if (currentQuest == 0) {
g.drawString("当前任务: 与门派导师交谈", WIDTH - 250, 20);
} else if (currentQuest == 1) {
g.drawString("当前任务: 消灭土匪 (" + (3 - enemies.size()) + "/3)", WIDTH - 250, 20);
}
// 绘制操作提示
g.drawString("WASD移动, 空格交互, J攻击, K轻功, L技能", 20, HEIGHT - 20);
}
private String[] splitString(String str, int length) {
int parts = (str.length() + length - 1) / length;
String[] result = new String[parts];
for (int i = 0; i < parts; i++) {
int start = i * length;
int end = Math.min(start + length, str.length());
result[i] = str.substring(start, end);
}
return result;
}
@Override
public void actionPerformed(ActionEvent e) {
if (gameState == GameState.PLAYING) {
updateGame();
}
repaint();
}
private void updateGame() {
// 更新玩家位置
int dx = 0, dy = 0;
if (isKeyPressed("W")) dy -= 5;
if (isKeyPressed("S")) dy += 5;
if (isKeyPressed("A")) dx -= 5;
if (isKeyPressed("D")) dx += 5;
player.x = Math.max(0, Math.min(WIDTH - PLAYER_SIZE, player.x + dx));
player.y = Math.max(0, Math.min(HEIGHT - PLAYER_SIZE, player.y + dy));
// 更新特效
for (int i = effects.size() - 1; i >= 0; i--) {
Effect effect = effects.get(i);
effect.duration--;
if (effect.duration <= 0) {
effects.remove(i);
}
}
// 自动恢复内力
if (playerQi < playerMaxQi) {
playerQi = Math.min(playerMaxQi, playerQi + 1);
}
}
private boolean isKeyPressed(String key) {
return keysPressed.getOrDefault(key, false);
}
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
switch (gameState) {
case MAIN_MENU:
handleMainMenuInput(keyCode);
break;
case CHARACTER_SELECT:
handleCharacterSelectInput(keyCode);
break;
case PLAYING:
handlePlayingInput(keyCode);
break;
case BATTLE:
handleBattleInput(keyCode);
break;
case DIALOG:
handleDialogInput(keyCode);
break;
case GAME_OVER:
handleGameOverInput(keyCode);
break;
}
// 更新按键状态
if (keyCode == KeyEvent.VK_W) keysPressed.put("W", true);
if (keyCode == KeyEvent.VK_A) keysPressed.put("A", true);
if (keyCode == KeyEvent.VK_S) keysPressed.put("S", true);
if (keyCode == KeyEvent.VK_D) keysPressed.put("D", true);
}
@Override
public void keyReleased(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_W) keysPressed.put("W", false);
if (keyCode == KeyEvent.VK_A) keysPressed.put("A", false);
if (keyCode == KeyEvent.VK_S) keysPressed.put("S", false);
if (keyCode == KeyEvent.VK_D) keysPressed.put("D", false);
}
@Override
public void keyTyped(KeyEvent e) {}
private void handleMainMenuInput(int keyCode) {
if (keyCode == KeyEvent.VK_ENTER) {
gameState = GameState.PLAYING;
} else if (keyCode == KeyEvent.VK_C) {
gameState = GameState.CHARACTER_SELECT;
} else if (keyCode == KeyEvent.VK_ESCAPE) {
System.exit(0);
}
}
private void handleCharacterSelectInput(int keyCode) {
if (keyCode == KeyEvent.VK_UP) {
selectedCharacter = (selectedCharacter - 1 + characterNames.length) % characterNames.length;
} else if (keyCode == KeyEvent.VK_DOWN) {
selectedCharacter = (selectedCharacter + 1) % characterNames.length;
} else if (keyCode == KeyEvent.VK_ENTER) {
gameState = GameState.PLAYING;
} else if (keyCode == KeyEvent.VK_ESCAPE) {
gameState = GameState.MAIN_MENU;
}
}
private void handlePlayingInput(int keyCode) {
if (keyCode == KeyEvent.VK_SPACE) {
// 与NPC或敌人交互
for (NPC npc : npcs) {
if (isNear(player, npc)) {
currentDialog = npc.dialog;
gameState = GameState.DIALOG;
// 任务逻辑
if (npc.name.equals("门派导师") && currentQuest == 0) {
currentQuest = 1;
currentDialog = "很好,你已经选择了" + characterNames[selectedCharacter] + "的道路。现在去找任务使者,他会给你第一个任务。";
} else if (npc.name.equals("任务使者") && currentQuest == 1) {
if (enemies.isEmpty()) {
currentQuest = 2;
experience += 100;
gold += 50;
playerLevel++;
playerMaxHealth += 20;
playerHealth = playerMaxHealth;
playerMaxQi += 10;
playerQi = playerMaxQi;
currentDialog = "干得好!你已经完成了第一个任务。这是你的奖励。";
spawnEnemies(5); // 生成更多敌人
} else {
currentDialog = "你还没有消灭所有的土匪。继续努力!";
}
}
return;
}
}
for (Enemy enemy : enemies) {
if (isNear(player, enemy)) {
gameState = GameState.BATTLE;
return;
}
}
} else if (keyCode == KeyEvent.VK_J) {
// 普通攻击
for (Enemy enemy : enemies) {
if (isNear(player, enemy)) {
enemy.health -= 5;
effects.add(new Effect(enemy.x, enemy.y, Color.ORANGE, 20, 10));
if (enemy.health <= 0) {
enemies.remove(enemy);
experience += 10;
gold += 5;
// 检查任务完成情况
if (currentQuest == 1 && enemies.isEmpty()) {
currentDialog = "你已经消灭了所有土匪!回去找任务使者领取奖励吧。";
gameState = GameState.DIALOG;
}
}
break;
}
}
} else if (keyCode == KeyEvent.VK_K) {
// 轻功 - 快速移动
if (playerQi >= 5) {
int dx = 0, dy = 0;
if (isKeyPressed("W")) dy -= 20;
if (isKeyPressed("S")) dy += 20;
if (isKeyPressed("A")) dx -= 20;
if (isKeyPressed("D")) dx += 20;
player.x = Math.max(0, Math.min(WIDTH - PLAYER_SIZE, player.x + dx));
player.y = Math.max(0, Math.min(HEIGHT - PLAYER_SIZE, player.y + dy));
playerQi -= 5;
// 添加轻功特效
effects.add(new Effect(player.x, player.y, Color.WHITE, 30, 15));
}
} else if (keyCode == KeyEvent.VK_L) {
// 使用技能
if (playerQi >= 10) {
for (Enemy enemy : enemies) {
if (isNear(player, enemy)) {
enemy.health -= 15;
playerQi -= 10;
// 添加技能特效
effects.add(new Effect(enemy.x, enemy.y, characterColors[selectedCharacter], 40, 20));
if (enemy.health <= 0) {
enemies.remove(enemy);
experience += 10;
gold += 5;
// 检查任务完成情况
if (currentQuest == 1 && enemies.isEmpty()) {
currentDialog = "你已经消灭了所有土匪!回去找任务使者领取奖励吧。";
gameState = GameState.DIALOG;
}
}
break;
}
}
}
} else if (keyCode == KeyEvent.VK_ESCAPE) {
gameState = GameState.MAIN_MENU;
}
}
private void handleBattleInput(int keyCode) {
if (keyCode == KeyEvent.VK_ESCAPE) {
gameState = GameState.PLAYING;
} else if (keyCode >= KeyEvent.VK_1 && keyCode <= KeyEvent.VK_3 && !enemies.isEmpty()) {
Enemy enemy = enemies.get(0);
if (keyCode == KeyEvent.VK_1) {
// 使用技能
if (playerQi >= 10) {
enemy.health -= 15;
playerQi -= 10;
effects.add(new Effect(enemy.x, enemy.y, characterColors[selectedCharacter], 40, 20));
}
} else if (keyCode == KeyEvent.VK_2) {
// 普通攻击
enemy.health -= 5;
effects.add(new Effect(enemy.x, enemy.y, Color.ORANGE, 20, 10));
} else if (keyCode == KeyEvent.VK_3) {
// 防御 - 恢复少量气血
playerHealth = Math.min(playerMaxHealth, playerHealth + 5);
}
// 敌人攻击
if (enemy.health > 0) {
playerHealth -= enemy.damage;
}
// 检查战斗结果
if (enemy.health <= 0) {
enemies.remove(enemy);
experience += 10;
gold += 5;
gameState = GameState.PLAYING;
// 检查任务完成情况
if (currentQuest == 1 && enemies.isEmpty()) {
currentDialog = "你已经消灭了所有土匪!回去找任务使者领取奖励吧。";
gameState = GameState.DIALOG;
}
}
if (playerHealth <= 0) {
gameState = GameState.GAME_OVER;
}
}
}
private void handleDialogInput(int keyCode) {
if (keyCode == KeyEvent.VK_SPACE) {
gameState = GameState.PLAYING;
}
}
private void handleGameOverInput(int keyCode) {
if (keyCode == KeyEvent.VK_R) {
initGame();
gameState = GameState.MAIN_MENU;
}
}
private boolean isNear(Player p1, Object p2) {
int p2x, p2y, size;
if (p2 instanceof NPC) {
NPC npc = (NPC) p2;
p2x = npc.x;
p2y = npc.y;
size = NPC_SIZE;
} else if (p2 instanceof Enemy) {
Enemy enemy = (Enemy) p2;
p2x = enemy.x;
p2y = enemy.y;
size = ENEMY_SIZE;
} else {
return false;
}
return Math.abs(p1.x - p2x) < SKILL_RANGE && Math.abs(p1.y - p2y) < SKILL_RANGE;
}
// 玩家类
class Player {
int x, y;
Player(int x, int y) {
this.x = x;
this.y = y;
}
}
// NPC类
class NPC {
int x, y;
String name;
String dialog;
NPC(int x, int y, String name, String dialog) {
this.x = x;
this.y = y;
this.name = name;
this.dialog = dialog;
}
}
// 敌人类
class Enemy {
int x, y;
String name;
int health;
int damage;
Enemy(int x, int y, String name, int health, int damage) {
this.x = x;
this.y = y;
this.name = name;
this.health = health;
this.damage = damage;
}
}
// 特效类
class Effect {
int x, y;
Color color;
int size;
int duration;
Effect(int x, int y, Color color, int size, int duration) {
this.x = x;
this.y = y;
this.color = color;
this.size = size;
this.duration = duration;
}
}
public static void main(String[] args) {
JFrame frame = new JFrame("天涯明月刀");
MoonlightBladeGame game = new MoonlightBladeGame();
frame.add(game);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
游戏控制
· 主菜单:
· Enter:开始游戏
· C:角色选择
· ESC:退出游戏
· 角色选择:
· ↑↓:选择角色
· Enter:确认选择
· ESC:返回主菜单
· 游戏世界:
· WASD:移动角色
· 空格:与NPC或敌人交互
· J:普通攻击
· K:轻功(消耗内力)
· L:使用技能(消耗内力)
· ESC:返回主菜单
· 战斗模式:
· 1:使用技能
· 2:普通攻击
· 3:防御
· ESC:退出战斗
· 对话模式:
· 空格:继续
· 游戏结束:
· R:重新开始游戏
更多推荐


所有评论(0)