Reputation: 75
So I was trying to do a something like tic-tac-toe in java. Instead of printing a new board every time a player make a move I want to just overwrite the previous board.
Example board:
x|x|x
-+-+-
x|x|x
-+-+-
x|x|x
I tried with \r while printing the last line but seems like it only goes back to the start of the last line but what I want is to the start of the first line.
Upvotes: 0
Views: 228
Reputation: 9058
In old-school C, this was done with a Unix library called Curses. So I did a google for Java curses library and got this link:
The other choice might be to use Swing to make it a GUI instead of a terminal program. But if you just want to work within the terminal window, this question points out several libraries that could help you.
Basically you need to send escape codes to the terminal window that tell the terminal what to do. Google VT100 escape codes as an example of what I mean, but your terminal window may not emulate a VT100 (an old, old text terminal from Digital Equipment Corp). So you can't just use VT100 escape sequences, as they might not be right. Instead, those libraries should look at your TERM environment variable and send the right escape sequences.
I have absolutely no idea if they'll work on Windows (if that's your environment). Good luck.
Upvotes: 1