"在您输入扫描仪输入后出现-6ren"> "在您输入扫描仪输入后出现-我正在尝试创建一个基于文本的冒险游戏,并且我正在尝试添加一个功能,每当游戏需要您输入时,一个小勾号“=>”将显示在您输入的位置旁边。使用此处的代码,每当我在命令提示符 (Windows 7) 中运行它-6ren">
gpt4 book ai didi

java - 为什么打印语句 "=>"在您输入扫描仪输入后出现

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:30 26 4
gpt4 key购买 nike

我正在尝试创建一个基于文本的冒险游戏,并且我正在尝试添加一个功能,每当游戏需要您输入时,一个小勾号“=>”将显示在您输入的位置旁边。使用此处的代码,每当我在命令提示符 (Windows 7) 中运行它时,输入都会显示,而小勾号不会显示。输入后,勾号会出现在输入后。我希望能够像这样将刻度线和输入全部放在一行中,“=> [使用输入]”。请帮忙!

import java.io.IOException;
import java.util.Scanner;

import org.fusesource.jansi.AnsiConsole;



public class Game {

public static String BLACK = "\u001B[0;30m";
public static String RED = "\u001B[0;31m";
public static String GREEN = "\u001B[0;32m";
public static String YELLOW = "\u001B[0;33m";
public static String BLUE = "\u001B[0;34m";
public static String MAGENTA = "\u001B[0;35m";
public static String CYAN = "\u001B[0;36m";
public static String WHITE = "\u001B[0;37m";

public final static String ESC = "\033[";

public static String name;
public static String gender;

public static void main(String[] args) {
AnsiConsole.systemInstall();

check();
}

public static void start() {

Scanner a = new Scanner(System.in);

System.out.println("###############################################################################");
System.out.println("# #");
System.out.println("# " + YELLOW + "^.^" + WHITE + " " + "Adventure Time Is Yes " + YELLOW + "^.^" + WHITE + " #");
System.out.println("# #");
System.out.println("###############################################################################");

//Get Name
System.out.print("\n");
System.out.println("Hello young lad! What is thy " + RED + "name " + WHITE + "you were given at birth?");
System.out.print("=> ");
//Global Variable for Name
name = a.next();

System.out.print("\n");

System.out.println("Hello " + RED + name + WHITE + "! Are you a Male or Female?");
System.out.print("=> ");
gender = a.next();


}

public static void check() {

Scanner a = new Scanner(System.in);

System.out.println("Can you see these colors?: ");
System.out.println(RED + "Red " + GREEN + "Green " + YELLOW + "Yellow " + BLUE + "Blue " + MAGENTA + "Magenta " + CYAN + "Cyan " + WHITE + "White");
System.out.println("Y/N");
System.out.print("=> ");

String as = a.nextLine();
as.toUpperCase();

if (as == "Y") {
System.out.println(ESC + "2J");
start();
} else {
System.out.println(ESC + "2J");
start();
//Future idea is to make it so there is an exact copy of the game but without color :D
}

}
}

/*try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}

System.exit(0);*/

//System.out.println(ESC + "2J"); Clear Lines On Screen

最佳答案

您可以使用 outputstreamName.flush() 刷新输出流。如需更多帮助,请参阅 this exampledocs .

刷新输出流将帮助您找出代码失败的地方。

关于java - 为什么打印语句 "=>"在您输入扫描仪输入后出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21323890/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com