Java实现萝卜勇者游戏的示例代码

目录
  • 前言
  • 主要设计
  • 功能截图
  • 代码实现
    • 启动类
    • 键盘监听
    • 核心算法
  • 总结

前言

《萝卜勇者》是由国内玩家自制的一款独立游戏,玩家扮演萝卜勇士闯关,打败各种邪恶的敌人,获得最后的胜利。

《萝卜勇者》游戏是用java语言实现,采用了swing技术进行了界面化处理,设计思路用了面向对象思想。

主要需求

参考《萝卜勇者》的剧情,实现JAVA版本的单机游戏。

主要设计

1、 用Swing库做可视化界面

2、键盘监听,用WSAD可以控制光标移动,J是确定,K是取消,游戏中,WSAD移动,J攻击,K格挡。

3、 用线程实现画面刷新。

4、用流实现音乐播放。

5、支持多种语言,支持用户翻译语言文件。

6、在帮助界面下,按键盘1234567890可以启用秘籍(传奇模式:一刀砍999血)

7、使用的是JDK8

8、文件编码GBK

功能截图

游戏开始

游戏帮助

游戏设置

选择不同的关卡

游戏效果

怪物攻击效果

代码实现

启动类

@SuppressWarnings("serial")
public class TestWindowBuilder extends JFrame {

	TextLibrary textLib;
	settingLoader settingLib;
	private JPanel contentPane;
	boolean isCheating;
	saveSelect saveSelectMenu;
	int[] startMenuPointer=new int[1];
	JLabel lblNewLabel1;
	JLabel lblNewLabel2;
	JLabel lblNewLabel3;
	JLabel lblNewLabel3_2;
	JLabel lblNewLabel3_1;
	JLabel lblNewLabel4;
	JLabel lblNewLabel5;
	JLabel lblNewLabel6;

	CMusicLink CMLHead=new CMusicLink(1);
	CMusicLink CMLLast=new CMusicLink(2);

	boolean sawExplain=true;

	CMusic menuBGMusic;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestWindowBuilder frame = new TestWindowBuilder();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
public TestWindowBuilder() {
		this.setTitle("CARROT MAN II");
		this.setIconImage(new ImageIcon("resource/down4.png").getImage());
		int screenWidth=Calculator.setInside(ScreenSize.getWidth(), 800, 99999);
		int screenHeight=Calculator.setInside(ScreenSize.getHeight(), 450, 99999);

		System.out.println("启动控制台222...");

		CMLHead.next=CMLLast;
		CMLLast.prev=CMLHead;

		settingLib=new settingLoader();
		settingLib.loadSetting();//加载设置
		settingLib.saveSetting();
		textLib=new TextLibrary();
		textLib.saveText();//创建默认的语言文件
		textLib.loadText(settingLib.settings[0]);
		startNewMenuBGMusic(1);
		/*游戏阶段:
		 * 0开始菜单
		 * */
		int gamePhase=0;
		isCheating=false;
		/*开始菜单指针
		 * 0开始
		 * 1帮助
		 * 2退出
		 * */
		startMenuPointer[0]=0;
		int allSMPCount=5;//总指针数
		TestWindowBuilder testMenu=this;

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds((screenWidth-800)/2, (screenHeight-450)/2, 800, 450);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JPanel mainMenu = new JPanel();
		mainMenu.setBounds(0, 0, 784, 412);
		contentPane.add(mainMenu);
		mainMenu.setLayout(null);

		lblNewLabel1 = new JLabel();//菜单标题
		lblNewLabel1.setBounds(192, 10, 400, 150);
		lblNewLabel1.setIcon(new ImageIcon("resource/MenuTitle.png"));
		mainMenu.add(lblNewLabel1);

		lblNewLabel2 = new JLabel();//开始
		lblNewLabel2.setBounds(10, 193, 764, 43);
		lblNewLabel2.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel2.setFont(new Font("Adobe 黑体 Std R", Font.PLAIN, 21));
		lblNewLabel2.setForeground(new Color(200,200,200));
		mainMenu.add(lblNewLabel2);

		lblNewLabel3 = new JLabel();//帮助
		lblNewLabel3.setBounds(10, 223, 764, 43);
		lblNewLabel3.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel3.setFont(new Font("Adobe 黑体 Std R", Font.PLAIN, 21));
		lblNewLabel3.setForeground(new Color(200,200,200));
		mainMenu.add(lblNewLabel3);

		lblNewLabel3_2 = new JLabel();//设置
		lblNewLabel3_2.setBounds(10, 253, 764, 43);
		lblNewLabel3_2.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel3_2.setFont(new Font("Adobe 黑体 Std R", Font.PLAIN, 21));
		lblNewLabel3_2.setForeground(new Color(200,200,200));
		mainMenu.add(lblNewLabel3_2);

		lblNewLabel3_1 = new JLabel();//语言
		lblNewLabel3_1.setBounds(10, 283, 764, 43);
		lblNewLabel3_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel3_1.setFont(new Font("Adobe 黑体 Std R", Font.PLAIN, 21));
		lblNewLabel3_1.setForeground(new Color(200,200,200));
		mainMenu.add(lblNewLabel3_1);

		lblNewLabel4 = new JLabel();//退出
		lblNewLabel4.setBounds(10, 313, 764, 43);
		lblNewLabel4.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel4.setFont(new Font("Adobe 黑体 Std R", Font.PLAIN, 21));
		lblNewLabel4.setForeground(new Color(200,200,200));
		mainMenu.add(lblNewLabel4);

		lblNewLabel5 = new JLabel(textLib.textData[5]);//底部提示
		lblNewLabel5.setBounds(10, 371, 764, 31);
		lblNewLabel5.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel5.setFont(new Font("Adobe 黑体 Std R", Font.PLAIN, 15));
		lblNewLabel5.setForeground(new Color(200,200,200));
		mainMenu.add(lblNewLabel5);

		lblNewLabel6 = new JLabel();//半透明黑背景
		lblNewLabel6.setBounds(267, 193, 250, 209);
		lblNewLabel6.setIcon(new ImageIcon("resource/mainMenuButtonBackGround.png"));
		mainMenu.add(lblNewLabel6);

		JLabel MenuBackGroundLabel = new JLabel();//白色背景
		MenuBackGroundLabel.setBounds(0, 0, 800, 450);
		MenuBackGroundLabel.setIcon(new ImageIcon("resource/mainMenuBackGround.png"));
		mainMenu.add(MenuBackGroundLabel);

		reflash();

		//键盘监听器
		this.addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				char cmd=e.getKeyChar();
				if(gamePhase==0)//开始菜单
				{
					if(sawExplain==false)
					{
						sawExplain=true;
						StartView sv=new StartView(testMenu);
						sv.setVisible(true);
						testMenu.setVisible(false);
					}
					else
					{
						if(TestWindowBuilder.charEqualsIgnoreCase(cmd, 'w'))
						{
							startMenuPointer[0]=(startMenuPointer[0]-1+allSMPCount)%allSMPCount;
							startNewSound("pointerMove.wav",false,1);
						}
						if(TestWindowBuilder.charEqualsIgnoreCase(cmd, 's'))
						{
							startMenuPointer[0]=(startMenuPointer[0]+1)%allSMPCount;
							startNewSound("pointerMove.wav",false,1);
						}
						reflash();
						if(TestWindowBuilder.charEqualsIgnoreCase(cmd, 'j'))
						{
							if(startMenuPointer[0]==0)
							{
								saveSelectMenu=new saveSelect(testMenu);
								saveSelectMenu.setVisible(true);
								testMenu.setVisible(false);
								startNewSound("menuChange.wav",false,1);
							}
							if(startMenuPointer[0]==1)
							{
								HelpMenu helpMenu=new HelpMenu(testMenu);
								helpMenu.setVisible(true);
								testMenu.setVisible(false);
								startNewSound("menuChange.wav",false,1);
							}
							if(startMenuPointer[0]==2)
							{
								settingMenu sMenu=new settingMenu(testMenu);
								sMenu.setVisible(true);
								testMenu.setVisible(false);
								startNewSound("menuChange.wav",false,1);
							}
							if(startMenuPointer[0]==3)
							{
								settingLanguage settingMenu=new settingLanguage(testMenu);
								settingMenu.setVisible(true);
								testMenu.setVisible(false);
								startNewSound("menuChange.wav",false,1);
							}
							if(startMenuPointer[0]==4)
							{
								startNewSound("menuChange.wav",false,1);
								System.exit(0);
							}
						}
					}
				}
			}
		});
	}

	public void reflash()
	{
		lblNewLabel1.setText(textLib.textData[1]);
		lblNewLabel2.setText(textLib.textData[6]);
		lblNewLabel3.setText(textLib.textData[3]);
		lblNewLabel3_2.setText(textLib.textData[60]);
		lblNewLabel3_1.setText(textLib.textData[49]);
		lblNewLabel4.setText(textLib.textData[4]);
		lblNewLabel5.setText(textLib.textData[5]);
		if(startMenuPointer[0]==0)
		{
			lblNewLabel2.setText(textLib.textData[6]+" <--");
		}
		if(startMenuPointer[0]==1)
		{
			lblNewLabel3.setText(textLib.textData[3]+" <--");
		}
		if(startMenuPointer[0]==2)
		{
			lblNewLabel3_2.setText(textLib.textData[60]+" <--");
		}
		if(startMenuPointer[0]==3)
		{
			lblNewLabel3_1.setText(textLib.textData[49]+" <--");
		}
		if(startMenuPointer[0]==4)
		{
			lblNewLabel4.setText(textLib.textData[4]+" <--");
		}
	}

	public void startNewMenuBGMusic(int prepare)
	{
		if(settingLib.settings[1].equals("1"))
		{
			if(menuBGMusic!=null)
				menuBGMusic.endMusic();
			menuBGMusic=new CMusic("menuMusic.wav",true,30000);
			menuBGMusic.start();
		}
		else if(prepare==1)
		{
			if(menuBGMusic!=null)
				menuBGMusic.endMusic();
			menuBGMusic=new CMusic("menuMusic.wav",true,30000);
			menuBGMusic.start();
			menuBGMusic.pauseMusic();
		}
	}

	public void startNewSound(String soundName,boolean isReplay,int replayDelay)//开启新音效
	{
		if(settingLib.settings[2].equals("1"))
			new CMusicLink(CMLLast,soundName,isReplay,replayDelay);
	}

	/**
	 * 判断字母a和字母b是否相同(无视大小写)
	 * @param a 字母a
	 * @param b 字母b
	 * @return true:字母a和字母b相同 | false:字母a和字母b不同,或ab中存在非字母
	 */
	public static boolean charEqualsIgnoreCase(char a,char b)
	{
		if(((int)a)>=65&&((int)a)<=90)//大写
		{
			if(a==b)
				return true;
			if(a+32==b)
				return true;
		}
		if(((int)a)>=97&&((int)a)<=122)//小写
		{
			if(a==b)
				return true;
			if(a-32==b)
				return true;
		}
		return false;
	}
}

