Skip to main content
Added Javascript version
Source Link
tryzor
  • 156
  • 2

Like @Anko suggested, you should use a graph as data structure for your game map. If you use the this implementation of a graph in Java as a starting point you can represent your map as follows:

Graph<Zone> gameMap = new Graph<>();

Zone zone1 = new Zone("Zone1");
Zone zone2 = new Zone("Zone2");
Zone zone3 = new Zone("Zone3");
Zone zone4 = new Zone("Zone4");
Zone zone5 = new Zone("Zone5");
Zone zone6 = new Zone("Zone6");
Zone zone7 = new Zone("Zone7");
Zone zone8 = new Zone("Zone8");
Zone zone9 = new Zone("Zone9");
Zone zone10 = new Zone("Zone10");

gameMap.addEdge(zone1, zone2);
gameMap.addEdge(zone2, zone3);
gameMap.addEdge(zone2, zone4);

If you want to check if you can attack zone2 from zone1 you can just do

// can attack zone2 from zone1
gameMap.hasEdge(zone1, zone2);

Edit: I reimplemented the Java version in Javascript. You can use it like the Java version.

Here you can find the complete implementation of the above example in Java and Javascript.

Like @Anko suggested, you should use a graph as data structure for your game map. If you use the this implementation of a graph in Java as a starting point you can represent your map as follows:

Graph<Zone> gameMap = new Graph<>();

Zone zone1 = new Zone("Zone1");
Zone zone2 = new Zone("Zone2");
Zone zone3 = new Zone("Zone3");
Zone zone4 = new Zone("Zone4");
Zone zone5 = new Zone("Zone5");
Zone zone6 = new Zone("Zone6");
Zone zone7 = new Zone("Zone7");
Zone zone8 = new Zone("Zone8");
Zone zone9 = new Zone("Zone9");
Zone zone10 = new Zone("Zone10");

gameMap.addEdge(zone1, zone2);
gameMap.addEdge(zone2, zone3);
gameMap.addEdge(zone2, zone4);

If you want to check if you can attack zone2 from zone1 you can just do

// can attack zone2 from zone1
gameMap.hasEdge(zone1, zone2);

Here you can find the complete implementation of the above example.

Like @Anko suggested, you should use a graph as data structure for your game map. If you use the this implementation of a graph in Java as a starting point you can represent your map as follows:

Graph<Zone> gameMap = new Graph<>();

Zone zone1 = new Zone("Zone1");
Zone zone2 = new Zone("Zone2");
Zone zone3 = new Zone("Zone3");
Zone zone4 = new Zone("Zone4");
Zone zone5 = new Zone("Zone5");
Zone zone6 = new Zone("Zone6");
Zone zone7 = new Zone("Zone7");
Zone zone8 = new Zone("Zone8");
Zone zone9 = new Zone("Zone9");
Zone zone10 = new Zone("Zone10");

gameMap.addEdge(zone1, zone2);
gameMap.addEdge(zone2, zone3);
gameMap.addEdge(zone2, zone4);

If you want to check if you can attack zone2 from zone1 you can just do

// can attack zone2 from zone1
gameMap.hasEdge(zone1, zone2);

Edit: I reimplemented the Java version in Javascript. You can use it like the Java version.

Here you can find the complete implementation of the above example in Java and Javascript.

added 116 characters in body
Source Link
tryzor
  • 156
  • 2

Like @Anko suggested, you should use a graph as data structure for your game map. If you use the this implementation of a graph in Java as a starting point you can represent your map as follows:

Graph<Zone> gameMap = new Graph<>();

Zone zone1 = new Zone("Zone1");
Zone zone2 = new Zone("Zone2");
Zone zone3 = new Zone("Zone3");
Zone zone4 = new Zone("Zone4");
Zone zone5 = new Zone("Zone5");
Zone zone6 = new Zone("Zone6");
Zone zone7 = new Zone("Zone7");
Zone zone8 = new Zone("Zone8");
Zone zone9 = new Zone("Zone9");
Zone zone10 = new Zone("Zone10");

gameMap.addEdge(zone1, zone2);
gameMap.addEdge(zone2, zone3);
gameMap.addEdge(zone2, zone4);

If you want to check if you can attack zone2 from zone1 you can just do

// can attack zone2 from zone1
gameMap.hasEdge(zone1, zone2);

Here you can find the complete implementation of the above example.

Like @Anko suggested, you should use a graph as data structure for your game map. If you use the this implementation of a graph in Java as a starting point you can represent your map as follows:

Graph<Zone> gameMap = new Graph<>();

Zone zone1 = new Zone("Zone1");
Zone zone2 = new Zone("Zone2");
Zone zone3 = new Zone("Zone3");
Zone zone4 = new Zone("Zone4");
Zone zone5 = new Zone("Zone5");
Zone zone6 = new Zone("Zone6");
Zone zone7 = new Zone("Zone7");
Zone zone8 = new Zone("Zone8");
Zone zone9 = new Zone("Zone9");
Zone zone10 = new Zone("Zone10");

gameMap.addEdge(zone1, zone2);
gameMap.addEdge(zone2, zone3);
gameMap.addEdge(zone2, zone4);

If you want to check if you can attack zone2 from zone1 you can just do

// can attack zone2 from zone1
gameMap.hasEdge(zone1, zone2);

Like @Anko suggested, you should use a graph as data structure for your game map. If you use the this implementation of a graph in Java as a starting point you can represent your map as follows:

Graph<Zone> gameMap = new Graph<>();

Zone zone1 = new Zone("Zone1");
Zone zone2 = new Zone("Zone2");
Zone zone3 = new Zone("Zone3");
Zone zone4 = new Zone("Zone4");
Zone zone5 = new Zone("Zone5");
Zone zone6 = new Zone("Zone6");
Zone zone7 = new Zone("Zone7");
Zone zone8 = new Zone("Zone8");
Zone zone9 = new Zone("Zone9");
Zone zone10 = new Zone("Zone10");

gameMap.addEdge(zone1, zone2);
gameMap.addEdge(zone2, zone3);
gameMap.addEdge(zone2, zone4);

If you want to check if you can attack zone2 from zone1 you can just do

// can attack zone2 from zone1
gameMap.hasEdge(zone1, zone2);

Here you can find the complete implementation of the above example.

Source Link
tryzor
  • 156
  • 2

Like @Anko suggested, you should use a graph as data structure for your game map. If you use the this implementation of a graph in Java as a starting point you can represent your map as follows:

Graph<Zone> gameMap = new Graph<>();

Zone zone1 = new Zone("Zone1");
Zone zone2 = new Zone("Zone2");
Zone zone3 = new Zone("Zone3");
Zone zone4 = new Zone("Zone4");
Zone zone5 = new Zone("Zone5");
Zone zone6 = new Zone("Zone6");
Zone zone7 = new Zone("Zone7");
Zone zone8 = new Zone("Zone8");
Zone zone9 = new Zone("Zone9");
Zone zone10 = new Zone("Zone10");

gameMap.addEdge(zone1, zone2);
gameMap.addEdge(zone2, zone3);
gameMap.addEdge(zone2, zone4);

If you want to check if you can attack zone2 from zone1 you can just do

// can attack zone2 from zone1
gameMap.hasEdge(zone1, zone2);