开发者

Need algorithm to set the pieces on my game board in Java

I'm building a game (maybe someone knows it, its name is "Hexxagon").

I am currently building the board with the 61 pieces. The shape is hexagonal, so I can't put the pieces in a simple orthogonal matrix. I need to put each piece into its own position (x,y) on the board.

The problem is that I do not want to write 61 times the individual positions. I need a sorting algorithm that will put the images (copies of the hexagonal image) on the panel.

I write the game in Java.

开发者_StackOverflow

The pieces need to look like this.


Whoa, I remember this game. You might want to take a look at Coordinates in Hexagon-Based Tile Maps or Hex Coordinate Systems to help you get started. You're almost certainly going to want to have an object that represents each piece. In it you would store the position, references to adjacent pieces and the current state.

Somewhere in the beginning you're still going to have to construct what pieces belong where on the board, since this game has a specific layout. You can probably store this in some array to represent the board. Then at startup you'll interpret it to construct the objects with the right coordinates and associates. Then to draw it each frame you can just iterate over those objects. E.g. the array could look something like this:

String[] board = new String[] {
        "    X    ",
        "   X X   ",
        "  X X X  ",
        " X X X X ",
        "X X X X X",
        " X X X X ",
        "X X   X X",
        " X X X X ",
        "X X X X X",
        " X     X ",
        "X X X X X",
        " X X X X ",
        "X X X X X",
        " X X X X ",
        "  X X X  ",
        "   X X   ",
        "    X    "
};

Parsing that will be interesting :) Good luck!


You might want to check at Processing i used it to make a board with shapes like that for a project.Its easier to work on graphics with that and it works with java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