我正在尝试制作蛇游戏。我已经快完成了。问题是,有时当蛇吃掉敌人的物体时,会弹出此错误--->Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 33er.java:814)这是敌人的位置单元--->private int[] enemyYpos = {25,50,75,100,125,150,175,200,225,250,275,300,325,350,375,400,425,450,475,500,525,550,575,600,625,650,675,700,725,750,775,800,825,850};private int[] enemyXpos = {100,125,150,175,200,225,250,275,300,325,350,375,400,425,450,475,500,525,550,575,600,625};这是随机数--->private int xpos = r.nextInt(34);private int ypos = r.nextInt(20);现在,我通过使用for循环来绘制敌人,在其中定义了敌人的位置-> enemy = new ImageIcon("E:\\Netbeans\\old files\\Game\\src\\game\\bug.png"); if((enemyXpos[xpos] == snakeXlength[0] && enemyYpos[ypos] == snakeYlength[0])){ lengthsnake++; xpos = r.nextInt(34); ypos = r.nextInt(20); } enemy.paintIcon(this, g, enemyXpos[xpos], enemyYpos[ypos]); //The Exception error shows that the mistake is in this line我希望这些信息足够了。提前致谢!:)
添加回答
举报
0/150
提交
取消