键盘监听

public class KeyLininter extends KeyAdapter
{
	GameMenu gameMenu;

	public KeyLininter(GameMenu gameMenu)
	{
		this.gameMenu=gameMenu;
	}

	public void keyPressed(KeyEvent e) {
		char cmd = e.getKeyChar();
		if(cmd=='w'||cmd=='W')
		{
			gameMenu.pressingW=1;
		}
		if(cmd=='s'||cmd=='S')
		{
			gameMenu.pressingS=1;
		}
		if(cmd=='a'||cmd=='A')
		{
			gameMenu.pressingA=1;
		}
		if(cmd=='d'||cmd=='D')
		{
			gameMenu.pressingD=1;
		}
		if(cmd=='j'||cmd=='J')
		{
			gameMenu.pressingJ=1;
		}
		if(cmd=='k'||cmd=='K')
		{
			gameMenu.pressingK=1;
		}
	}
	public void keyReleased(KeyEvent e)
	{
		char cmd = e.getKeyChar();
		if(cmd=='w'||cmd=='W')
		{
			gameMenu.pressingW=0;
		}
		if(cmd=='s'||cmd=='S')
		{
			gameMenu.pressingS=0;
		}
		if(cmd=='a'||cmd=='A')
		{
			gameMenu.pressingA=0;
		}
		if(cmd=='d'||cmd=='D')
		{
			gameMenu.pressingD=0;
		}
		if(cmd=='j'||cmd=='J')
		{
			gameMenu.pressingJ=0;
		}
		if(cmd=='k'||cmd=='K')
		{
			gameMenu.pressingK=0;
		}
	}
}

核心算法

@SuppressWarnings("serial")
public class GameMenu extends JFrame {

	GameMenu thisMenu;
	private JPanel contentPane;
	TestWindowBuilder fatherMenu;
	boolean isCheating;
	CMusic battleBGM,questCompleteBGM;

	int pressingW;
	int pressingS;
	int pressingA;
	int pressingD;
	int pressingJ;
	int pressingK;

	int playingSave;
	int playingProfessionID;

	int g_int1;

	Role playingRole;
	double playerX;//0-734
	double playerY;//0-312
	int rotationSpeed=15;//旋转速度
	int movementSpeed=3;//移动速度
	int NormalSpeed=3;
	int attackSpeed=3;//攻击速度
	int activeCounter;
	int attackCounter;
	int defenceCounter=0;
	int perfectDefenceTime=0;//完美格挡剩余时间(在敌人发动攻击前0.1秒启动的格挡能让格挡所需体力消耗减少到原来的十分之一)
	int defenceCooldown=0;//格挡冷却 这样阻止了玩家疯狂地启动/停止格挡
	int playerWidth=50;
	int playerHeight=50;
	int gamePhaseTimeCounter=0;
	int gamePhaseTimeCounter2=0;
	int endPhase=6*4;//游戏通关的阶段
	/*第一关 0
	 * 第二关 6
	 * */
	int gamePhase=0;//游戏开始时的阶段(正常玩家从第一关开始打,阶段应当从0开始)

	String humanIconContorler;

	JPanel viewMap;

	//玩家有两个Label 一个在boss上方 一个在boss下方
	int usingPlayerLabel=0;
	JLabel[] playerLabel=new JLabel[2];

	JLabel lblNewLabel_6;
	JLabel lblNewLabel_7;
	JLabel[] GiantBackGround=new JLabel[400];
	JLabel bossLabel;
	JLabel lblNewLabel_2;
	JLabel lblNewLabel_3;
	JLabel lblNewLabel_2B;
	JLabel lblNewLabel_3B;
	JLabel MobHead;
	JLabel MobName;
	JLabel MobHPBar;
	JLabel MobHPText;
	JLabel TitleLabelT;
	JLabel SubTitleLabelT;
	JLabel TitleLabel;
	JLabel SubTitleLabel;
	JPanel Titles;
	JLabel placeNameLabel;
	JLabel groundArrayLabel;
	JLabel placeChangeBlack;//换场地时的黑幕
	JLabel placeChangeBlack_1;//换场地时的黑幕(用于属性条)

