Shape and representation of the movement of the hexagonal plane

The easiest way to represent a square plane (a bunch of squares) is to use a two-dimensional array.

In C #, we declare this as int[,]we can make our plane as large as we want:

string[3,3] => tic-tac-toe board (or similar)
string[8,8] => chess or checkers board

To “move” an element in the plane, we simply assign it a new “position”

//using our tic-tac-toe board:
string[0,0] = "x"; //top-left
string[1,1] = "o"; //middle-middle

//to move
string[0,1] = bN; //Black Knight starting positon
string[2,2] = bN; //Black Knight moves
string[0,1] = String.Empty;

So, how would you imagine the hexagonal plane (a bunch of hexagons) and how could you move the movement from one position to another?

Note. This is not purely theoretical, since I have an idea for a small game in my head that will require such a movement, but I can’t wrap my head around how this will be done. I looked through some other questions here, but can't find a good match ...

+5
2

, , , , , "", ( null ). , .

. , , .


: , alt text http://img833.imageshack.us/img833/4739/hexgame11x11.gif

[,] , , (Up Right is [+ 1, -1], Right is [+1,0 ], Down Right - [0, + 1], Down Left - [-1, + 1], Left - [-1,0], Up Left - [0, -1])

, , , , (X) X + Y * 2, (y) 0 Yy Xy X off .

:

const int X = 10;
const int Y = 10;
int grid[,] = new int[X+(2*Y), Y];

bool IsCellOffLimits(int x, int y)
{
    return (x < Y-y || x > X-y || y < 0 || y > Y);
}

, ​​ alt text http://img192.imageshack.us/img192/5580/gridw.png

©, , - Y-y X-y . .

+7

, /, /, / .

public class Player
{
    public int X { get; set; }
    public int Y { get; set; }

    public void MoveLeft() { X++; }
    public void MoveRight() { X--; }

    public void MoveUp() { Y++; }
    public void MoveDown() { Y--; }

    public void MoveFunny() { Y++; X++; }
    public void MoveOtherFunny() { Y--; X--; }
}
0

All Articles