Select Git revision
Display.java
Kellian Mirey authored
Display.java 1.55 KiB
package bitFight;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Display {
public static int row = 1;
public static void clearScreen() {
System.out.print("\033[H\033[2J");
}
public static String loadTextFile(String path) throws IOException{
FileInputStream fis = new FileInputStream(path);
InputStreamReader instreamReader = new InputStreamReader(fis);
BufferedReader reader = new BufferedReader(instreamReader);
String data = "";
while (reader.ready()){
data += reader.readLine() + "\n";
}
reader.close();
return data;
}
public static void setCursorPos(int row, int col){
char escCode = 0x1B;
System.out.print(String.format("%c[%d;%df",escCode,row,col));
}
public static void goToDialogBox(){
setCursorPos(row+7,0);
}
public static void clearDialogBox() throws IOException{
clearScreen();
setCursorPos(row, 0);
printDialogBox();
goToDialogBox();
}
public static void printDialogBox() throws IOException{
setCursorPos(50, 0);
String dialogBox = loadTextFile("assets/DialogBox.text");
System.out.println(dialogBox);
}
public static void goToUserInput(){
setCursorPos(50, 0);
}
public static void newPrintln(String text) throws IOException{
clearDialogBox();
System.out.println(text);
goToUserInput();
}
}