📄 mapcontrol.java
字号:
package rich;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MapControl{
Container layeredPane; // main container
Container contentPane;
JFrame f;
int mapWidth,mapHeight;
private JPanel Panel; // container
private JLabel groundLabel[]; // for add Ground Object in label
Ground map; // initial map Object
Ground[] mapList;
int x=0,y=0,j=0;
public MapControl(){
initialMap();
f = new JFrame("The Rich"); // construt Frame
contentPane = f.getContentPane();
contentPane.setLayout(new GridLayout(1,2));
layeredPane = f.getLayeredPane();
Panel = new JPanel();
Panel.setLayout(null);
groundLabel = new JLabel[mapList.length];
for(int i=1;i<mapList.length;i++){ //draw the map in contentPane
groundLabel[i] = new JLabel("",mapList[i].getIcon(),JLabel.CENTER);
groundLabel[i].setBounds(mapList[i].getX(),mapList[i].getY(),mapList[i].getIconWidth(),mapList[i].getIconHeight()); //get X,Y from Ground
Panel.add(groundLabel[i]);
}
Panel.setBounds(0,0,mapWidth,mapHeight);
contentPane.add(Panel);
f.pack();
f.setSize(mapWidth,mapHeight);
f.show();
f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){ System.exit(0); }});
}
private void initialMap() { // initial map ,set x ,y
mapList = new Ground[41];
for(int i=1;i<=40;i++){
map = new Ground(2000,200,i,0+x,0+y);
map.setGroundType("house");
mapList[i] = map;
if(i<=10){
x+=map.getIconWidth();
}
if(i>10&&i<=20){
y+=map.getIconHeight();
mapHeight+=map.getIconHeight();
}
if(i>20&&i<=30){
x-=map.getIconWidth();
mapWidth+=map.getIconWidth();
}
if(i>30&&i<=40){
y-=map.getIconHeight();
}
}
mapList[1] = new Ground(2000,200,1,0+x,0+y);
mapList[1].setGroundType("bank");
mapList[1].setIcon(new ImageIcon(getClass().getResource("picture/bank.gif")));
mapList[1].setOwner(new Character("Govement","none",100,9999999,9999999,0,0,null,null));
mapList[21] = new Ground(2000,200,1,mapList[21].getX(),mapList[21].getY());
mapList[21].setGroundType("bank");
mapList[21].setIcon(new ImageIcon(getClass().getResource("picture/bank.gif")));
mapList[21].setOwner(new Character("Govement","none",100,9999999,9999999,0,0,null,null));
mapList[11] = new Ground(2000,200,1,mapList[11].getX(),mapList[11].getY());
mapList[11].setGroundType("special");
mapList[11].setIcon(new ImageIcon(getClass().getResource("picture/special.gif")));
mapList[11].setOwner(new Character("God","none",100,9999999,9999999,0,0,null,null));
mapList[31] = new Ground(2000,200,1,mapList[31].getX(),mapList[31].getY());
mapList[31].setGroundType("special");
mapList[31].setIcon(new ImageIcon(getClass().getResource("picture/special.gif")));
mapList[31].setOwner(new Character("God","none",100,9999999,9999999,0,0,null,null));
mapWidth+=map.getIconWidth()+50;
mapHeight+=map.getIconHeight()+50;
}
public void resetMap(int address){
groundLabel[address].setIcon(mapList[address].getIcon());
}
public JLabel createCharacter(Character player){ // put the player in to LayeredPane
JLabel characterLabel = new JLabel();
characterLabel.setIcon(player.getIcon());
layeredPane.add(characterLabel);
return characterLabel;
}
public void move(Character player,JLabel Label,int address,String type){ //reset the player x,y ,let player move
if(type=="jump"){
player.setX(mapList[address].getX());
player.setY(mapList[address].getY());
Label.setBounds(player.getX(),player.getY(),player.getIcon().getIconWidth(),player.getIcon().getIconHeight());
}
EventHandle event = new EventHandle(this);
event.Event(player,mapList[address]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -