Temple of The Roguelike Forums

Development => Programming => Topic started by: Brigand on July 17, 2011, 04:38:51 PM

Title: Java rogues that are open source?
Post by: Brigand on July 17, 2011, 04:38:51 PM
Are there any Java roguelikes out there that are open source? I've been learning Java at school, but they focus on pesky data structures and how to write white papers. I'm specifically interested in how the display elements are implemented. I downloaded Jcurses but it's hard to understand everything just reading the javadoc.
Title: Re: Java rogues that are open source?
Post by: taffer on July 25, 2011, 11:59:09 AM
At the moment I am writing a rogue in java.  How I am doing it is creating a class that extends JPanel which has char[][] and Color[][] Buffers.  Writing the map to the screen all you need to do is override the JPanel's paintComponent(Graphics g) method:
Code: [Select]
public class MyJPanel extends JPanel
{

      private Color[][] cColors;  //The Colors of the map
      private char[][]   chChar;  //The characters of the map

      public MyJPanel()
      {

             cColors = new Color[20][20];
             chChar = new char[20][20];

             for(int iy = 0; iy < 20; iy++)
                 for(int ix  = 0; ix < 20; ix++)
                 {

                      cColor[ix][iy] = Color.WHITE;
                      chChar[ix][iy] = '#';

                  }

      }
      //This overrides JPanel's paintComponent method
      public void paintComponent(Graphics g)
      {

            super.paintComponent(g);  //Always do this first when overriding paintComponent

             for(int iy = 0; iy < 20; iy++)
                 for(int ix  = 0; ix < 20; ix++)
                 {

                        g.setColor(cColors[ix][iy];
                        g.drawString(String.valueOf(chChar[ix][iy]),
                             StartX + (CharSpace * ix),
                             StartY + (LineSpace * iy));                     

                  }     

      }

}

In the g.drawString method:

StartX:         is the pixel you wish to start drawing on the X axis,
StartY:         is the pixel you wish to start drawing on the Y axis
CharSpace:   is how I create spacing between each character - X axis spacing
LineSpace:    is how I create spacing between each Line - Y axis spacing

Now if you wish to use tile graphics instead g has a many drawImage methods.
g has many methods in it to draw graphics onto a JPanel. 

I hope this helps

Taffer
Title: Re: Java rogues that are open source?
Post by: Slash on July 27, 2011, 03:42:34 AM
There's a bunch of Open Source Java roguelikes here: http://slashie.net/openxrl

You might also want to check libjcsi for console output in java, it might be just what you need: http://slashie.net/libjcsi/
Title: Re: Java rogues that are open source?
Post by: TSMI on August 02, 2011, 01:20:41 AM
You might also want to check libjcsi for console output in java, it might be just what you need: http://slashie.net/libjcsi/

Must...resist...writing engine...for jvm....

Damn you Slashie!!!