如何向方法发送枚举?

时间:2017-11-24 01:02:25

标签: java methods enums arguments

我正在尝试创建游戏,并设置枚举以确定用户所在的屏幕。我想将用户所在的屏幕发送到将设置屏幕的方法。

private enum Screen {START, SETTINGS, MAP, ATTACK, END};
private Screen currentScreen;

public void begin () {
    setScreen(Screen.START);
}

public void onMouseClick(Location point) {
    switch (currentScreen) {
        case (Screen.START)
            break;
        case (Screen.SETTINGS)
            break;
        case (Screen.MAP)
            break;
        case (Screen.ATTACK)
            break;
        case (Screen.END)
            break;
    }
}

public void setScreen(/*I do not know what to put here, would i put enum, or Screen*/) {
    //set up screen here
}

我用什么作为参数?

1 个答案:

答案 0 :(得分:1)

语法与Screen是一个类相同:

public void setScreen(Screen screen) {
    //set up screen here
}