斯坦福 IT

月盈亏

月月盈
最大赞力
0.00
当前赞力
100.00%
Current position应该设置为飞船类的一个属性。
A B 各是一个飞船类的实例。
public classGame {
private Spaceship A;
private Spaceship B;

A.moveto();
B.moveto();

A.moveto();
B.moveto();
}

public class Spaceship {
private Planete currentPlanet;
private name

public Spaceship(String name){
}

public void moveto{
...find currentplanet;
....move to next planet;
...save currentplanet;
}
大概这个意思,就是没明白怎么能把currentplant跟spaceship捆绑起来
 

月盈亏

月月盈
最大赞力
0.00
当前赞力
100.00%
public class SpaceGame{

private Spaceship A;
private Spaceship B;

public SpaceGame(String name){
ArrayList<Planet> planets = FileIO.loadPlanets("sol.txt");
Spaceship.setPlanets(planets);

Spaceship s = new Spaceship();
String playerName = A.getName();
s.setName(playerName);
String firstPlanetName = planets.get(0).getName();
s.moveTo(firstPlanetName);

Spaceship s = new Spaceship();
String playerName = B.getName();
s.setName(playerName);
String lastPlanetName = planets.get(8).getName();
s.moveTo(lastPlanetName);


public class Spaceship{
private String name;
private Planet currPlanet;

public void moveTo(String name){
int x = Planet.findPlanet(name,Spaceship.planets);
String Name = getName();

Planet currPlanet = planets.get(x);
String currName = currPlanet.getName();
System.out.println("Spaceship " +Name +" moved to " + currName);
setCurrPlanet(currPlanet);
}
 

月盈亏

月月盈
最大赞力
0.00
当前赞力
100.00%
别把currentPosition设置成静态变量就好了。
没有设静态啊
private Planet currPlanet;

我觉得是我引用的不对,可是不知道怎么引用
Spaceship s = new Spaceship();
System.out.println(s.currPlanet);
这样写不成功
 
最大赞力
0.00
当前赞力
100.00%
Java程序员改作C#了。忘记怎么写了。
public interface SomeBehaviourAndProperty{
public int position;
public void move();

}

public abstract class Star implements SomeBehaviourAndProperty{
public void move(){
//do some common
}
}

public class Solar {
private Earth earth;

}

public class Earth extends Start{
public Earth(){
}
public void move(){
super.move();
//some special move
}
}

public class Moon extends Start{
public Moon(){
}
public void move(){
super.move();
//some special move
}
}
 

Similar threads

家园推荐黄页

家园币系统数据

家园币池子报价
家园币最新成交价
家园币总发行量
加元现金总量
家园币总成交量
家园币总成交价值

池子家园币总量
池子加元现金总量
池子币总量
1池子币现价
池子家园币总手续费
池子加元总手续费
入池家园币年化收益率
入池加元年化收益率

微比特币最新报价
毫以太币最新报价
微比特币总量
毫以太币总量
家园币储备总净值
家园币比特币储备
家园币以太币储备
比特币的加元报价
以太币的加元报价
USDT的加元报价

交易币种/月度交易量
家园币
加元交易对(比特币等)
USDT交易对(比特币等)
顶部