⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mazegame.java

📁 java Labyrinth game;Provides two kinds to produce map s way stochastically: The stochastic distribut
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						"深度_1(容易)"),// 西北深度
				dfsES = new JMenuItem("深度_2(默认)"),// 东南深度
				dfsEN = new JMenuItem("深度_3(较难)");// 东北深度

		public MenuBarPanel() {
			this.setVisible(true);
			this.setLayout(new GridLayout(1, 6));
			this.add(menuBar);

			menuBar.add(contrl);
			contrl.add(starGame);
			contrl.add(printWay);
			contrl.addSeparator();// 分组
			contrl.add(exitGame);
			starGame.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0));
			printWay.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, 0));
			exitGame.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,
					0));

			menuBar.add(sys);
			sys.add(setBlockColor);
			sys.add(setBackColor);
			sys.add(resetColor);
			sys.addSeparator();// 分组

			sys.add(hard1);
			sys.add(hard2);
			sys.add(hard3);
			hard1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1,
					KeyEvent.ALT_MASK));
			hard2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2,
					KeyEvent.ALT_MASK));
			hard3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
					KeyEvent.ALT_MASK));

			menuBar.add(howTocreat);
			howTocreat.add(byRandom);
			howTocreat.addSeparator();// 分组
			howTocreat.add(dfsWN);
			howTocreat.add(dfsES);
			howTocreat.add(dfsEN);
			byRandom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0,
					KeyEvent.CTRL_MASK));
			dfsWN.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1,
					KeyEvent.CTRL_MASK));
			dfsES.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2,
					KeyEvent.CTRL_MASK));
			dfsEN.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
					KeyEvent.CTRL_MASK));

			menuBar.add(help);
			help.add(aboutGame);

			exitGame.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {// 关闭
					String[] options = { "退出游戏吗?" };
					infOut.setText("将退出游戏!");
					int choice = JOptionPane.showConfirmDialog(null, options,
							"退出游戏!", JOptionPane.YES_NO_OPTION,
							JOptionPane.WARNING_MESSAGE, new ImageIcon(
									"inco\\ask.png"));
					if (choice == 0)
						System.exit(0);
					else
						infOut.setText("操作被取消");
				}
			});
			printWay.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {// 帮助
					LinkedList<XandY> temlist = new LinkedList<XandY>();
					if (Judges.isConnected(canvas.getBox(1, 1), canvas.getBox(
							canvas.getRows() - 2, canvas.getCols() - 1),
							canvas, 1)) {
						temlist = Judges.toConnected(canvas.getBox(1, 1),
								canvas.getBox(canvas.getRows() - 2, canvas
										.getCols() - 1), canvas);
						XandY xandy = new XandY();
						int x, y;
						for (int i = 0; i < temlist.size(); i++) {
							xandy = temlist.get(i);
							x = xandy.getX();
							y = xandy.getY();
							canvas.getBox(x, y).setState(Enums.colors.WAY);
						}
						nowBox.setState(Enums.colors.NOW);
						canvas.repaint();
						infOut.setText("路径已标示(采用随机布点法生成地图显示的路径不一定最短)");
					} else
						infOut.setText("查找路径失败");
				}
			});
			starGame.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {// 刷新地图
					if (methodOfCreateMap == 0)
						new NewMap(getCanvas());
					else
						new NewMap(getCanvas(), methodOfCreateMap);
					nowBox.setState(Enums.colors.NOW);
					canvas.repaint();
					infOut.setText("地图已更新");
				}
			});
			aboutGame.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {// 帮助
					if (HlepWindow.getisCreated() == 0) {// 此窗口现在没有被打开
						new HlepWindow();
						infOut.setText("弹出帮助窗口");
					}
				}
			});
			setBlockColor.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					infOut.setText("设置砖块颜色");
					Color newBlockColor = JColorChooser.showDialog(
							MazeGame.this, "设置砖块颜色", canvas.getBlockColor());
					if (newBlockColor != null) {
						canvas.setstockColor(newBlockColor);
						canvas.repaint();
						infOut.setText("砖块颜色已更新");
					} else
						infOut.setText("设置砖块颜色被取消");
				}
			});
			setBackColor.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					infOut.setText("设置背景颜色");
					Color newBlockColor = JColorChooser.showDialog(
							MazeGame.this, "设置背景颜色", canvas.getBlockColor());
					if (newBlockColor != null) {
						canvas.setbackColor(newBlockColor);
						canvas.repaint();
						infOut.setText("背景颜色已更新");
					} else
						infOut.setText("设置背景颜色被取消");
				}
			});
			resetColor.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					infOut.setText("重置所有颜色");
					canvas.setbackColor(Color.gray);
					canvas.setstockColor(Color.red);
					canvas.repaint();
				}
			});
			byRandom.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {// 随机生成地图
					if (methodOfCreateMap != 0) {
						methodOfCreateMap = 0;
						new NewMap(getCanvas());
						nowBox.setState(Enums.colors.NOW);
						canvas.repaint();
						infOut.setText("选择随机布点法生成地图,地图已更新");
					}
				}
			});
			dfsWN.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (methodOfCreateMap != 1) {
						methodOfCreateMap = 1;
						new NewMap(getCanvas(), 1);
						nowBox.setState(Enums.colors.NOW);
						canvas.repaint();
						infOut.setText("选择左上角深度优先遍历法生成地图,地图已更新");
					}
				}
			});
			dfsES.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (methodOfCreateMap != 2) {
						methodOfCreateMap = 2;
						new NewMap(getCanvas(), 2);
						nowBox.setState(Enums.colors.NOW);
						canvas.repaint();
						infOut.setText("选择右上角深度优先遍历法生成地图,地图已更新");
					}
				}
			});
			dfsEN.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (methodOfCreateMap != 3) {
						methodOfCreateMap = 3;
						new NewMap(getCanvas(), 3);
						nowBox.setState(Enums.colors.NOW);
						canvas.repaint();
						infOut.setText("选择右下角深度优先遍历法生成地图,地图已更新");
					}
				}
			});
			/*
			 * 以下调节难度功能有待优化, 现在还没有想到办法,唉,试N次都显示不正常
			 */

			hard1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {// 方格数为1
					if (areaOftheMap != 1) {
						areaOftheMap = 1;
						setrowsAnacolsOfmap(49, 55);
						for (int i = 0; i < canvas.getRows(); i++)
							for (int j = 0; j < canvas.getCols(); j++)
								canvas.getBox(i, j).setState(Enums.colors.BACK);
						canvas.setCols(getcolsOfmap());
						canvas.setRows(getrowsOfmap());
						if (methodOfCreateMap == 0)
							new NewMap(getCanvas());
						else
							new NewMap(getCanvas(), methodOfCreateMap);

						nowBox.setState(Enums.colors.NOW);
						canvas.fanning();
						canvas.repaint();
					}
				}
			});
			hard2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (areaOftheMap != 2) {
						areaOftheMap = 2;
						setrowsAnacolsOfmap(71, 79);
						for (int i = 0; i < canvas.getRows(); i++)
							for (int j = 0; j < canvas.getCols(); j++)
								canvas.getBox(i, j).setState(Enums.colors.BACK);
						canvas.setCols(getcolsOfmap());
						canvas.setRows(getrowsOfmap());
						if (methodOfCreateMap == 0)
							new NewMap(getCanvas());
						else
							new NewMap(getCanvas(), methodOfCreateMap);
						nowBox.setState(Enums.colors.NOW);
						canvas.fanning();
						canvas.repaint();
					}
				}
			});
			hard3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (areaOftheMap != 3) {
						areaOftheMap = 3;
						setrowsAnacolsOfmap(91, 103);
						for (int i = 0; i < canvas.getRows(); i++)
							for (int j = 0; j < canvas.getCols(); j++)
								canvas.getBox(i, j).setState(Enums.colors.BACK);
						canvas.setCols(getcolsOfmap());
						canvas.setRows(getrowsOfmap());
						if (methodOfCreateMap == 0)
							new NewMap(getCanvas());
						else
							new NewMap(getCanvas(), methodOfCreateMap);

						nowBox.setState(Enums.colors.NOW);
						canvas.fanning();
						canvas.repaint();
					}
				}
			});
			/*
			 * 以上调节难度功能有待优化, 现在还没有想到办法,唉,试N次都显示不正常
			 */
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -