/*
* <p>项目名称: zhangguangyuan5377 </p>
* <p>文件名称: Test.java </p>
* <p>描述: [类型描述] </p>
* <p>创建时间: 2020年6月16日 </p>
* @author <a href="mail to: z1010223@126.com" rel="nofollow">张光远</a>
* @version v1.0
* @update [序号][日期YYYY-MM-DD] [更改人姓名][变更描述]
*/
package zhangguangyuan5377.test;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
import zhangguangyuan5377.behavior.*;
import zhangguangyuan5377.characters.*;
// TODO: Auto-generated Javadoc
/**
* The Class Test.
*/
public class Test {
/** The frame. */
private JFrame frame;
/** The mpsitua. */
private int id=1,situa=0,mpsitua=0;
/** The hero. */
private Characters hero;
/** The heroauto. */
private Characters heroauto;
/** The heros. */
private Characters heros[]=new Characters[5];
/** The w. */
private WeaponBehavior w[]=new WeaponBehavior[4];
/** The m. */
private MagicBehavior m[]=new MagicBehavior[3];
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test window = new Test();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Instantiates a new test.
*/
public Test() {
initialize();
}
/**
* Initialize.
*/
private void initialize() {
heros[0]=new King("King");
heros[1]=new Queen("Queen");
heros[2]=new Knight("Knight");
heros[3]=new Troll("Troll");
heros[4]=new Boss("Boss");
hero=heros[0];
w[0]=new KnifeBehavior();
w[1]=new BowAndArrowBehavior();
w[2]=new AxeBehavior();
w[3]=new SwordBehavior();
m[0]=new HealBehavior();
m[1]=new InvisibleBehavior();
m[2]=new NoneMagicBehavior();
Random r=new Random();
heroauto=heros[r.nextInt(5)];
heroauto.setWeaponBehavior(w[r.nextInt(4)]);
heroauto.setMagicBehavior(m[r.nextInt(3)]);
frame = new JFrame();
frame.setResizable(false);
frame.setBackground(Color.CYAN);
frame.setForeground(new Color(128, 0, 0));
frame.setTitle("革命");
frame.setBounds(100, 100, 675, 437);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);//启动后在屏幕正中央,成功
JMenuBar menuBar = new JMenuBar();
menuBar.setForeground(Color.WHITE);
menuBar.setBackground(Color.WHITE);
frame.setJMenuBar(menuBar);
JMenu mnNewMenu = new JMenu("文件");
menuBar.add(mnNewMenu);
JMenuItem mntmNewMenuItem = new JMenuItem("开始游戏");
mntmNewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
mnNewMenu.add(mntmNewMenuItem);
JMenuItem mntmNewMenuItem_1 = new JMenuItem("暂停游戏");
mntmNewMenuItem_1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK));
mnNewMenu.add(mntmNewMenuItem_1);
JMenuItem mntmNewMenuItem_2 = new JMenuItem("回到主界面");
mntmNewMenuItem_2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK));
mnNewMenu.add(mntmNewMenuItem_2);
JMenuItem mntmNewMenuItem_5 = new JMenuItem("退出游戏");
mntmNewMenuItem_5.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, 0));
mnNewMenu.add(mntmNewMenuItem_5);
JMenu mnNewMenu_1 = new JMenu("帮助");
menuBar.add(mnNewMenu_1);
JMenuItem mntmNewMenuItem_3 = new JMenuItem("查看帮助");
mnNewMenu_1.add(mntmNewMenuItem_3);
JMenuItem mntmNewMenuItem_4 = new JMenuItem("发送反馈");
mnNewMenu_1.add(mntmNewMenuItem_4);
frame.getContentPane().setLayout(new CardLayout(0, 0));
//test
final CardLayout cards = new CardLayout();
final JPanel container = new JPanel(cards);
JPanel start=new JPanel();
frame.getContentPane().add(start, "name_747044582085601");
start.setLayout(null);
JPanel play = new JPanel();
frame.getContentPane().add(play, "name_747044582085600");
play.setLayout(null);
JButton btnNewButton = new JButton("start");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
});
btnNewButton.setFont(new Font("楷体", Font.BOLD, 14));
btnNewButton.setToolTipText("start game now");//未点击时显示提示信息
btnNewButton.addActionListener(new ActionListener() {//匿名类
public void actionPerformed(ActionEvent e) {
//frame.getContentPane().add(play,"name_747044582085600");
//test
//btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
container.add(start, "panel");
}
});
btnNewButton.setBounds(516, 129, 93, 23);
start.add(btnNewButton);
JButton btnNewButton_1 = new JButton("剧情模式");
btnNewButton_1.setFont(new Font("楷体", Font.BOLD, 13));
btnNewButton_1.setToolTipText("开始惊险刺激的故事闯关吧!");
btnNewButton_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
//if (e.getSource() == btnNewButton_1)
JOptionPane.showMessageDialog(null,"剧情版敬请期待,感谢您的支持");//弹出对话框显示信息
}
@Override
public void mouseEntered(MouseEvent e) {
btnNewButton_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
});
btnNewButton_1.setBounds(516, 178, 93, 23);
start.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("在线模式");
btnNewButton_2.setToolTipText("和好友一起线上过关斩将,享受乐趣!");
btnNewButton_2.addActionListener(e->{JOptionPane.showMessageDialog(null, "本模块尚未开发,感谢您的支持");});
//测试使用lambda表达式简化
/*(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,"本模块还没被开发,感谢您的支持");
}
});*/
btnNewButton_2.setBounds(516, 225, 93, 23);
start.add(btnNewButton_2);
JButton btnNewButton_3 = new JButton("关于革命");
btnNewButton_3.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
//cards.last(parent);
//frame.setContentPane(play);
}
});
btnNewButton_3.setToolTipText("Press to know more about revolution");
btnNewButton_3.setBounds(516, 275, 93, 23);
start.add(btnNewButton_3);
/*btnNewButton_3.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
if(e.getSource()==btnNewButton_3)
btnNewButton_3.setBackground(Color.red);
}});*/
JLabel lblNewLabel = new JLabel("New label");
lblNewLabel.setIcon(new ImageIcon(Test.class.getResource("/zhangguangyuan5377/image/2.jpg")));
lblNewLabel.setBounds(0, 0, 669, 385);
start.add(lblNewLabel);
JLabel herochoice = new JLabel("您选择的英雄:"+hero.getName());
herochoice.setFont(new Font("楷体", Font.BOLD, 15));
herochoice.setBounds(10, 17, 168, 29);
play.add(herochoice);
JLabel weaponchoice = new JLabel("勇士配良兵,请挑选武器");
weaponchoice.setBounds(426, 24, 177, 15);
play.add(weaponchoice);
JLabel ability = new JLabel("能力");
ability.setBounds(73, 65, 54, 15);
play.add(ability);
JLabel mp = new JLabel("法力值");
mp.setBounds(10, 123, 54, 15);
play.add(mp);
JLabel at = new JLabel("攻击力");
at.setBounds(10, 147, 54, 15);
play.add(at);
JLabel de = new JLabel("防御力");
de.setBounds(10, 172, 54, 15);
play.add(de);
JLabel skill = new JLabel("技能");
skill.setBounds(73, 212, 54, 15);
play.add(skill);
JButton startbutton = new JButton("开始游戏");
startbutto
没有合适的资源?快使用搜索试试~ 我知道了~
Java实现简易rpg小游戏
共202个文件
html:70个
class:43个
png:29个
需积分: 13 13 下载量 173 浏览量
2020-07-08
15:52:52
上传
评论 1
收藏 3.14MB ZIP 举报
温馨提示
rpg小游戏一个游戏中有多种角色(Character),例如:国王(King)、皇后(Queen)、骑士(Knight)、老怪(Troll)。 角色之间可能要发生战斗(fight),每场战斗都是一个角色与另一角色之间 的 一 对 一 战 斗 。 每 个 角 色 都 有 自 己 的 生 命 值 (hitPoint) 、 魔法值(magicPoint)、攻击力值(damage)和防御力值(defense)。每种角色都有一种武器进行攻击(fight);在程序运行中,可以动态修改角色的武器(setWeaponBehavior)。每种角色都有一种魔法对自己或者其他角色施(performMagic);可以动态改变拥有的魔法(setMagicBehavior)
资源推荐
资源详情
资源评论
收起资源包目录
Java实现简易rpg小游戏 (202个子文件)
Test.class 17KB
Characters.class 4KB
Test$18.class 2KB
Test$17.class 2KB
Test$15.class 2KB
Test$16.class 2KB
Test$14.class 2KB
Test$13.class 2KB
Test$9.class 2KB
Test$10.class 2KB
Test$7.class 2KB
Test$8.class 2KB
Test$19.class 2KB
Test$20.class 2KB
Test$21.class 2KB
Test$12.class 2KB
Test$11.class 2KB
Test$6.class 1KB
BowAndArrowBehavior.class 1KB
SwordBehavior.class 1KB
KnifeBehavior.class 1KB
Test$24.class 1KB
AxeBehavior.class 1KB
Test$4.class 1KB
King.class 988B
Test$3.class 960B
Test$2.class 929B
Troll.class 883B
Knight.class 868B
Queen.class 859B
Test$1.class 847B
InvisibleBehavior.class 813B
HealBehavior.class 798B
Boss.class 766B
Test$23.class 736B
Test$22.class 682B
Test$5.class 680B
NoneMagicBehavior.class 613B
WeaponBehavior.class 286B
MagicBehavior.class 244B
package-info.class 135B
package-info.class 133B
package-info.class 129B
.classpath 396B
stylesheet.css 21KB
jquery-ui.css 20KB
jquery-ui.min.css 17KB
jquery-ui.structure.css 2KB
jquery-ui.structure.min.css 2KB
element-list 85B
Characters.html 30KB
BowAndArrowBehavior.html 16KB
SwordBehavior.html 16KB
KnifeBehavior.html 16KB
AxeBehavior.html 16KB
index-6.html 15KB
Characters.html 15KB
Knight.html 14KB
Queen.html 14KB
Troll.html 14KB
Boss.html 14KB
King.html 14KB
NoneMagicBehavior.html 12KB
InvisibleBehavior.html 12KB
HealBehavior.html 12KB
Test.html 12KB
testcode.html 11KB
WeaponBehavior.html 10KB
allclasses-index.html 9KB
index-17.html 9KB
overview-tree.html 9KB
index-15.html 9KB
help-doc.html 9KB
MagicBehavior.html 8KB
WeaponBehavior.html 8KB
MagicBehavior.html 8KB
index-9.html 8KB
index-16.html 7KB
index-4.html 7KB
package-tree.html 7KB
package-summary.html 7KB
index-2.html 7KB
package-use.html 6KB
index-3.html 6KB
package-use.html 6KB
index-10.html 6KB
index-13.html 6KB
index-11.html 6KB
index-8.html 6KB
index-7.html 6KB
index-1.html 6KB
package-summary.html 5KB
index-19.html 5KB
index-12.html 5KB
index-5.html 5KB
index-18.html 5KB
index-14.html 5KB
package-tree.html 5KB
package-summary.html 5KB
package-tree.html 4KB
共 202 条
- 1
- 2
- 3
资源评论
zero_only
- 粉丝: 12
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功