所以我有这个迷宫游戏,我试图使用RNG来确定当用户撞墙,越界或到达迷宫尽头时要打印出的消息。我在TextCard类中拥有所有这些消息,但是我希望所有文本卡都与周围的边框无关,所以我创建了另一个名为buildBorder的方法,但是当我运行代码时,它仅输出消息,而不输出边界,我不知道为什么。
BUILDBORDER方法
public String buildBorder(String cardType){
return ("**********************\n" + cardType + "\n" + "**********************");
墙纸方法
public String wallCard(){
Random rnd = new Random();
number = rnd.nextInt(100) + 1;
if(number < 20 && number > 1){
cardText = ("Going that way would lead to a painful face plant");
return (cardText);
}
if(20 < number && number < 40){
cardText = ("Some are destined for greatness, You are destined for a hard surface. You cant go this way");
return (cardText);
}
if(40 < number && number < 60){
cardText = ("Are you lost? or do you just like running into walls?");
return (cardText);
}
if(60 < number && number < 80){
cardText = ("phasing is not your strong suit. Find another way, this wall is as hard as your skull, take the hint.");
return (cardText);
}
else{
cardText = ("You spend longer than you should looking for the door handle, only to realize you ran into a wall.");
return (cardText);
}
}
CONSTRUCTOR(部分)
public TextCard(CardType cardType)
{
if(cardType == (CardType.WALL)){
buildBorder(wallCard());
}
GETCARD方法
public String getCard(){
return this.cardText;
}
其他类别的方法调用
else if((this.maze.isWall(x, y, "N")) == true){
System.out.println(new TextCard(TextCard.CardType.WALL).getCard());
也忘记发布了,但这是我的枚举
public enum CardType{
WALL, OUT, START, END
}
答案 0 :(得分:3)
调用buildBorder(wallCard());
时,它将返回一个字符串。
您不将此字符串分配给任何内容-您不打印它,存储它。很自然,什么也没发生。
String temp = buildBorder(wallCard()); // NOW you can do whatever your heart desires