该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JPanel;
/**
* 棋盘
*/
public class ChessBoard extends JPanel {
private final static int WIDTH = 393;
private final static int HEIGHT = 532;
private JPanel panel = new JPanel();
private static ChessBox boxs[][] = new ChessBox[14][5];
public ChessBoard() {
this.setLayout(null);
this.setSize(WIDTH, HEIGHT);
this.setLocation(100, 0);
panel.setLayout(new GridLayout(14, 5, 5, 15));
panel.setLocation(100, 0);
panel.setSize(195, HEIGHT);
loadMap();
this.add(panel);
}
public void paint(Graphics g) {
super.paint(g);
g.drawImage(LoadImage.bgimg, 0, 0, null);
this.repaint();
ChessBlock chess = new ChessBlock("工兵",LoadImage.redimg,ChessColor.getRED());
chess.draw(g);
}
// 加载地图
public void loadMap() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("map.txt")));
for (int i = 0; i < 14; i++) {
String line = br.readLine();
for(int j=0;j<5;j++){
char c = line.charAt(j);
ChessBox box = null;
if(c=='2'){
box = new ChessBox(false,false);