Pure Java text interface for roguelike games
OK, that sounds like a crazy idea - but I'm interested in emulating the 1980s style roguelike game text interface in pure Java, using swing or something like that
This is probably what it needs to do:
>Provide a fixed size grid of fixed size characters as a "screen" (e.g. 100 * 75) > use appropriate constant width fonts, ideally there are many interesting symbols > allow the foreground and background colors of each character position to be set separately > allow string or single characters to be printed anywhere in the screen (any content in the screen buffer in these positions should be overwritten)
Does anyone know that a good existing solution can achieve this? Or have I been hacking from the beginning?
PS: the reason I want pure Java is that it can run in sandbox applet So JNI solutions like jcurses sadly rule out
Solution
It's not crazy at all. This is the method I implemented in legerdemain: http://roguelikefiction.com
I use a two-dimensional array of characters (char []) with a corresponding Java awt. Color [] [] object array to track color You can push these arrays into a class that inherits from JPanel, which is also part of JFrame, and execute all drawings in the paintcomponent() callback of the panel
翻译错误 TIMEOUT