Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to display ASCII in a grid with panels using Java?

Tags:

java

roguelike

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

like image 479
Adam K Dean Avatar asked Jun 29 '12 10:06

Adam K Dean


2 Answers

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.

like image 139
Durandal Avatar answered Nov 15 '22 13:11

Durandal


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

like image 30
Anubian Noob Avatar answered Nov 15 '22 11:11

Anubian Noob