所以对于我正在创建的游戏,我有一些扩展 GameDriver 的类。
到目前为止,在所有其他类上我已经能够扩展 GameDriver 然后在 GameDriver 中我可以做到:
ArrayList<Card> library = new ArrayList<Card>();
今天我开始学习 GameAI 课程并扩展了 GameDriver,当我把:
GameAI Enemy = new GameAI();
在同一个地方,我放了另一行代码(在公共类 GameDriver 的正下方)
我得到:
java.lang.StackOverflowError
at java.util.WeakHashMap.expungeStaleEntries(Unknown Source)
at java.util.WeakHashMap.getTable(Unknown Source)
at java.util.WeakHashMap.get(Unknown Source)
at java.awt.Component.checkCoalescing(Unknown Source)
at java.awt.Component.<init>(Unknown Source)
at java.awt.Container.<init>(Unknown Source)
at java.awt.Panel.<init>(Unknown Source)
at java.awt.Panel.<init>(Unknown Source)
at java.applet.Applet.<init>(Unknown Source)
at GameDriver.<init>(GameDriver.java:14)
at GameAI.<init>(GameAI.java:8)
at GameDriver.<init>(GameDriver.java:40)
at GameAI.<init>(GameAI.java:8)
如果我把它放在我的小程序的 public void init() 中,那么它在运行时不会出错,但是我将无法从我的其他方法访问它,我是不是在看东西?通宵达旦通常对我的大脑没有帮助...
这就是 GameAI 现在的样子:
public class GameAI extends GameDriver {
public int life;
public int energy;
public void drawPhase(){
}
public GameAI(){
life = 20;
energy = 2;
}
}
然后是 GameDriver 的一些内容:
public class GameDriver extends Applet implements MouseMotionListener,MouseListener {
Graphics g;
Image offscreen;
Dimension dim;
int playerLife = 20;
int playerEnergy = 8;
int xMouse;
int yMouse;
int lineThickness = 4;
int handSize = 6;
int currentHover;
boolean slotHover;
int currentSelected;
boolean slotClicked;
int currentHoverBoard;
boolean slotHoverBoard;
boolean slotClickedBoard;
int currentSelectedBoard;
boolean canPlace;
ArrayList<Card> library = new ArrayList<Card>();
ArrayList<Card> hand = new ArrayList<Card>();
ArrayList<Card> playerBoard = new ArrayList<Card>();
GameAI Enemy;
int[] handBoxX = new int[handSize];
int[] handBoxY = new int[handSize];
int[] handBoxW = new int[handSize];
int[] handBoxH = new int[handSize];
int[] playerBoardX = new int[8];
int[] playerBoardY = new int[8];
int[] playerBoardW = new int[8];
int[] playerBoardH = new int[8];
public void init(){
this.setSize(640, 480);
dim = this.getSize();
addMouseMotionListener(this);
addMouseListener(this);
createLibrary();
drawFirstHand();
printHand();
GameAI Enemy = new GameAI();
checkEnemy();
offscreen = createImage(this.getSize().width,this.getSize().height);
g = offscreen.getGraphics();
}
public void checkEnemy(){
System.out.println(Enemy.energy);
}
... Alot more methods and stuff below, but nothing to do with the GameAI enemy