コード例 #1
0
        public bool AddDoubleEdgedPipe(Coordinate position, EdgeType firstEdge, EdgeType secondEdge)
        {
            var pipe  = new DoubleEdgedPipe(firstEdge, secondEdge);
            var block = GetBlock(position);

            if (block != null)
            {
                if (!CheckIfDoubleEdgeAlreadyExists(pipe, block))
                {
                    if (!(block.HasShipComponent()))
                    {
                        var intersectingPipe = HasIntersectingPipes(block, pipe);
                        if (intersectingPipe != null)
                        {
                            blueprint.PlaceShipComponent(position, emptyShipComponentFactory.Create(block));
                            TransformDoubleEdgedPipeIntoConnectingPipe(position, intersectingPipe);
                            TransformDoubleEdgedPipeIntoConnectingPipe(position, pipe);
                            ClearPipes(position, block.PipesWithBothEdges);
                        }
                        else
                        {
                            blueprint.PlacePipe(position, pipe);
                        }
                        return(true);
                    }
                    else
                    {
                        TransformDoubleEdgedPipeIntoConnectingPipe(position, pipe);
                        return(true);
                    }
                }
                return(false);
            }
            return(false);
        }
コード例 #2
0
        public bool DeleteDoubleEdgedPipe(Coordinate position, DoubleEdgedPipe pipe)
        {
            var block = GetBlock(position);

            if (block != null)
            {
                if (CheckIfDoubleEdgeAlreadyExists(pipe, block))
                {
                    var p = GetDoubleEdgedPipe(pipe, block);
                    blueprint.RemovePipe(position, p);
                    return(true);
                }

                if (CheckIfDoubleEdgedPipeCanBeComposedOfTwoConnectingPipes(pipe, block))
                {
                    var list = GetConnectingPipesThatComposeTwoEdgedPipe(pipe, block);
                    foreach (var p in list)
                    {
                        blueprint.RemovePipe(position, p);
                    }
                    return(true);
                }
            }
            return(false);
        }
コード例 #3
0
        public void PlacePipe(Coordinate position, DoubleEdgedPipe pipe)
        {
            blocks.Get(position).AddPipe(pipe);

            foreach (var observer in observers)
            {
                observer.DoubleEdgePipeAdded(this, position, pipe);
            }
        }
コード例 #4
0
        public void RemovePipe(Coordinate position, DoubleEdgedPipe pipe)
        {
            blocks.Get(position).DeletePipe(pipe);

            foreach (var observer in observers)
            {
                observer.DoubleEdgePipeDeleted(this, position, pipe);
            }
        }
コード例 #5
0
        private DoubleEdgedPipe GetDoubleEdgedPipe(DoubleEdgedPipe pipe, IConstBlock block)
        {
            foreach (var p in block.PipesWithBothEdges)
            {
                if (p.IsEqualTo(pipe))
                {
                    return(p);
                }
            }

            return(null);
        }
コード例 #6
0
        private List <ConnectingPipe> GetConnectingPipesThatComposeTwoEdgedPipe(DoubleEdgedPipe pipe, IConstBlock block)
        {
            var list = new List <ConnectingPipe>();

            foreach (var connectingPipe in block.PipesWithOneEdge)
            {
                if (connectingPipe.Edge == pipe.FirstEdge || connectingPipe.Edge == pipe.SecondEdge)
                {
                    list.Add(connectingPipe);
                }
            }

            return(list);
        }
コード例 #7
0
        private bool DoPipesIntersect(DoubleEdgedPipe pipe1, DoubleEdgedPipe pipe2)
        {
            if ((pipe1.FirstEdge == EdgeType.UP && pipe1.SecondEdge == EdgeType.DOWN) || (pipe1.FirstEdge == EdgeType.DOWN && pipe1.SecondEdge == EdgeType.UP))
            {
                if ((pipe2.FirstEdge == EdgeType.LEFT && pipe2.SecondEdge == EdgeType.RIGHT) || (pipe2.FirstEdge == EdgeType.RIGHT && pipe2.SecondEdge == EdgeType.LEFT))
                {
                    return(true);
                }
            }

            if ((pipe1.FirstEdge == EdgeType.LEFT && pipe1.SecondEdge == EdgeType.RIGHT) || (pipe1.FirstEdge == EdgeType.RIGHT && pipe1.SecondEdge == EdgeType.LEFT))
            {
                if ((pipe2.FirstEdge == EdgeType.UP && pipe2.SecondEdge == EdgeType.DOWN) || (pipe2.FirstEdge == EdgeType.DOWN && pipe2.SecondEdge == EdgeType.UP))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #8
0
 private bool CheckIfDoubleEdgedPipeCanBeComposedOfTwoConnectingPipes(DoubleEdgedPipe pipe, IConstBlock block)
 {
     return(block.PipesWithOneEdge.Select(p => p.Edge).ToList().Any(p => p == pipe.FirstEdge) &&
            block.PipesWithOneEdge.Select(p => p.Edge).ToList().Any(p => p == pipe.SecondEdge));
 }
コード例 #9
0
 private bool CheckIfDoubleEdgeAlreadyExists(DoubleEdgedPipe pipe, IConstBlock block)
 {
     return(block.PipesWithBothEdges.Any(p => p.IsEqualTo(pipe)));
 }
コード例 #10
0
 private void TransformDoubleEdgedPipeIntoConnectingPipe(Coordinate position, DoubleEdgedPipe pipe)
 {
     AddConnectingPipe(position, pipe.FirstEdge);
     AddConnectingPipe(position, pipe.SecondEdge);
 }
コード例 #11
0
 private DoubleEdgedPipe HasIntersectingPipes(IConstBlock block, DoubleEdgedPipe pipeToCheck)
 {
     return(block.PipesWithBothEdges.FirstOrDefault(pipe => DoPipesIntersect(pipe, pipeToCheck)));
 }
コード例 #12
0
ファイル: Block.cs プロジェクト: andreea-florea/SpaceOddity
 public void DeletePipe(DoubleEdgedPipe pipe)
 {
     pipesWithBothEdges.Remove(pipe);
 }
コード例 #13
0
ファイル: Block.cs プロジェクト: andreea-florea/SpaceOddity
 public void AddPipe(DoubleEdgedPipe pipe)
 {
     pipesWithBothEdges.Add(pipe);
 }
コード例 #14
0
 public bool IsEqualTo(DoubleEdgedPipe pipe)
 {
     return((FirstEdge == pipe.FirstEdge && SecondEdge == pipe.SecondEdge) ||
            (FirstEdge == pipe.SecondEdge && SecondEdge == pipe.FirstEdge));
 }