6

I don't have much experience in Java, but I am attempt to write a simple rogue-like game to familiarize myself with it, and I am just wondering how I would go about creating an interface like this:

A screen from JADE by Thomas Biskup Are there any obvious ways that you would go about something like this? Being new to Java, I really have no idea what the best method would be.

Sorry to be vague!

Thanks

Adam K Dean
  • 7,387
  • 10
  • 47
  • 68

3 Answers3

4

There is no such (simple) component in the JDK - if you don't need color, a JTextArea can be used to display ASCII-Art (after setting a fixed-width font). You will need to take care not to run into characterset issues (if you don't stick to US-ASCII 7-bit). Writing a component that handles color display (and maybe escape sequences, in essence emulates a console window) wouldn't be too hard, but if you just started with Java it may prove to be an unwelcome challenge.

You could also just write your game in Java and leave displaying the ASCII to the system console (your game would simple output to stdout).

Edit: Color ASCII could be acieved by converting your internal format to (simple) HTML and that HTML could be displayed using a JLabel. Its probably not the most elegant method, but it should be reasonably simple to implement (and with nowadays hardware speed should not be an issue with this approach either). This approach builds on the capability that you can just use JLabel.setText() and pass a string that starts with a HTML tag. The JLabel then interprets the whole text as HTML.

Durandal
  • 19,919
  • 4
  • 36
  • 70
  • I was going to say (after reading the first two paragraphs), could I not just use a monospaced font and format it with HTML and put that into a JLabel.. the one thing I would like to avoid is getting repaint flicker, I've ran into that problem when displaying everything in a single control before, just never tried to do it in Java before. I will tinker and see what I can come up with. Thanks! – Adam K Dean Jun 29 '12 at 12:58
3

Check out Trystan's Ascii Panel, and his blog and tutorial on making a roguelike here.

Anubian Noob
  • 13,426
  • 6
  • 53
  • 75
1

Better late than never, right? You may want to check Zircon Project.

Viking
  • 328
  • 4
  • 9
  • That looks super cool, however, ten years on, while I love roguelikes, I don't have nearly enough time for this project. Thanks though, definitely better late than never! – Adam K Dean Aug 03 '22 at 11:33