3

im creating a boardgame, with a hexagon shaped tilebased map. i used konva to create the hexagons/polygons. the way i went about it was to just create a variable for each polygon, but this ended up as a 1000+ lines of code (as the map has about 50 hexagontiles) so im wondering if there is a more efficient way since its hard to keep track of so many lines of code.

this is how 1 polygon looks. (im intending to place a sprite, where the player will be able to move the sprite such as in chess, moving from one tile to another by clicking the mouse etc.)

var polyA = new Konva.RegularPolygon({
  x: 600,
  y: 400,
  sides: 6,
  radius: 400,
  rotation: 90,
  stroke: "black",
  strokeWidth: 5
});

and here is the code for loading the tiles. as you can see its very long.

board.add(polyA, polyB, polyC, polyD, polyE, polyF, polyG, polyCr, polyDr, polyEr, polyFr, polyGr, polyA1, polyB1, polyC1, polyD1, polyE1, polyF1, polyCr1, polyDr1, polyEr1, polyFr1, polyGr1, polyB2, polyC2, polyD2, polyE2, polyF2, polyG2, polyCr2, polyDr2, polyEr2, polyB3, polyC3, polyD3, polyE3, polyCr3, polyDr3, polyEr3, polyFr3, polyB4, polyC4, polyD4, polyE4, polyCr4, polyDr4, polyEr4, polyB5, polyC5, polyD5, polyCr5, polyDr5, polyEr5, polyB1u, polyC1u, polyD1u, polyE1u, polyF1u, polyCr1u, polyDr1u, polyEr1u, polyFr1u, polyGr1u, polyB2u, polyC2u, polyD2u, polyE2u, polyF2u, polyG2u, polyCr2u, polyDr2u, polyEr2u, polyB3u, polyC3u, polyD3u, polyE3u, polyCr3u, polyDr3u, polyEr3u, polyFr3u, polyB4u, polyC4u, polyD4u, polyE4u, polyCr4u, polyDr4u, polyEr4u, polyB5u, polyC5u, polyD5u, polyCr5u, polyDr5u, polyEr5u);

stage.add(board);
j a
  • 41
  • 7
  • I think this will do better in https://codereview.stackexchange.com/. More of a refactoring issue than an actual bug/unexpected behaviour etc – L_Church May 03 '18 at 09:05
  • thanks, i have to wait 40 minutes to post again :( but ill post it there. – j a May 03 '18 at 09:07
  • I'll upvote this so you'll get more rep. Good luck and happy coding. Maybe you'll get a response here who knows ^^ – L_Church May 03 '18 at 09:17

0 Answers0