📄 echiquier.java
字号:
import java.awt.Color;
import javax.swing.JPanel;
public class Echiquier {
int taille;
JPanel [][] tableau;
Element jr, mtr;
boolean cle;
Echiquier(int[][] tab){
cle=false;
taille=tab.length;
tableau=new JPanel[taille][taille];
for(int i=0;i<taille;i++){
for(int j=0;j<taille;j++){
tableau[i][j]=new JPanel();
switch (tab[i][j]){
case 1: tableau[i][j].setBackground(Color.black);break;
case 0: tableau[i][j].setBackground(Color.white);break;
case 2: {tableau[i][j].setBackground(Color.blue);
jr=new Element(i,j,Color.blue);
break;
}
case 3: tableau[i][j].setBackground(Color.yellow);break;
case 4: {tableau[i][j].setBackground(Color.red);
mtr=new Element(i,j,Color.red);
break;
}
}
}
}
}
public void setTableau(int[][] tab){
for(int i=0;i<taille;i++){
for(int j=0;j<taille;j++){
//tableau[i][j]=new JPanel();
switch (tab[i][j]){
case 1: tableau[i][j].setBackground(Color.black);break;
case 0: tableau[i][j].setBackground(Color.white);break;
case 2: {tableau[i][j].setBackground(Color.blue);
jr.setX(i);
jr.setY(j);
break;
}
case 3: tableau[i][j].setBackground(Color.yellow);break;
case 4: {tableau[i][j].setBackground(Color.red);
mtr.setX(i);
mtr.setY(j);
break;
}
}
}
}
}
public Color getColor(int x, int y){return tableau[x][y].getBackground();}
boolean estMur(int x, int y){
if (tableau[x][y].getBackground()==Color.black)
return true;
return false;
}
Element getJoueur(){
for(int i=0;i<taille;i++){
for(int j=0;j<taille;j++){
if(estJoueur(i,j)) {
jr.setX(i);
jr.setY(j);
}
}
}
return jr;
}
Element getMonsteur(){
for(int i=0;i<taille;i++){
for(int j=0;j<taille;j++){
if(estMonsteur(i,j)) {
mtr.setX(i);
mtr.setY(j);
}
}
}
return mtr;
}
JPanel getJPanel(int x,int y){return tableau[x][y];}
void setJoueur(int x, int y){
tableau[x][y].setBackground(Color.blue);
}
void deleteJoueur(int x, int y){
tableau[x][y].setBackground(Color.white);
}
void setMonsteur(int x, int y){
tableau[x][y].setBackground(Color.red);
}
void deleteMonsteur(int x, int y){
tableau[x][y].setBackground(Color.white);
}
int getTaille(){return taille;}
boolean estMonsteur(int x, int y){
if (tableau[x][y].getBackground()==Color.red)
return true;
return false;
}
boolean estJoueur(int x, int y){
if (tableau[x][y].getBackground()==Color.blue)
return true;
return false;
}
boolean estOr(int x, int y){
if (tableau[x][y].getBackground()==Color.yellow)
return true;
return false;
}
boolean getCle(){
return cle;
}
void setCle(boolean b){
cle=b;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -