Ejemplo n.º 1
0
 private IBasicPolygon GetCell(Point3d coordinates)
 {
     return Game.Board.Cells.Where(c => c.Coordintes.X == coordinates.X &&
                                             c.Coordintes.Y == coordinates.Y &&
                                             c.Coordintes.Z == coordinates.Z)
                                             .FirstOrDefault();
 }
Ejemplo n.º 2
0
        private void CheckCellExists(Point3d coordinates)
        {
            var cell = GetCell(coordinates);

            if (cell == null)
            {
                throw new InvalidOperationException("Cell with coordinates {coordinates} not found.");
            }
        }
Ejemplo n.º 3
0
 private IBasicPolygon GetMiddleCell(Point3d from, Point3d to)
 {
     return GetCell(new Point3d() { X = (from.X + to.X) / 2, Y = (from.Y + to.Y) / 2, Z = (from.Z + to.Z) / 2 });
 }
Ejemplo n.º 4
0
 private void CheckMoveCoordiantes(Point3d from, Point3d to)
 {
     CheckCellExists(from);
     CheckCellExists(to);
     CheckTargetCellIsSolid(to);
     CheckCoordiantes(from, to);
     CheckMoveState(from, to);
 }
Ejemplo n.º 5
0
        private void CheckMoveState(Point3d from, Point3d to)
        {
            var cellFrom = GetCell(from);
            var cellTo = GetCell(to);

            var middleCell = GetMiddleCell(from, to);

            if (middleCell == null ||
                middleCell.State != PolygonState.Filled ||
                cellFrom.State != PolygonState.Filled ||
                cellTo.State != PolygonState.Empty)
            {
                throw new InvalidOperationException(string.Format("Can't move from {0}.", from));
            }
        }
Ejemplo n.º 6
0
        private void CheckCoordiantes(Point3d from, Point3d to)
        {
            var xDiff = Math.Abs(from.X - to.X);
            var yDiff = Math.Abs(from.Y - to.Y);

            if ((xDiff == 2 && yDiff == 0) || (yDiff == 2 && xDiff == 0))
            {
                return;
            }
            else
            {
                throw new InvalidOperationException(string.Format("Can't move {0} -> {1}.", from, to));
            }
        }
Ejemplo n.º 7
0
        private void CheckTargetCellIsSolid(Point3d coordinates)
        {
            var cell = GetCell(coordinates);

            if (cell.State == PolygonState.Solid)
            {
                throw new InvalidOperationException(string.Format("Cell with coordinates {0} is solid.", coordinates));
            }
        }