如何将代理移动到空间中

时间:2014-09-29 00:43:34

标签: java text-based

我被困在家庭作业的一部分。我不确定如何将代理运送到另一个空间。

将方法usePortal添加到没有参数和void返回类型的Agent类。 此方法获取代理的位置门户,并检查它是否为空。

•如果门户网站不为null,请让门户网站使用门户网站传输代理 运输方式。您需要使用this来指代需要的代理 被运送。

•如果门户为空,则不要做任何事情。

public class Agent {
    private Space _location;
    private String _name;

    public Space get_location() {
        return _location;
    }
    public void set_location(Space _location) {
        this._location = _location;
    }
    public String get_name() {
        return _name;
    }
    public void set_name(String _name) {
        this._name = _name;
    }

    public String toString(){
        return _name;
    }

    public String toStringLong(){
        return _name + " is in " + _location;
    }

    public void usePortal(){

        if(Portal.get_destination() == null){

        }else{

        }
    }
}


public class Portal {
    private static String _name;
    private static String _direction;
    private static Space _destination;


    public String get_name() {
        return _name;
    }

    public void set_name(String  _name) {
        Portal._name = _name;
    }

    public String get_direction() {
        return _direction;
    }

    public void set_direction(String _direction) {
        Portal._direction = _direction;
    }

    public static Space get_destination() {
        return _destination;
    }

    public  void set_destination(Space _destination) {
        Portal._destination = _destination;
    }


    public String toString(){
        return _name + " that goes " + _direction;
    }

    public String toStringLong(){
        return _name + " that goes " + _direction + " to " + _destination;  
    }

    public void transport(Agent student){
        student.set_location(_destination);
    }
}

public class Space {
    Portal p = new Portal();
    private String _name;
    private String _description;
    private Portal _portal;

    public String get_name() {
        return _name;
    }

    public void set_name(String _name) {
        this._name = _name;
    }

    public  String get_description() {
        return _description;

    }

    public void set_description(String _description) {
        this._description = _description;
    }

    public Portal get_portal() {
        return _portal;
    }

    public void set_portal(Portal _portal) {
        this._portal = _portal;
    }

    public String toString() {
        return _name;
    }

    public String toStringLong(){
        if (_portal != null){
        return _name + ": " + _description + " with a " + p.toStringLong();
        }
        return _name + ": " + _description;

    }
}

1 个答案:

答案 0 :(得分:0)

列表和数组是基于Java的ZERO。第一个元素是0而非1