	int maxProCount=5000;
	JLabel[] proLabel=new JLabel[maxProCount];
	boolean[] proIsUsed=new boolean[maxProCount];
	proLink proHead=new proLink();
	int existProCount;

	int maxParCount=5000;
	JLabel[] parLabel=new JLabel[maxParCount];
	boolean[] parIsUsed=new boolean[maxParCount];
	parLink parHead=new parLink();
	int existParCount;

	int existPro=0;
	int proTeamPointer=0;//队列指针 0-499

	int existPar=0;
	int parTeamPointer=0;

	JPanel panel;

	Mob boss;

	int allPhaseCount=1;
	int gameTime=0;

	Map map;

	/**
	 * Create the frame.
	 */
	public GameMenu(TestWindowBuilder fatherMenu,boolean isCheating,int professionID,int partID,int playingSave)
	{
		this.setTitle("CARROT MAN II");
		this.setIconImage(new ImageIcon("resource/down4.png").getImage());
		for(int i=0;i<proIsUsed.length;++i)
			proIsUsed[i]=false;
		for(int i=0;i<parIsUsed.length;++i)
			parIsUsed[i]=false;
		playingProfessionID=professionID;
		this.playingSave=playingSave;
		gamePhase=(partID-1)*6;
		this.fatherMenu=fatherMenu;
		this.isCheating=isCheating;
		//this.isCheating=true;//测试用
		g_int1=0;
		playerX=50;
		playerY=200;
		thisMenu=this;
		activeCounter=0;
		attackCounter=0;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(fatherMenu.getBounds());
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		//转场黑幕 第100层
		placeChangeBlack=new JLabel("");
		placeChangeBlack.setIcon(new ImageIcon("resource/black.png"));
		placeChangeBlack.setVisible(true);
		placeChangeBlack_1=new JLabel("");
		placeChangeBlack_1.setIcon(new ImageIcon("resource/black.png"));
		placeChangeBlack_1.setVisible(true);
		placeChangeBlack.setBounds(0, 0, 784, 362);
		placeChangeBlack_1.setBounds(0, 0, 784, 362);
		//contentPane.add(placeChangeBlack);

		JPanel panel_1 = new JPanel();
		panel_1.setBounds(0, 0, 784, 50);
		contentPane.add(panel_1);
		panel_1.setLayout(null);

		panel_1.add(placeChangeBlack_1);

		JLabel lblNewLabel = new JLabel("");//头像
		lblNewLabel.setBounds(0, 0, 50, 50);
		lblNewLabel.setIcon(new ImageIcon("resource/HPBarHead.png"));
		panel_1.add(lblNewLabel);

		lblNewLabel_2B = new JLabel("");//血量字
		lblNewLabel_2B.setForeground(Color.WHITE);
		lblNewLabel_2B.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_2B.setBounds(50, 0, 200, 25);
		panel_1.add(lblNewLabel_2B);

		lblNewLabel_3B = new JLabel("");//体力字
		lblNewLabel_3B.setForeground(Color.WHITE);
		lblNewLabel_3B.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_3B.setBounds(50, 25, 200, 25);
		panel_1.add(lblNewLabel_3B);

		lblNewLabel_2 = new JLabel("");//血条
		lblNewLabel_2.setBounds(50, 0, 200, 25);
		lblNewLabel_2.setIcon(new ImageIcon("resource/RedBar.png"));
		panel_1.add(lblNewLabel_2);

		lblNewLabel_3 = new JLabel("");//体力条
		lblNewLabel_3.setBounds(50, 25, 200, 25);
		lblNewLabel_3.setIcon(new ImageIcon("resource/GreenBar.png"));
		panel_1.add(lblNewLabel_3);

		JLabel lblNewLabel_1 = new JLabel("");//血条体力条背景
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_1.setBounds(50, 0, 200, 50);
		lblNewLabel_1.setIcon(new ImageIcon("resource/HPBarBG.png"));
		panel_1.add(lblNewLabel_1);

		JLabel lblNewLabel_4 = new JLabel("J");
		lblNewLabel_4.setForeground(Color.GRAY);
		lblNewLabel_4.setFont(new Font("黑体", Font.BOLD, 30));
		lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_4.setBounds(250, 0, 50, 50);
		panel_1.add(lblNewLabel_4);

		JLabel lblNewLabel_5 = new JLabel("");
		lblNewLabel_5.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel_5.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_5.setBounds(250, 0, 50, 50);
		lblNewLabel_5.setIcon(new ImageIcon("resource/skillJ.png"));
		panel_1.add(lblNewLabel_5);

		JLabel skillKLabel = new JLabel("K");
		skillKLabel.setForeground(Color.GRAY);
		skillKLabel.setFont(new Font("黑体", Font.BOLD, 30));
		skillKLabel.setHorizontalAlignment(SwingConstants.CENTER);
		skillKLabel.setBounds(300, 0, 50, 50);
		panel_1.add(skillKLabel);

		JLabel skillKLabel2 = new JLabel("");
		skillKLabel2.setFont(new Font("宋体", Font.PLAIN, 20));
		skillKLabel2.setHorizontalAlignment(SwingConstants.CENTER);
		skillKLabel2.setBounds(300, 0, 50, 50);
		skillKLabel2.setIcon(new ImageIcon("resource/skillK.png"));
		panel_1.add(skillKLabel2);

		placeNameLabel = new JLabel("");
		placeNameLabel.setFont(new Font("宋体", Font.PLAIN, 30));
		placeNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
		placeNameLabel.setBounds(350, 0, 200, 50);
		panel_1.add(placeNameLabel);

		JLabel placeNameLabel2 = new JLabel("");
		placeNameLabel2.setHorizontalAlignment(SwingConstants.CENTER);
		placeNameLabel2.setBounds(350, 0, 200, 50);
		placeNameLabel2.setIcon(new ImageIcon("resource/placeNameBackGround.png"));
		panel_1.add(placeNameLabel2);

		MobHead = new JLabel("");
		MobHead.setHorizontalAlignment(SwingConstants.CENTER);
		MobHead.setBounds(550, 0, 50, 50);
		MobHead.setIcon(new ImageIcon("resource/MobHead_0.png"));
		panel_1.add(MobHead);

		MobName = new JLabel("");
		MobName.setHorizontalAlignment(SwingConstants.CENTER);
		MobName.setBounds(600, 0, 184, 25);
		panel_1.add(MobName);

		MobHPText = new JLabel("");
		MobHPText.setForeground(Color.WHITE);
		MobHPText.setHorizontalAlignment(SwingConstants.CENTER);
		MobHPText.setBounds(600, 25, 184, 25);
		panel_1.add(MobHPText);

		MobHPBar = new JLabel("");
		MobHPBar.setHorizontalAlignment(SwingConstants.CENTER);
		MobHPBar.setBounds(600, 25, 184, 25);
		MobHPBar.setIcon(new ImageIcon("resource/RedBar.png"));
		panel_1.add(MobHPBar);

		JLabel MobNameBG = new JLabel("");
		MobNameBG.setHorizontalAlignment(SwingConstants.CENTER);
		MobNameBG.setBounds(600, 0, 184, 50);
		MobNameBG.setIcon(new ImageIcon("resource/MobNameBG.png"));
		panel_1.add(MobNameBG);	

		panel = new JPanel();
		panel.setBounds(0, 50, 784, 362);
		contentPane.add(panel);
		viewMap=panel;
		panel.setLayout(null);

		panel.add(placeChangeBlack);

		lblNewLabel_7 = new JLabel("");//玩家tryingFace指示器(暂时停用)
		lblNewLabel_7.setBounds((int)playerX, (int)playerY, 5, 5);
		lblNewLabel_7.setIcon(new ImageIcon("resource/moveDeraction2.png"));
		lblNewLabel_7.setVisible(false);
		panel.add(lblNewLabel_7);

		//第99层
		//标题
		TitleLabelT = new JLabel("");
		TitleLabelT.setFont(new Font("黑体", Font.PLAIN, 45));
		TitleLabelT.setHorizontalAlignment(SwingConstants.CENTER);
		TitleLabelT.setBounds(100, 50, 584, 50);
		TitleLabelT.setVisible(true);
		panel.add(TitleLabelT);
		//副标题
		SubTitleLabelT = new JLabel("");
		SubTitleLabelT.setFont(new Font("黑体", Font.PLAIN, 25));
		SubTitleLabelT.setHorizontalAlignment(SwingConstants.CENTER);
		SubTitleLabelT.setBounds(100, 100, 584, 50);
		SubTitleLabelT.setVisible(true);
		panel.add(SubTitleLabelT);

		//预先创建粒子效果的Label,第6层
		for(int i=0;i<maxParCount;++i)
		{
			parLabel[i]=new JLabel("");
			panel.add(parLabel[i]);
		}

		//boss上方的玩家,第5层
		playerLabel[1]=new JLabel("");
		playerLabel[1].setHorizontalAlignment(SwingConstants.CENTER);
		playerLabel[1].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerHeight, playerWidth);
		playerLabel[1].setIcon(new ImageIcon("resource/HumanRight_0.png"));
		playerLabel[1].setVisible(false);
		panel.add(playerLabel[1]);

