在java中传递静态类变量

时间:2021-09-27 17:02:23

This is a game where you jst randomly walk around a maze and find items so that you can fight the boss.

这是一个游戏,你随机走动迷宫,找到物品,这样你就可以对抗老板。

The entire code is about 350 lines so ive pulled out the relevant parts. But the problem is that "items" isnt working and when the "monster" method is used it just ignores it. (Sorry for swedish comments)

整个代码大约有350行,所以我已经拿出了相关的部分。但问题是“项目”不起作用,当使用“怪物”方法时,它只是忽略它。 (对不起瑞典评论)

//The static

public class Spel
{
static Rum current;
static Rum rum12 = new Rum("Du hittar ingenting. " , "En väg. ");
static boolean items = false;

//Where "visited" is used.

//使用“访问过的”。

    if (current.item1 != null){
        current.visited = true;
        }
        if (current.item2 != null){
        current.visited = true;
        }
        if (current.item3 != null){
        current.visited = true;

//Where "items" is checked.

//检查“项目”的位置。

  boolean items = ((rum9.visited==true) || (rum2.visited==true) && (rum5.visited==true));

//Where im trying to use "items".

//我试图使用“项目”。

public class monster {

public void rulla1(){
if (Spel.items == false){
System.out.println("Du behöver hitta 2 objekt för att slåss mot bossen");
Spel.current = Spel.rum12; /
}else

2 个解决方案

#1


It's not ignored, it is just empty, so it does what you code it to do: nothing.

它没有被忽略,它只是空的,所以它做你编码它做的事情:没有。

public monster() {
}

Maybe you meant to call rulla1().

也许你打算打电话给rulla1()。

#2


Firstly monster() is not the method it's constuctor.

首先,monster()不是它的构造方法。

Secondly it is not doing anything because nothing is written into it , It's Empty

其次它没有做任何事情,因为没有任何东西写进去,它是空的

public monster() {
}

#1


It's not ignored, it is just empty, so it does what you code it to do: nothing.

它没有被忽略,它只是空的,所以它做你编码它做的事情:没有。

public monster() {
}

Maybe you meant to call rulla1().

也许你打算打电话给rulla1()。

#2


Firstly monster() is not the method it's constuctor.

首先,monster()不是它的构造方法。

Secondly it is not doing anything because nothing is written into it , It's Empty

其次它没有做任何事情,因为没有任何东西写进去,它是空的

public monster() {
}