package cn.nju.game.ui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import cn.nju.game.equip.Bag;
import cn.nju.game.equip.Equipment;
import cn.nju.game.equip.EquipmentShop;
import cn.nju.game.model.vo.CommanderBasicVO;
import cn.nju.game.model.vo.EquipmentVO;
import cn.nju.game.model.vo.SkillVO;
import cn.nju.game.role.Commander;
import cn.nju.game.role.JuniorStrategy;
import cn.nju.game.role.LevelUpStrategy;
import cn.nju.game.role.PrimaryLevelupStrategy;
import cn.nju.game.role.SeniorStrategy;
import cn.nju.game.service.OnlineCommander;
import cn.nju.game.service.RoleService;
import cn.nju.game.service.StageService;
import cn.nju.game.skill.DeleteEquipItemListener;
import cn.nju.game.skill.SkillLeveledPool;
import cn.nju.game.ui.handler.SkillUpgradeListener;
import cn.nju.game.ui.handler.StartFightMouseHandler;
import cn.nju.game.ui.handler.StrengthWeaponLeadingListener;
import cn.nju.game.ui.handler.StrengthWeaponTailListener;
import cn.nju.game.ui.handler.WindowClosingHandler;
import cn.nju.game.ui.util.BoundsUtil;
import cn.nju.game.ui.util.CommanderModelUtilFactory;
import cn.nju.game.ui.util.EquipmentModelUtilFactory;
import cn.nju.game.ui.util.ModelToTableModelUtil;
import cn.nju.game.ui.util.SharedModelUtilFactory;
import cn.nju.game.ui.util.SkillModelUtilFactory;
public class GameClientWindow extends JFrame implements Observer {
private static final String EXP_TOOLTIP = "经验值/升级所需经验";
private static final int W = 800;
private static final int H = 600;
private RoleService roleService;
private StageService stageService;
private List<String> equipmentsInBag = new ArrayList<String>(Bag.CAPACITY);
/**
*
*/
private static final long serialVersionUID = 8646291614420411539L;
private JPanel contentPane;
private JTable tableEquipments;
private JTable tableSkills;
private JTable tableOnlineCommanders;
private JPanel[] rowPanels;
private JButton buttonAddToBag;
private JLabel lblCommanderName;
private JLabel lblExprience;
private JLabel lblLevel;
private LevelUpStrategy strategy;
public void showInCenter(JFrame parent) {
setBounds(BoundsUtil.getCenterOwnerBounds(parent, W, H));
setVisible(true);
}
/**
* Create the frame.
*/
public GameClientWindow(RoleService service, StageService stageService) {
this.stageService = stageService;
setResizable(false);
roleService = service;
CommanderBasicVO commanderBasic = roleService.getCommanderBasic();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, W, H);
setMaximumSize(new Dimension(W, H));
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel lblCommanderInfo = new JPanel();
lblCommanderInfo.setBorder(new TitledBorder(null, "召唤师信息", TitledBorder.CENTER, TitledBorder.TOP, null, null));
lblCommanderInfo.setBounds(6, 6, 230, 250);
contentPane.add(lblCommanderInfo);
JLabel lblIcon = new JLabel();
lblIcon.setBounds(6, 18, 100, 128);
try {
ImageIcon imageIcon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/" + commanderBasic.getIcon())));
lblIcon.setIcon(imageIcon);
int magicDamage = commanderBasic.getMagicDamage();
int physicalDamage = commanderBasic.getPhysicalDamage();
magicDamage = (int) (magicDamage * (1 + Math.log10(commanderBasic.getLevel())));
physicalDamage = (int) (physicalDamage * (1 + Math.log10(commanderBasic.getLevel())));
lblIcon.setToolTipText("将对目标造成" + physicalDamage + "的物理伤害和" + magicDamage + "的魔法伤害,基础伤害将随等级自适应提高");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
lblCommanderInfo.setLayout(null);
lblCommanderInfo.add(lblIcon);
lblCommanderName = new JLabel(commanderBasic.getName());
lblCommanderName.setBounds(113, 18, 114, 16);
lblCommanderInfo.add(lblCommanderName);
JLabel lblJob = new JLabel(commanderBasic.getJob());
lblJob.setBounds(113, 36, 114, 16);
lblCommanderInfo.add(lblJob);
lblLevel = new JLabel(commanderBasic.getLevel() + "");
lblLevel.setBounds(113, 54, 114, 16);
lblCommanderInfo.add(lblLevel);
strategy = null;
if (4 > commanderBasic.getLevel()) {
strategy = new PrimaryLevelupStrategy();
} else if (10 >= commanderBasic.getLevel()) {
strategy = new JuniorStrategy();
} else {
strategy = new SeniorStrategy();
}
lblExprience = new JLabel(commanderBasic.getExpirience() + "/" + strategy.getLevelupExperienceNeeded(commanderBasic.getLevel()));
lblExprience.setBounds(113, 72, 114, 16);
lblExprience.setToolTipText(EXP_TOOLTIP);
lblCommanderInfo.add(lblExprience);
JLabel lblWeapon = new JLabel(roleService.getWeaponVo().getName());
lblWeapon.setToolTipText(roleService.getWeaponVo().getDescription());
lblWeapon.setBounds(113, 90, 114, 16);
lblCommanderInfo.add(lblWeapon);
JButton buttonStart = new JButton("确认并开始竞技");
StartFightMouseHandler startFightMouseHandler = new StartFightMouseHandler();
buttonStart.addMouseListener(startFightMouseHandler);
startFightMouseHandler.setContext(this);
startFightMouseHandler.setStageService(stageService);
buttonStart.setBounds(59, 199, 117, 29);
lblCommanderInfo.add(buttonStart);
JButton buttonStrengthLeading = new JButton("加强武器头部");
buttonStrengthLeading.setBounds(110, 110, 117, 29);
StrengthWeaponLeadingListener strengthWeaponLeadingListener = new StrengthWeaponLeadingListener();
strengthWeaponLeadingListener.setObservrLabel(lblWeapon);
strengthWeaponLeadingListener.setRoleService(roleService);
buttonStrengthLeading.addMouseListener(strengthWeaponLeadingListener);
lblCommanderInfo.add(buttonStrengthLeading);
JButton buttonStrengthTail = new JButton("加强武器尾部");
buttonStrengthTail.setBounds(110, 136, 117, 29);
StrengthWeaponTailListener strengthWeaponTailListener = new StrengthWeaponTailListener();
strengthWeaponTailListener.setObservrLabel(lblWeapon);
strengthWeaponTailListener.setRoleService(roleService);
buttonStrengthTail.addMouseListener(strengthWeaponTailListener);
lblCommanderInfo.add(buttonStrengthTail);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(248, 6, 546, 250);
contentPane.add(scrollPane);
JPanel panelEquipments = new JPanel();
scrollPane.setViewportView(panelEquipments);
scrollPane.setBorder(null);
panelEquipments.setBorder(new TitledBorder(null, "装备库", TitledBorder.CENTER, TitledBorder.TOP, null, null));
panelEquipments.setLayout(new BorderLayout(0, 0));
Iterable<Equipment> allEquipments = EquipmentShop.sharedPool().getAllEquipments();
Set<EquipmentVO> allEquipmentsVo = new HashSet<EquipmentVO>();
for (Equipment equipment : allEquipments) {
allEquipmentsVo.add(new EquipmentVO(equipment));
}
Iterator<EquipmentVO> equipIt = allEquipmentsVo.iterator();
Object[] headers = null;
Vector<O
苹果酱0567
- 粉丝: 2040
- 资源: 1102
最新资源
- 基于SSM的医院住院管理系统+vue(Java毕业设计,附源码,数据库,教程).zip
- 基于SSM的游戏攻略网站的设计与实现+vue(Java毕业设计,附源码,数据库,教程).zip
- 基于springboot+Vue的机动车号牌管理系统(Java毕业设计,附源码,部署教程).zip
- 基于SSM的在线医疗服务系统+jsp(Java毕业设计,附源码,数据库,教程).zip
- 基于springboot+Vue的火锅店管理系统(Java毕业设计,附源码,部署教程).zip
- 基于springboot+Vue的火锅店管理系统2(Java毕业设计,附源码,部署教程).zip
- 基于SSM的在线云音乐系统的设计与实现+jsp(Java毕业设计,附源码,数据库,教程).zip
- 基于springboot+Vue的高校专业实习管理系统的设计和开发2(Java毕业设计,附源码,部署教程).zip
- 基于springboot+Vue的高校专业实习管理系统的设计和开发(Java毕业设计,附源码,部署教程).zip
- 基于springboot+Vue的个人博客系统的设计与实现(Java毕业设计,附源码,部署教程).zip
- 基于springboot+Vue的华府便利店信息管理系统2(Java毕业设计,附源码,部署教程).zip
- 基于springboot+Vue的华府便利店信息管理系统(Java毕业设计,附源码,部署教程).zip
- 基于SSM的助学贷款+jsp(Java毕业设计,附源码,数据库,教程).zip
- 基于SpringBoot+Vue的火车票订票系统的设计与实现(Java毕业设计,附源码,部署教程).zip
- 基于SSM框架的购物商城系统+jsp(Java毕业设计,附源码,数据库,教程).zip
- 基于SSM框架的个人博客网站的设计与实现+vue(Java毕业设计,附源码,数据库,教程).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