Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure Java text interface for a roguelike game

OK, this is going to sound like a crazy idea - but I'm interested in emulating a 1980s style roguelike game text interface in pure Java, i.e. using Swing or similar.

Here's roughly what it needs to do:

  • Provide a fixed size grid of fixed size characters as the "screen" (e.g. 100*75)
  • Use an appropriate monospaced font, ideally with lots of interesting symbols
  • Allow setting of foreground and background character colours for each character position individually
  • Allow printing of strings or individual characters at any place in the screen (which should overwrite whatever is already in the screen buffer in those locations)

Anyone know of a good existing solution that would enable this? Or am I stuck with hacking one together from scratch?

p.s. the reason I want pure Java is so that it can run in a sandboxed applet. So JNI solutions like jcurses are sadly ruled out.....

like image 674
mikera Avatar asked Feb 02 '11 20:02

mikera


1 Answers

Not crazy at all, this is the approach I implemented in Legerdemain:http://roguelikefiction.com

I used a two dimensional array of characters (char[][]) with a corresponding array of java.awt.Color[][] objects to track the colors. You can shove these arrays into a class that inherits from JPanel (which in turn is part of a JFrame) and do all of the drawing in the panel's paintComponent() callback.

Nothing wrong with the Curses/JNI approach either, although you get all sorts of great Unicode glyphs if you go the Swing route. Legerdemain uses five or six hundred of them.

like image 57
Nathan Jerpe Avatar answered Oct 12 '22 00:10

Nathan Jerpe