How to create a map in Java?

I am trying to complete an RPG game for a project, but don’t know how to make a game map. This does not have to be graphic, but the code for the entire map and each tile must be correct.

So far, I have been thinking of creating a non-matrix map (as a professor request) using an ArrayList that contains all the associated fragments.

public abstract class Casella {
/** 
 * @uml.property name="tabellone"
 * @uml.associationEnd multiplicity="(1 1)" inverse="casella:Tabellone"
 * @uml.association name="contains"
 */

private int id;
private boolean free = true;
private List adjacent;
private List items;
private Tabellone tabellone = null;

public void in(){
    free = false;
}

public void out(){
    free = true;
}

}

This was the code for one tile (which has 3 classes that extend it). I still don’t know how to assemble and create a map.

Thank you for your time.

+3
source share
8 answers

, . ArrayList, . , ArrayList .

http://en.wikipedia.org/wiki/Adjacency_list

+1

, , . , . :

, ? ? " X"?

[EDIT] RPG. / - (.. - ).

. (, , ). , (.. ?)

: , . , , , ( ).

, " ". : , , , . . - , .

, ASCII ( "C", "P", "H" ill), , .

+9

​​ , , , . , - , . , , , :

private Tabellone up = null;
private Tabellone down = null;
private Tabellone left = null;
private Tabellone right = null;

, . , , , , Tablellone , , .

Tabellone adj = new Tabellone();
up = adj;
adj.setDown(this);

, . . . , , , , , .

int count = 0;
ArrayList<Tabellone> queue = new ArrayList<Tabellone>()
queue.add(/*center tile*/);
while (count < 100) { //if we want 100 tiles
  //take out the center tile from the beginning of the array list, create a tile for each direction and add those tiles to the array list, then increment count by 1.
}

.. , , .

, , , .

+3

, - , , .

private String level =
          "    ######\n"
        + "    ##   #\n"
        + "    ##$  #\n"
        + "  ####  $##\n"
        + "  ##  $ $ #\n"
        + "#### # ## #   ######\n"
        + "##   # ## #####  ..#\n"
        + "## $  $          ..#\n"
        + "###### ### #@##  ..#\n"
        + "    ##     #########\n"
        + "    ########\n";

. , . (#) . ($) . (.) , . at (@) - sokoban. , , (\n) .

+2

? , 2d-?

-

Casella map [][] = new Casella[xSize][ySize];

, Excel, .

, , , . . , , -, , .

, .

for(int i = 0; i < XSIZE ; ++i)
    for(int j = 0; j < YSIZE ; ++j)
        if(j==0) //found left edge (i.e. no adjacent ones to the left)
        if(j==(YSIZE)) //found right edge (you get the picture) 

, , , , 2, 3 4.

+1

, , , , /.

, , X- , - , , , , , , edge, , , a multimap, .

, , AlbertoPL .

, X- Y-, , 4 2 , . , [Y] [X] [Y + 1] [X] [Y] [X + 1] . max 6 min 3, [Y + 1] [X + 1] [Y] [X]. , , 2 , . , , , . , , , , () , .

+1

, . ( , ), .

, , , (n, s, e, w). , 1-6 (, ). .

0

Aaron, , .

X-Y-Z. , . , .

, RPG, . ? ? ?

, , , .

, .

0

Source: https://habr.com/ru/post/1710988/


All Articles