Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何处理参与者_Java_Arraylist_Timer_Jpanel_Multidimensional Array - Fatal编程技术网

Java 如何处理参与者

Java 如何处理参与者,java,arraylist,timer,jpanel,multidimensional-array,Java,Arraylist,Timer,Jpanel,Multidimensional Array,好的,我有一个坏家伙类,在这个类中我创建了一个随机数生成器和方法来上下左右移动图标,我把它包装在一个摆动计时器中,这样它就会不断重复,但是我的坏家伙不动,当我射杀他时,他会立即复活,有什么想法吗?这是我的代码,谢谢:) public class BadGuy扩展了战场网格{ ArrayList b=新的ArrayList(); 私人INTX; 私营企业; 私人形象不好; 定时器; 公众坏蛋(int x1,int y1,图像图标b){ x=x1; y=y1; 坏=b; } 公共int getx()

好的,我有一个坏家伙类,在这个类中我创建了一个随机数生成器和方法来上下左右移动图标,我把它包装在一个摆动计时器中,这样它就会不断重复,但是我的坏家伙不动,当我射杀他时,他会立即复活,有什么想法吗?这是我的代码,谢谢:)

public class BadGuy扩展了战场网格{
ArrayList b=新的ArrayList();
私人INTX;
私营企业;
私人形象不好;
定时器;
公众坏蛋(int x1,int y1,图像图标b){
x=x1;
y=y1;
坏=b;
}
公共int getx(){
返回x;
}
公共int gety(){
返回y;
}
公共图像图标getIcon(){
返回坏;
}
公共整数变更x(整数x1){
x1=x;
返回x;
}
公共整数兑换(整数y1){
y1=y;
返回y;
}
公敌(整数x,整数y){
如果(y<10){
返回;
}
WizardCells[x][y].setIcon(BadGuyWizard());
}
公共无效删除(int x,int y){
如果(y<10){
返回;
}
WizardCells[x][y]。设置图标(空);
}
公共空间向上移动(){
如果(this.getx()!=0){
WizardCells[this.getx()][this.gety()].setIcon(null);
WizardCells[this.changex(this.getx()-1)][this.gety()].setIcon(this.getIcon());
}
}
公共无效向下移动(){
if(this.getx()!=19){
WizardCells[this.getx()][this.gety()].setIcon(null);
WizardCells[this.changex(this.getx()+1)][this.gety()].setIcon(this.getIcon());
}
}
公权{
如果(this.gety()!=19){
WizardCells[this.getx()][this.gety()].setIcon(null);
WizardCells[this.getx()][this.changey(this.gety()+1)].setIcon(this.getIcon());
}
}
公共空间左移(){
如果(this.gety()!=10){
WizardCells[this.getx()][this.gety()].setIcon(null);
WizardCells[this.getx()][this.changey(this.gety()-1)].setIcon(this.getIcon());
}
}
公开作废动议(){
int延迟=100;
b、 添加(bgw);
计时器=新计时器(延迟,新ActionListener(){
已执行的公共无效操作(操作事件e){
int movechoice=(int)(Math.random()*4);
对于(坏人a:b){
if(movechoice==0){
a、 moveUp();
}
else if(movechoice==1){
a、 向下移动();
}
else if(movechoice==2){
a、 左移();
}
else if(movechoice==3){
a、 moveRight();
}
System.out.println(movechoice);
}
}
});
timer.start();
}
}
我的网格类:

public class WizardBattleGrid extends GameWindowWizard {
    public static JLabel[][] WizardCells = new JLabel [20][20];
    public static JPanel WizardPanel = new JPanel(new GridLayout(20, 20, 0, 0));
    static BufferedImage cursorimage = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    static Cursor blankcursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorimage, new Point(0, 0), "blank cursor");





        public static void CreateGrid(){

         for(int i=0; i<WizardCells.length; i++ ){
            for(int j=0; j<WizardCells[i].length; j++){

                JLabel label = new JLabel();
                WizardCells[i][j] = label;


            }
        }

        for(int i=0; i<WizardCells.length; i++){
            for(int j=0; j<WizardCells[i].length;j++){


                WizardPanel.add(WizardCells[i][j]);


            }

        }



        WizardCells[10][0].setIcon(GoodGuyWizardIcon());





        WizardPanel.setOpaque(true);
        WizardPanel.setBackground(Color.DARK_GRAY);
        WizardPanel.setCursor(blankcursor);

        gameWindow.add(WizardPanel);

    }
公共类向导BattleGrid扩展了GameWindowWizard{
公共静态JLabel[][]向导单元格=新JLabel[20][20];
publicstaticjpanel向导面板=新的JPanel(新的GridLayout(20,20,0,0));
静态BuffereImage cursorimage=新的BuffereImage(16,16,BuffereImage.TYPE_INT_ARGB);
静态游标blankcursor=Toolkit.getDefaultToolkit().createCustomCursor(游标图像,新点(0,0),“空白游标”);
公共静态void CreateGrid(){

对于(int i=0;i您的问题在于changex()和changey()方法。您实际上什么也不做,只是返回当前的x或y值。它应该是:

public int changex(int x1){

    x = x1;
    return x;
}

public int changey(int y1){

    y = y1;
    return y;
}

没有回答你的问题,但是…坏人是一种巫师战网?真的吗?也许你应该读一读关于继承和组合的书。非常感谢你,现在感觉自己像个白痴,因为我在好人课上有同样的方法,但我做得对哈
public int changex(int x1){

    x = x1;
    return x;
}

public int changey(int y1){

    y = y1;
    return y;
}