📄 blockviewspanel.java
字号:
package mine.view;
import javax.swing.JPanel;
import java.awt.*;
import mine.*;
import mine.view.*;
import mine.model.*;
import mine.listener.*;
public class BlockViewsPanel
extends JPanel
implements TimeListener {
private GameConfigure gameconfigure = GameConfigure.getInstance();
private int xx;
private int yy;
private GameModel gamemodel;
private GameMouseListener gamemouselistener;
private GameMouseListener startGameMouseListener = new GameMouseListener() {
public void processGameEvent(GameMouseEvent event) {
if (event.getMousemode() == GameMouseEvent.LeftClick) {
firstClickOn(event.getX(), event.getY());
}
}
};
public void setGameMouselistener(GameMouseListener gml){
this.gamemouselistener=gml;
}
private GameMouseListener commonGameMouseListener = new GameMouseListener() {
public void processGameEvent(GameMouseEvent event) {
gamemouselistener.processGameEvent(event);
switch (event.getMousemode()) {
case GameMouseEvent.LeftClick:
gamemodel.open(event.getX(), event.getY());
break;
case GameMouseEvent.RightClick:
gamemodel.mark(event.getX(), event.getY());
break;
case GameMouseEvent.LRClick:
gamemodel.numberCheckOpen(event.getX(), event.getY());
break;
case GameMouseEvent.LRPress:
gamemodel.pressAround(event.getX(), event.getY());
break;
case GameMouseEvent.LRRelease:
gamemodel.releaseAround(event.getX(), event.getY());
break;
}
}
};
private BlockView[][] blockviews;
public BlockViewsPanel() {
init();
}
public void init() {
xx = gameconfigure.getXx();
yy = gameconfigure.getYy();
blockviews = new BlockView[xx][yy];
this.setLayout(null);
this.removeAll(); //移除所有以前的组件
for (int x = 0; x < xx; x++) {
for (int y = 0; y < yy; y++) {
blockviews[x][y] = new BlockView(x, y);
this.add(blockviews[x][y]);
}
}
int width = blockviews[0][0].getBlockSize() * xx;
int height = blockviews[0][0].getBlockSize() * yy;
this.setForeground(Color.BLUE);
this.setSize(width, height);
bindToMouseListener(startGameMouseListener);
}
public void setModel(GameModel gamemodel) {
this.gamemodel = gamemodel;
}
public void bindToModel() {
BlockModel[][] bm = gamemodel.getBlocks();
for (int x = 0; x < xx; x++) {
for (int y = 0; y < yy; y++) {
blockviews[x][y].setModel(bm[x][y]);
}
}
}
public void removeMouseListener(GameMouseListener listener) {
for (int x = 0; x < xx; x++) {
for (int y = 0; y < yy; y++) {
blockviews[x][y].removeGameMouseListener(listener);
}
}
}
public void bindToMouseListener(GameMouseListener listener) {
for (int x = 0; x < xx; x++) {
for (int y = 0; y < yy; y++) {
blockviews[x][y].addGameMouseListener(listener);
}
}
}
public BlockView[][] getBlockviews() {
return blockviews;
}
public void firstClickOn(int x, int y) {
gamemodel.initBlock(x, y);
bindToModel();
removeMouseListener(startGameMouseListener);
bindToMouseListener(commonGameMouseListener);
gamemodel.open(x, y);
}
public void gameTimeStart() {
}
public void gameTimeEnd(int endreason) {
removeMouseListener(commonGameMouseListener);
}
public void gameTimeChange(int timenumber) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -