Ejemplo n.º 1
0
        public GameLogic()
        {
            LineDirection newLine = null;

            //build all possible directions a line of linegth d cubes can be in a dxdxd board
            //check the 9 3d directions
            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    newLine = new LineDirection(i, j, 1);
                    possibleDirections[newLine.ID] = newLine;
                }
            }

            //the 4 2d directions

            //horizontal 2d check
            newLine = new LineDirection(1, 0, 0);
            possibleDirections[newLine.ID] = newLine;

            //vertical 2d check
            newLine = new LineDirection(0, 1, 0);
            possibleDirections[newLine.ID] = newLine;

            //diagonal 2d check
            newLine = new LineDirection(1, 1, 0);
            possibleDirections[newLine.ID] = newLine;

            //diagonal 2d check
            newLine = new LineDirection(1, -1, 0);
            possibleDirections[newLine.ID] = newLine;
        }
Ejemplo n.º 2
0
        private List <BoardPosition> GetLinePositions(BoardPosition move, LineDirection direction)
        {
            int posX = move.X;
            int posY = move.Y;
            int posZ = move.Z;

            List <BoardPosition> cellList = new List <BoardPosition>();

            while (posX >= 0 &&
                   posY >= 0 &&
                   posZ >= 0 &&
                   posX < dimension &&
                   posY < dimension &&
                   posZ < dimension
                   )
            {
                cellList.Add(gameMatrix[posX, posY, posZ]);
                posX += direction.dx;
                posY += direction.dy;
                posZ += direction.dz;
            }

            posX = move.X - direction.dx;
            posY = move.Y - direction.dy;
            posZ = move.Z - direction.dz;

            while (posX >= 0 &&
                   posY >= 0 &&
                   posZ >= 0 &&
                   posX < dimension &&
                   posY < dimension &&
                   posZ < dimension)
            {
                cellList.Add(gameMatrix[posX, posY, posZ]);
                posX -= direction.dx;
                posY -= direction.dy;
                posZ -= direction.dz;
            }

            return(cellList);
        }