		//bossLabel,第4.5层
		bossLabel = new JLabel("");
		panel.add(bossLabel);

		//boss下方的玩家,第4层
		playerLabel[0]=new JLabel("");
		playerLabel[0].setHorizontalAlignment(SwingConstants.CENTER);
		playerLabel[0].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerHeight, playerWidth);
		playerLabel[0].setIcon(new ImageIcon("resource/HumanRight_0.png"));
		playerLabel[0].setVisible(true);
		panel.add(playerLabel[0]);

		//玩家面向方向指示器,第3层
		lblNewLabel_6 = new JLabel("");
		lblNewLabel_6.setBounds((int)playerX, (int)playerY, 5, 5);
		lblNewLabel_6.setIcon(new ImageIcon("resource/moveDeraction.png"));
		panel.add(lblNewLabel_6);

		//预先创建发射物的Label,第2层
		for(int i=0;i<maxProCount;++i)
		{
			proLabel[i]=new JLabel("");
			panel.add(proLabel[i]);
		}

		//创建地面箭头,第1.5层
		groundArrayLabel=new JLabel("");
		groundArrayLabel.setBounds(709,156, 50, 50);
		groundArrayLabel.setIcon(new ImageIcon("resource/groundArray.png"));
		groundArrayLabel.setVisible(false);
		panel.add(groundArrayLabel);

		//创建地面Label,第1层
		for(int i=0;i<400;++i)
		{
			GiantBackGround[i]=new JLabel("");
			GiantBackGround[i].setVisible(true);
			panel.add(GiantBackGround[i]);
		}	

		playingRole=new Role(professionID,thisMenu);

		KeyLininter kl=new KeyLininter(thisMenu);
        this.addKeyListener(kl);

		map=new Map(thisMenu);
		map.start();
	}

	//发射物相关
	public int addProjectile(Projectile pro)
	{
		existProCount=proHead.getLength();
		if(existProCount<maxProCount)
		{
			proHead.insert(new proLink(pro));
			int tempFinder=0;
			for(int i=0;i<maxProCount;++i)
			{
				if(proIsUsed[i]==false)
				{
					proIsUsed[i]=true;
					tempFinder=i;
					break;
				}
			}
			return tempFinder;
		}
		return -1;
	}
	public void removeProjectile(int id)
	{
		proLabel[id].setVisible(false);
		proIsUsed[id]=false;
	}
	public void allProjectilesFly()
	{
		proLink tempNode=proHead;
		while(tempNode.next!=null)
		{
			tempNode=tempNode.next;
			tempNode.data.doFly();
		}
	}
	//发射物相关结束

	//粒子效果相关
	public int addParticle(particle par)
	{
		existParCount=parHead.getLength();
		if(existParCount<maxParCount)
		{
			parHead.insert(new parLink(par));
			int tempFinder=0;
			for(int i=0;i<maxParCount;++i)
			{
				if(parIsUsed[i]==false)
				{
					parIsUsed[i]=true;
					tempFinder=i;
					break;
				}
			}
			return tempFinder;
		}
		return -1;
	}
	public void removeParticle(int id)
	{
		parLabel[id].setVisible(false);
		parIsUsed[id]=false;
	}
	public void allParticlesFly()
	{
		parLink tempNode=parHead;
		while(tempNode.next!=null)
		{
			tempNode=tempNode.next;
			tempNode.data.doFly();
		}
	}
	public void checkPlayerLocation()//检测玩家位置 如果超出地图 则拉回地图
	{
		if(playerX<playerWidth/2)
			playerX=playerWidth/2;
		if(playerX>784-playerWidth/2)
			playerX=784-playerWidth/2;
		if(playerY<playerHeight/2)
			playerY=playerHeight/2;
		if(playerY>362-playerHeight/2)
			playerY=362-playerHeight/2;
	}

	@SuppressWarnings("unused")
	public void saveData(int part)
	{
		if(Integer.parseInt(fatherMenu.saveSelectMenu.savedData[playingSave].split(" ")[1])<part)
		{
			String[] temp= {
					fatherMenu.saveSelectMenu.savedData[playingSave].split(" ")[0],
					fatherMenu.saveSelectMenu.savedData[playingSave].split(" ")[1]
			};
			fatherMenu.saveSelectMenu.savedData[playingSave]=""+playingProfessionID+" "+part;
			fatherMenu.saveSelectMenu.saveSaves();
		}
	}

	@SuppressWarnings({ "deprecation" })
	public void modTick()//每秒执行50次
	{
		if(attackCounter==0&&defenceCounter==0)
			playingRole.regenerate();
		if(playingRole.HP>0)
		{
			//刷新体力条
			lblNewLabel_3.setBounds(50, 25, (int) (200*playingRole.energy/playingRole.MaxEnergy), 25);
			lblNewLabel_3B.setText(""+(int)playingRole.energy+"/"+(int)playingRole.MaxEnergy);
			//刷新血条
			lblNewLabel_2.setBounds(50, 0, (int) (200*playingRole.HP/playingRole.MaxHP), 25);
			lblNewLabel_2B.setText(""+(int)playingRole.HP+"/"+(int)playingRole.MaxHP);
		}
		else if(gamePhase!=-1)
		{
			boss.target=null;
			gamePhaseTimeCounter=0;
			gamePhase=-1;
			movementSpeed=0;
			TitleLabelT.setText("YOU DIED");
			TitleLabelT.setVisible(true);
			playerLabel[usingPlayerLabel].setVisible(false);
			lblNewLabel_6.setVisible(false);
			lblNewLabel_3.setBounds(50, 25, (int) (200*playingRole.energy/playingRole.MaxEnergy), 25);
			lblNewLabel_3B.setText(""+(int)playingRole.energy+"/"+(int)playingRole.MaxEnergy);
			lblNewLabel_2.setBounds(50, 0, (int) (200*playingRole.HP/playingRole.MaxHP), 25);
			lblNewLabel_2B.setText(""+(int)playingRole.HP+"/"+(int)playingRole.MaxHP);
		}

		++gameTime;
		allProjectilesFly();
		allParticlesFly();
		if(gamePhase==0)
		{
			if(gamePhaseTimeCounter<50)
				gamePhaseTimeCounter=50;
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter==51)
			{
				System.out.println("启动控制台...");
				movementSpeed=0;
				placeChangeBlack.setBounds(0, 0, 784, 362);
				placeChangeBlack_1.setBounds(0, 0, 784, 362);
				placeChangeBlack.setVisible(true);
				placeChangeBlack_1.setVisible(true);
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				groundArrayLabel.setVisible(false);
				for(int i=0;i<128;++i)//初始化第一关地面
				{
					String backGroundContorler="resource/ground";
					GiantBackGround[i].setBounds(50*(i%16),50*(int)(i/16), 50, 50);
					if(Math.random()<0.9)
						backGroundContorler=backGroundContorler+"1.png";
					else
						backGroundContorler=backGroundContorler+"2.png";
					GiantBackGround[i].setIcon(new ImageIcon(backGroundContorler));
				}
				playerX=50;
				playerY=200;
				placeNameLabel.setText(fatherMenu.textLib.textData[13]);
				TitleLabelT.setText(fatherMenu.textLib.textData[13]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[37]);
				SubTitleLabelT.setVisible(true);
			}
			if(gamePhaseTimeCounter>=100&&gamePhaseTimeCounter<=150)
			{
				placeChangeBlack.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
				placeChangeBlack_1.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
			}
			if(gamePhaseTimeCounter==151)
			{
				startNewBattleBGM(1);
				placeChangeBlack.setVisible(false);
				placeChangeBlack_1.setVisible(false);
				gamePhaseTimeCounter=0;
				++gamePhase;
			}
		}
		if(gamePhase%6==1)
		{
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter>=200)
			{
				++gamePhase;
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				movementSpeed=NormalSpeed;
			}
		}
		if(gamePhase==2)
		{
			gamePhaseTimeCounter=0;
			boss=new Mob(1,bossLabel,thisMenu);
			boss.reflash();
			bossLabel.setVisible(true);
			++gamePhase;
		}
		if(gamePhase==3)
		{
			if(boss.HP>0)
				boss.reflash();
			else
			{
				bossLabel.setVisible(false);
				MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
				MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
				++gamePhase;
				gamePhaseTimeCounter=0;
				TitleLabelT.setText(fatherMenu.textLib.textData[38]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[39]);
				SubTitleLabelT.setVisible(true);
				saveData(2);
				startQuestCompleteBGM();
				endBattleBGM();
			}
		}
		if(gamePhase%6==4)
		{
			playingRole.percentReHP(0.005);
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter>200)
			{
				gamePhaseTimeCounter=0;
				++gamePhase;
				TitleLabelT.setText(fatherMenu.textLib.textData[40]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[41]);
				SubTitleLabelT.setVisible(true);
				gamePhaseTimeCounter2=0;
			}
		}
		if(gamePhase%6==5)
		{
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter2==0)
			{
				if(gamePhaseTimeCounter>50)
				{
					groundArrayLabel.setVisible(true);
					if(playerX>709&&playerX<759&&playerY>156&&playerY<206)//进入箭头
					{
						gamePhaseTimeCounter=0;
						gamePhaseTimeCounter2=1;
						movementSpeed=0;
						placeChangeBlack.setBounds(-784,0,784,362);
						placeChangeBlack.setVisible(true);
						placeChangeBlack_1.setBounds(-784,0,784,362);
						placeChangeBlack_1.setVisible(true);
					}
				}
			}
			if(gamePhaseTimeCounter2==1)
			{
				if(gamePhaseTimeCounter>=0&&gamePhaseTimeCounter<=50)
				{
					placeChangeBlack.setBounds((int)(gamePhaseTimeCounter*0.02*784-784), 0, 784, 362);
					placeChangeBlack_1.setBounds((int)(gamePhaseTimeCounter*0.02*784-784), 0, 784, 362);
				}
				if(gamePhaseTimeCounter==51)
				{
					++gamePhase;
					gamePhaseTimeCounter=0;
				}
			}
		}
		if(gamePhase==6)
		{
			movementSpeed=0;
			if(gamePhaseTimeCounter<50)
				gamePhaseTimeCounter=50;
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter==51)
			{
				placeChangeBlack.setBounds(0, 0, 784, 362);
				placeChangeBlack.setVisible(true);
				placeChangeBlack_1.setBounds(0, 0, 784, 362);
				placeChangeBlack_1.setVisible(true);
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				groundArrayLabel.setVisible(false);
				for(int i=0;i<325;++i)
				{
					GiantBackGround[i].setBounds(32*(i%25),32*(int)(i/25), 32, 32);
					GiantBackGround[i].setIcon(new ImageIcon("resource/ground6.png"));
				}
				playerX=50;
				playerY=200;
				placeNameLabel.setText(fatherMenu.textLib.textData[14]);
				TitleLabelT.setText(fatherMenu.textLib.textData[14]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[42]);
				SubTitleLabelT.setVisible(true);
			}
			if(gamePhaseTimeCounter>=100&&gamePhaseTimeCounter<=150)
			{
				placeChangeBlack.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
				placeChangeBlack_1.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
			}
			if(gamePhaseTimeCounter==151)
			{
				startNewBattleBGM(2);
				placeChangeBlack.setVisible(false);
				placeChangeBlack_1.setVisible(false);
				gamePhaseTimeCounter=0;
				++gamePhase;
			}
		}
		if(gamePhase==8)
		{
			gamePhaseTimeCounter=0;
			boss=new Mob(2,bossLabel,thisMenu);
			bossLabel.setBounds(375, 175, 100, 100);
			boss.reflash();
			bossLabel.setVisible(true);
			++gamePhase;
		}
		if(gamePhase==9)
		{
			if(boss.HP>0)
				boss.reflash();
			else
			{
				bossLabel.setVisible(false);
				MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
				MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
				++gamePhase;
				gamePhaseTimeCounter=0;
				TitleLabelT.setText(fatherMenu.textLib.textData[43]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[39]);
				SubTitleLabelT.setVisible(true);
				saveData(3);
				startQuestCompleteBGM();
				endBattleBGM();
			}
		}
		if(gamePhase==12)
		{
			movementSpeed=0;
			if(gamePhaseTimeCounter<50)
				gamePhaseTimeCounter=50;
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter==51)
			{
				placeChangeBlack.setBounds(0, 0, 784, 362);
				placeChangeBlack.setVisible(true);
				placeChangeBlack_1.setBounds(0, 0, 784, 362);
				placeChangeBlack_1.setVisible(true);
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				groundArrayLabel.setVisible(false);
				for(int i=0;i<325;++i)
				{
					GiantBackGround[i].setBounds(32*(i%25),32*(int)(i/25), 32, 32);
					GiantBackGround[i].setIcon(new ImageIcon("resource/ground7.png"));
				}
				playerX=50;
				playerY=200;
				placeNameLabel.setText(fatherMenu.textLib.textData[15]);
				TitleLabelT.setText(fatherMenu.textLib.textData[15]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[44]);
				SubTitleLabelT.setVisible(true);
			}
			if(gamePhaseTimeCounter>=100&&gamePhaseTimeCounter<=150)
			{
				placeChangeBlack.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
				placeChangeBlack_1.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
			}
			if(gamePhaseTimeCounter==151)
			{
				startNewBattleBGM(3);
				placeChangeBlack.setVisible(false);
				placeChangeBlack_1.setVisible(false);
				gamePhaseTimeCounter=0;
				++gamePhase;
			}
		}
		if(gamePhase==14)
		{
			gamePhaseTimeCounter=0;
			boss=new Mob(3,bossLabel,thisMenu);
			bossLabel.setBounds(375, 175, 100, 100);
			boss.reflash();
			bossLabel.setVisible(true);
			++gamePhase;
		}
		if(gamePhase==15)
		{
			if(boss.HP>0)
				boss.reflash();
			else
			{
				bossLabel.setVisible(false);
				MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
				MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
				++gamePhase;
				gamePhaseTimeCounter=0;
				TitleLabelT.setText(fatherMenu.textLib.textData[45]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[39]);
				SubTitleLabelT.setVisible(true);
				saveData(4);
				startQuestCompleteBGM();
				endBattleBGM();
			}
		}
		if(gamePhase==18)
		{
			movementSpeed=0;
			if(gamePhaseTimeCounter<50)
				gamePhaseTimeCounter=50;
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter==51)
			{
				placeChangeBlack.setBounds(0, 0, 784, 362);
				placeChangeBlack.setVisible(true);
				placeChangeBlack_1.setBounds(0, 0, 784, 362);
				placeChangeBlack_1.setVisible(true);
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				groundArrayLabel.setVisible(false);
				//需要修改开始
				for(int i=0;i<325;++i)
				{
					GiantBackGround[i].setBounds(32*(i%25),32*(int)(i/25), 32, 32);
					GiantBackGround[i].setIcon(new ImageIcon("resource/ground8.png"));
				}
				//需要修改结束
				playerX=50;
				playerY=200;
				//需要修改开始
				placeNameLabel.setText(fatherMenu.textLib.textData[70]);
				TitleLabelT.setText(fatherMenu.textLib.textData[70]);
				TitleLabelT.setForeground(Color.LIGHT_GRAY);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[71]);
				SubTitleLabelT.setForeground(Color.LIGHT_GRAY);
				//需要修改结束
				SubTitleLabelT.setVisible(true);
			}
			if(gamePhaseTimeCounter>=100&&gamePhaseTimeCounter<=150)
			{
				placeChangeBlack.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
				placeChangeBlack_1.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
			}
			if(gamePhaseTimeCounter==151)
			{
				startNewBattleBGM(4);//需要修改
				placeChangeBlack.setVisible(false);
				placeChangeBlack_1.setVisible(false);
				gamePhaseTimeCounter=0;
				++gamePhase;
			}
		}
		if(gamePhase==20)
		{
			gamePhaseTimeCounter=0;
			boss=new Mob(4,bossLabel,thisMenu);//需要修改
			bossLabel.setBounds(375, 175, 100, 100);//需要修改
			boss.reflash();
			bossLabel.setVisible(true);
			++gamePhase;
		}
		if(gamePhase==21)
		{
			if(boss.HP>0)
				boss.reflash();
			else
			{
				bossLabel.setVisible(false);
				MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
				MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
				++gamePhase;
				gamePhaseTimeCounter=0;
				//需要修改开始
				TitleLabelT.setText(fatherMenu.textLib.textData[72]);
				TitleLabelT.setForeground(Color.LIGHT_GRAY);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[39]);
				TitleLabelT.setForeground(Color.LIGHT_GRAY);
				SubTitleLabelT.setVisible(true);
				//saveData(4);
				//需要修改完成
				startQuestCompleteBGM();
				endBattleBGM();
			}
		}
		if(gamePhase==endPhase)
		{
			endBattleBGM();
			winMenu WM=new winMenu(thisMenu);
			WM.setVisible(true);
			thisMenu.setVisible(false);
			map.stop();
		}
		if(gamePhase==-1)
		{
			if(boss.HP>0)
				boss.reflash();
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter>250)
			{
				endBattleBGM();
				loseMenu LM=new loseMenu(thisMenu);
				LM.setVisible(true);
				thisMenu.setVisible(false);
				map.stop();
			}
		}

		//刷新bossBar
		if(boss!=null&&gamePhase%6==3)
		{
			MobHead.setIcon(new ImageIcon("resource/MobHead_"+boss.MobId+".png"));
			MobName.setText(""+boss.Name);
			MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
			MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
		}

		//玩家试图面向方向
		if(attackCounter==0&&defenceCounter==0)
		{
			if(pressingD==1&&pressingW==0&&pressingS==0)
			{
				playingRole.tryingFace=0;
			}
			else if(pressingD==1&&pressingW==1)
			{
				playingRole.tryingFace=45;
			}
			else if(pressingW==1&&pressingA==0&&pressingD==0)
			{
				playingRole.tryingFace=90;
			}
			else if(pressingW==1&&pressingA==1)
			{
				playingRole.tryingFace=135;
			}
			else if(pressingA==1&&pressingW==0&&pressingS==0)
			{
				playingRole.tryingFace=180;
			}
			else if(pressingA==1&&pressingS==1)
			{
				playingRole.tryingFace=225;
			}
			else if(pressingS==1&&pressingA==0&&pressingD==0)
			{
				playingRole.tryingFace=270;
			}
			else if(pressingS==1&&pressingD==1)
			{
				playingRole.tryingFace=315;
			}
		}

		playingRole.setFace();
		humanIconContorler="resource/human_"+playingRole.face;

		if(attackCounter==0&&defenceCounter==0&&(pressingW==1||pressingS==1||pressingA==1||pressingD==1))//进行转向
		{
			double d_angle=(playingRole.facingAngle-playingRole.tryingFace+360)%360;//0-180为顺时针
			if(d_angle<=rotationSpeed||d_angle>=360-rotationSpeed)//旋转功能
			{
				playingRole.facingAngle=playingRole.tryingFace;
			}
			else
			{
				if(d_angle>0&&d_angle<=180)
				{
					playingRole.facingAngle-=rotationSpeed;
				}
				else
				{
					playingRole.facingAngle+=rotationSpeed;
				}
			}
		}

		if(attackCounter==0&&defenceCounter==0&&(pressingW==1||pressingS==1||pressingA==1||pressingD==1))//进行移动
		{
			++activeCounter;
			playerX+=(int)(movementSpeed*Math.cos(playingRole.facingAngle*Math.PI/180));
			playerY-=(int)(movementSpeed*Math.sin(playingRole.facingAngle*Math.PI/180));
			checkPlayerLocation();
			if(activeCounter>=10)//10Tick一次 切换移动图片
			{
				activeCounter=0;
				playingRole.lastMoveActive=(playingRole.lastMoveActive+1)%4;
			}
			if(playingRole.lastMoveActive==2)
				humanIconContorler=humanIconContorler+'_'+0;
			else if(playingRole.lastMoveActive==3)
				humanIconContorler=humanIconContorler+'_'+2;
			else
				humanIconContorler=humanIconContorler+'_'+playingRole.lastMoveActive;
		}

		if(pressingJ==1&&attackCounter==0&&defenceCounter==0&&playingRole.HP>0)//发动攻击
		{
			attackCounter=1;
		}

		if(attackCounter>0&&attackCounter<=8*attackSpeed)//正在攻击
		{
			++attackCounter;
			if(attackCounter>0&&attackCounter<=attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+3;
			}
			else if(attackCounter<=2*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+4;
			}
			else if(attackCounter<=3*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+5;
			}
			else if(attackCounter<=4*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+6;
			}
			else if(attackCounter<=5*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+7;
			}
			else if(attackCounter<=6*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+8;
			}
			else if(attackCounter<=7*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+9;
			}
		}

		if(attackCounter==3*attackSpeed)//完成攻击
		{
			playingRole.costEnergy(10);
			fatherMenu.startNewSound("sweep"+Calculator.randomInt(1,3)+".wav",false,1);
			playingRole.doAttack();
		}
		if(attackCounter>8*attackSpeed)//结束硬直
		{
			attackCounter=0;
		}

		if(defenceCooldown>0)
		{
			--defenceCooldown;
		}
		if(perfectDefenceTime>0)
		{
			--perfectDefenceTime;
		}
		if(pressingK==1&&attackCounter==0&&defenceCounter==0&&defenceCooldown==0)//发动防御
		{
			perfectDefenceTime=5;
			defenceCounter=1;
			playingRole.defenceStance=true;
			playingRole.isBlocked=false;
		}
		if(defenceCounter==1)
		{
			if(pressingK==0)//解除格挡
			{
				defenceCounter=0;
				playingRole.defenceStance=false;
				if(playingRole.isBlocked==true)
					defenceCooldown=0;
				else
					defenceCooldown=30;
			}
			else
			{
				humanIconContorler=humanIconContorler+'_'+10;
			}
		}

		humanIconContorler=humanIconContorler+".png";
		if(boss!=null&&playingRole.HP>0)
		{
			if(playerY>=boss.bossY&&usingPlayerLabel==0)//玩家应当盖住boss,但是却没盖住
			{
				usingPlayerLabel=1;
				playerLabel[0].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
				playerLabel[1].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
				playerLabel[0].setVisible(false);
				playerLabel[1].setVisible(true);
			}
			if(playerY<boss.bossY&&usingPlayerLabel==1)//boss应当盖住玩家,但是却没盖住
			{
				usingPlayerLabel=0;
				playerLabel[0].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
				playerLabel[1].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
				playerLabel[0].setVisible(true);
				playerLabel[1].setVisible(false);
			}
		}
		playerLabel[usingPlayerLabel].setIcon(new ImageIcon(humanIconContorler));
		playerLabel[usingPlayerLabel].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
		lblNewLabel_6.setBounds((int)playerX+(int)(25*Math.cos(playingRole.facingAngle*Math.PI/180))-2, (int)playerY-(int)(25*Math.sin(playingRole.facingAngle*Math.PI/180))-2, 4,4);
		lblNewLabel_7.setBounds((int)playerX+(int)(25*Math.cos(playingRole.tryingFace*Math.PI/180))-2, (int)playerY-(int)(25*Math.sin(playingRole.tryingFace*Math.PI/180))-2, 4,4);
	}

	public void startNewBattleBGM(int bossID)
	{
		if(fatherMenu.settingLib.settings[1].equals("1"))
		{
			if(battleBGM!=null)
				battleBGM.endMusic();
			battleBGM=new CMusic("boss"+bossID+".wav",true,1);
			battleBGM.start();
		}
	}

	public void endBattleBGM()
	{
		if(battleBGM!=null)
			battleBGM.endMusic();
	}

	public void startQuestCompleteBGM()
	{
		if(questCompleteBGM!=null)
			questCompleteBGM.endMusic();
		questCompleteBGM=new CMusic("QuestComplete.wav",false,1);
		questCompleteBGM.start();
	}

}

