a different tile technique

hello everyone.

i have been reading these forums for a while on game development and would like to ask you all a question ;D

I would like to try something new, but have not found any information on the topic for java. this is what i want :-

  1. create a screen of tiles (easy)
  2. give each tile a name that the java program can identify (cant do)
  3. apply attributes to the tiles

the intended outcome will be related to resources, that is each tile will have a different number of resources. using co-ordinates i cant figure out how to do this (i can make tiles but i cant give them a name). i could use panels or buttons but i dont want outline visable.

can anyone give suggestions for this method?

an example of this method is as follows.

object name food value wood value iron value

Tile1 5 0 0
Tile2 5 0 0
Tile3 0 5 0
Tile4 0 0 5

in the above example it is greatly simplified and consists of only 4 tiles. i believe that giving a tile an identifier will allow me to use algorithms to randomly generate different attributes for the tiles.
Refering back to using buttons or panels - i can give these two objects attributes, because they have an identifier eg jpanel1 jpanel2 etc. i have not been able to get rid of outlines or apply art to them tho.

thank you in advance for any help/articles/webpages that are relavent.

All you need is a map class that holds the information you want:

public class Map {
int sizeX; // map size
int sizeY; // map size

int[][] tileID; // tile id you use to lookup what tile to draw

string[][] description; // this is your tile description
int[][] food; // stores the food value
int[][] wood; // etc
int [][] iron; // etc

And maybe I’m misunderstanding what you’re asking, but you shouldn’t be trying to draw tiles using buttons or jpanels. Assuming that youre using Java2d you should be loading Image objects through ImageIO. After you have some tiles loaded you could then draw them to your jpanel or jframe.

It sounds like you should start with getting a handle on how a tile based structure works. I’d recommend going to gamedev.net and checking under the articles/tile based graphics sections.

alternately just make a Tile class that holds this info…

it sounds like you are using Swing (JLabels?) to do your game. Just do something like


Tile extends JLabel{
   int food = 0, iron = 0, wood = 0;
   String name = null;
   public Tile(int f, int i, int w, String n, ImageIcon icon)
   {
        super(icon)
        this.food = f;

etc…

while using Swing can work for low action games, you might want to look at building it from the ground up and doing your own rendering.

however, i suppose you might want to have the mouselistener and tool tips and all that stuff for your tiles as well, which could be convenient for a game like that where clicking on a tile will bring up info in the bottom.

hello.

firstly, thankyou both of you for replying to my question. they look like they will help me get what i want. im not able to try it out and integrat it into what i have at the moment, but i will do soon.
One of you said you were a buit unsure of my references to jpanels and the such. well i used jpanels as a dummy, just to see what i could do if a “tile” had a name.
Using my example of 4 tiles only, i call them tile1,tile2,tile3,tile4. each tile will have the food/wood/ore attributes but also the attribute picture.
a simple algorithm to be used (this is not written in java in this explanation) is using statements eg if…else.

  1. tile1 will have a randomly generated number between one and five for each resource. if there are two fives, they are rerolled.
  2. the highest number will dictate the type of terrain the tile is on. if there is a “five” then the other two attributes are changed to zero. ( a mixture of numbers eg 3 3 4 gives the attribute - rough)
  3. so a “five” in food will class the tile as “grass”. With the tile identified as “grass”, the appropriate image is used on the tile.
  4. the state of the first tile will dictate the state of the other tiles - this means if tile1 is “grass” then tile2 cannot be grass ( ie 5 food ), so tile2 has a “zero” for grass and so on.

i hope to use this to randomly generate different tiles. my use of jpanels was only because it was the only way that i knew of to actually give a tile an identifier. i do not intend to use them. i am aware that this theory is similar to turn based games, such as civilization, but i want to try to implement it into a different type of game. there is information out on the web, but 99% of it is visual basic or c++ ( i want java ;D). the algorithms are not a problem , i just need to be able to assign those 3 values and be able to assign the appropriate picture to each one. hopefully the suggestions you gave me will allow me to do this :slight_smile:

thankyou.