0

我昨天通过将所有类分成单独的文件来解决我之前的问题。尽管如此,我还是把所有的代码都写下来了,没有看到任何错误能够编译程序。或者我是这么想的。

这是错误代码:

Exception in thread "main" java.lang.StackOverflowError
at java.util.AbstractCollection.<init>(Unknown Source)
at java.util.AbstractList.<init>(Unknown Source)
at java.util.Vector.<init>(Unknown Source)
at java.util.Vector.<init>(Unknown Source)
at java.util.Vector.<init>(Unknown Source

这是我得到错误的地方(标有问题?)

public class GameWorld implements IObservable, IGameWorld 
{
// create collections class
public Vector<GameObject> GameObjectList = new Vector<GameObject>(); // PROBLEM
private Vector<IObserver> ObserverList = new Vector<IObserver>();
    // declare objects
Tank pTank = new Tank(10, 10);
// other objects and variables to declare 
public GameWorld() 
{
 // add objects to GameObjectList
}
// accessors/mutators
}

我在这里遇到另一个错误

public class Tank extends Movable implements ISteerable
     {
 private int armorStrength;
 private int missileCount;
 public Tank()
 {}

 public Tank(int armStr, int misslCt) // problem?
 {
     armorStrength = armStr; // default armorStrength
     missileCount = misslCt; // default missileCount
 }
 public void setDirection(int direction)
 {
    this.setDirection(direction); // get input from left turn or right turn
    // updateValues();
 }
     // access/mutators here

我很困惑在这里做什么。

这是主要代码

public class Starter {

public static void main (String args[])
{
    Game g = new Game();

}
    }

它有一个 Game 类,基本上是程序的 GUI

public class Game extends JFrame { 

 private GameWorld gw; 
 private MapView mv; // new in A2 
 private ScoreView sv; // new in A2 

公共游戏(){

 gw = new GameWorld(); // create “Observable” 
 mv = new MapView(); // create an “Observer” for the map 
 sv = new ScoreView(gw); // create an “Observer” for the game state data 
 gw.addObserver(mv); // register the map Observer 
 gw.addObserver(sv); // register the score observer 

     // code here to create menus, create Command objects for each command, 
     // add commands to Command menu, create a control panel for the buttons, 
     // add buttons to the control panel, add commands to the buttons, and 
     // add control panel, MapView panel, and ScoreView panel to the frame  



 setVisible(true); 
 } 
     }

并且有很多其他功能的参考。

4

0 回答 0