总结

通过此次的《萝卜勇者》游戏实现,让我对swing的相关知识有了进一步的了解,对java这门语言也有了比以前更深刻的认识。

java的一些基本语法,比如数据类型、运算符、程序流程控制和数组等,理解更加透彻。java最核心的核心就是面向对象思想,对于这一个概念,终于悟到了一些。

以上就是Java实现萝卜勇者游戏的示例代码的详细内容,更多关于Java萝卜勇者的资料请关注我们其它相关文章!

(0)

相关推荐

  • Java实现经典俄罗斯方块游戏

    目录 前言 主要设计 功能截图 代码实现 总结 前言 俄罗斯方块是一个最初由阿列克谢帕吉特诺夫在苏联设计和编程的益智类视频游戏. <俄罗斯方块>的基本规则是移动.旋转和摆放游戏自动输出的各种方块,使之排列成完整的一行或多行并且消除得分. 用java语言实现,采用了swing技术进行了界面化处理,设计思路用了面向对象思想. 主要需求 由小方块组成的不同形状的板块陆续从屏幕上方落下来,玩家通过调整板块的位置和方向,使它们在屏幕底部拼出完整的一条或几条.这些完整的横条会随即消失,给新落下来的板块腾出

  • Java+swing实现经典贪吃蛇游戏

    目录 前言 主要设计 功能截图 代码实现 总结 前言 贪吃蛇(也叫做贪食蛇)游戏是一款休闲益智类游戏,有PC和手机等多平台版本.既简单又耐玩.该游戏通过控制蛇头方向吃东西,从而使得蛇变得越来越长. 本程序是通过java的swing来实现<贪吃蛇大作战>这款游戏. 主要需求 1.通过上下左右控制蛇的方向,寻找吃的东西,每吃一口就能得到一定的积分,蛇的身体会变长 2.蛇头碰到自己的身体,则算失败 主要设计 1.设置swing的窗体大小 2.随机初始化蛇的位置和食物的位置,且食物不能落在蛇的身体上.

  • JAVA实现经典扫雷游戏的示例代码

    目录 前言 主要设计 功能截图 代码实现 总结 前言 windows自带的游戏<扫雷>是陪伴了无数人的经典游戏,本程序参考<扫雷>的规则进行了简化,用java语言实现,采用了swing技术进行了界面化处理,设计思路用了面向对象思想. 主要需求 1.要有难度等级,初级,中级,高级 2.由玩家逐个翻开方块,以找出所有地雷为最终游戏目标.如果玩家翻开的方块有地雷,则游戏结束 3.游戏主区域由很多个方格组成.使用鼠标左键随机点击一个方格,方格即被打开并显示出方格中的数字:方格中数字则表示其

  • JAVA实现经典游戏坦克大战的示例代码

    目录 前言 主要设计 功能截图 代码实现 总结 前言 小时候大家都玩过坦克大战吧,熟悉的旋律和丰富的关卡陪伴了我们一整个寒暑假,还记得传说中的经典坦克大战 吗?那些怀旧的记忆,伴随着我们一起走过来的经典坦克大战,刚开始那战战兢兢,屡屡被敌人坦克击毁的情景历历在目.现在好了,再也不用担心敌人坦克了,可 以横冲直撞,横扫敌人坦克了.快哉!!! <坦克大战>游戏以坦克战斗为主题,用java语言实现,采用了swing技术进行了界面化处理,设计思路用了面向对象思想. 主要需求 可以生成不同的地图,消灭地

  • Java实现经典大富翁游戏的示例详解

    目录 前言 主要设计 功能截图 代码实现 总结 前言 大富翁,又名地产大亨.是一种多人策略图版游戏.参与者分得游戏金钱,凭运气(掷骰子)及交易策略,买地.建楼以赚取租金.英文原名monopoly意为“垄断”,因为最后只得一个胜利者,其余均破产收场. <大富翁>游戏是用java语言实现,采用了swing技术进行了界面化处理,设计思路用了面向对象思想. 主要需求 可多人参与的大富翁游戏,玩家有初始资金,通过掷骰子,玩家移动指定骰子点数步骤,根据对应格子上的交易策略,来决定是赚钱还是亏钱,其他玩家破

  • Java实现经典游戏复杂迷宫

    目录 前言 主要设计 功能截图 代码实现 总结 前言 人类建造迷宫已有5000年的历史.在世界的不同文化发展时期,这些奇特的建筑物始终吸引人们沿着弯弯曲曲.困难重重的小路吃力地行走,寻找真相.迷宫类小游戏应运而生.在游戏中,迷宫被表现为冒险舞台里,藏有各式各样奇妙与谜题或宝藏的危险区域.型态有洞窟.人工建筑物.怪物巢穴.密林或山路等.迷宫内有恶徒或凶猛的生物(真实存在或想像物体都有)徘徊,其中可能会有陷阱.不明设施.遗迹等. <复杂迷宫>游戏是用java语言实现,采用了swing技术进行了界面

  • Java实现萝卜勇者游戏的示例代码

    目录 前言 主要设计 功能截图 代码实现 启动类 键盘监听 核心算法 总结 前言 <萝卜勇者>是由国内玩家自制的一款独立游戏,玩家扮演萝卜勇士闯关,打败各种邪恶的敌人,获得最后的胜利. <萝卜勇者>游戏是用java语言实现,采用了swing技术进行了界面化处理,设计思路用了面向对象思想. 主要需求 参考<萝卜勇者>的剧情,实现JAVA版本的单机游戏. 主要设计 1. 用Swing库做可视化界面 2.键盘监听,用WSAD可以控制光标移动,J是确定,K是取消,游戏中,WSA

  • Java+Swing实现五子棋游戏的示例代码

    目录 一.系统介绍 1.开发环境 2.技术选型 3.系统功能 二.系统展示 三.部分代码 AI.java Chess.java Gobang.java GobangListener.java 一.系统介绍 1.开发环境 开发工具:Eclipse2021 JDK版本:jdk1.8 Mysql版本:8.0.13 2.技术选型 Java+Swing 3.系统功能 实现五子棋游戏,开始游戏,悔棋,认输,退出功能. 二.系统展示 1.首页 2.黑棋走 3.白棋走 三.部分代码 AI.java packag

  • Java实现角色扮演游戏的示例代码

    目录 前言 主要设计 功能截图 代码实现 游戏启动类 抽象类:游戏角色类 魔法行为接口 总结 前言 <模式策略的角色扮演游戏>游戏是自制的角色扮演游戏.选择两个角色,然后进行PK,可用来学习JAVA的接口,继承和多态. 主要设计 1.事先设计好英雄,血量和相关技能. 2.为了让玩家能与程序互动,使用下面这个命令可达效果 Scanner sc = new Scanner(System.in); 3.运行StartMain里的main方法 4.设计四个角色 1.Queen 2.King 3.Kni

  • Java实现单机版五子棋游戏的示例代码

    目录 前言 主要需求 主要设计 功能截图 代码实现 总结 前言 五子棋是世界智力运动会竞技项目之一,是一种两人对弈的纯策略型棋类游戏,是世界智力运动会竞技项目之一,通常双方分别使用黑白两色的棋子,下在棋盘直线与横线的交叉点上,先形成5子连线者获胜. 棋具与围棋通用,起源于中国上古时代的传统黑白棋种之一.主要流行于华人和汉字文化圈的国家以及欧美一些地区,是世界上最古老的棋. 容易上手,老少皆宜,而且趣味横生,引人入胜:不仅能增强思维能力,提高智力,而且富含哲理,有助于修身养性. 用java语言实现

  • Java实现贪吃蛇游戏的示例代码

    目录 项目演示 项目实战 1. 游戏的主启动类 2. 游戏的面板 3. 数据中心 4. 绘制静态面板 5. 绘制静态小蛇 6. 绘制动态小蛇 7. 设置游戏状态 8. 让蛇动起来 9. 绘制食物布局 10. 游戏失败判定 11. 积分获取系统 12. 游戏优化 项目演示 项目演示地址 项目实战 1. 游戏的主启动类 作为贪吃蛇游戏的主启动类,构建了顶级窗口,可以容纳各种面板, package Snake; import javax.swing.*; /** * 游戏的主启动类 */ public

  • Java实现AI五子棋游戏的示例代码

    目录 前言 实现过程 抽象 实现AI接口 评估函数 前言 本文只是介绍五子棋AI的实现,最终的成品只是一个 AI 接口,并不包括 GUI,且不依赖 GUI. 五子棋 AI 的实现并不难,只需要解决一个问题就行: 怎么确定AI的最佳落子位置? 一般情况下,五子棋棋盘是由15条横线和15条纵线组合而成的,15x15 的棋盘共有 225 个交叉点,也就是说共有 225 个落子点. 假如说,AI 是黑棋,先行落子,所以 AI 总共有 225 个落子点可以选择,我们可以对每个落子点进行评估打分,哪个分高下

  • Java实现经典角色扮演侦探游戏游戏的示例代码

    目录 前言 游戏背景 主要需求 主要设计 功能截图 代码实现 游戏主界面 主卧 初始化 大厅 总结 前言 游戏背景 百变山庄坐落于太平洋的一座小岛上,山庄主人亦是小岛的主人.这个神秘主人细致周到,邀请函里不仅附着往返港口的机票,港口的邮船也是通往小岛的专线. 初登小岛,恢宏大气的山庄直入眼帘,通过门廊,金碧辉煌的大厅震人心魄. 受邀的侦探们陆续到齐,[侍者]彬彬有礼地站在一旁,他安排你们围坐在一个奇特十边形的桌子旁稍加等待.[侦探指尖]回忆着自己临行前调查的各位名侦探的资料,除了那个神秘的[电话

  • Java实现经典拳皇误闯冒险岛游戏的示例代码

    目录 前言 主要设计 功能截图 代码实现 游戏主界面 英雄 总结 前言 <拳皇误闯冒险岛>是拳皇和冒险岛素材的基于JavaSwing的动作类游戏,独创改编. 主要需求 拳皇迷迷糊糊醒来,发现自己在一间废弃的工厂里,地上爬满怪兽..这么可爱的怪兽,一拳下去,应该会哭很久吧~拳皇心里吐槽了下,向怪兽的怀抱冲了上去~~ 主要设计 1.游戏面板生成显示 2.背景选用冒险岛素材图 3.设计英雄,包含生命值,法术值,英雄的动作变化处理,英雄的技能特效 4.设计怪兽,包含怪物血量,攻击力,位置,步长等 5.

  • Java实现经典捕鱼达人游戏的示例代码

    目录 前言 主要设计 功能截图 代码实现 游戏窗体 鱼 鱼池类继承自Jpanel 总结 前言 <捕鱼达人>是一款以深海狩猎为题材的休闲竞技游戏.这是一场海底世界的远征,享受捕获大鱼的乐趣,但不是所有的鱼都是友善的,它们会用自己的方式保护自己,保卫属于自己的海底世界.当然,这里也是冒险与机遇共存的地方,诸多埋藏于海底的宝藏等待着被探寻. 游戏是用java语言实现,采用了swing技术进行了界面化处理,设计思路用了面向对象思想. 主要需求 在鱼池中有很多鱼,鱼各自游动. 有一张渔网,随鼠标移动,点

随机推荐