private void CreatePlane(PlaneCoordinates planeCoordinates, Brush planeColor, bool preview, Direction direction)
        {
            CustomButton headBtn = GetButtonById(planeCoordinates.HeadId);

            if (headBtn != null)
            {
                headBtn.Background    = planeColor;
                headBtn.IsHead        = true;
                headBtn.HeadDirection = direction;

                CustomButton cellCenterFrontBtn = GetButtonById(planeCoordinates.CellCenterFrontId);
                cellCenterFrontBtn.Background = planeColor;

                CustomButton cellLeftFrontWingBtn = GetButtonById(planeCoordinates.CellLeftFrontWingId);
                cellLeftFrontWingBtn.Background = planeColor;

                CustomButton cellRightFrontWingBtn = GetButtonById(planeCoordinates.CellRightFrontWingId);
                cellRightFrontWingBtn.Background = planeColor;

                CustomButton cellCenterMiddleBtn = GetButtonById(planeCoordinates.CellCenterMiddleId);
                cellCenterMiddleBtn.Background = planeColor;

                CustomButton cellCenterBackBtn = GetButtonById(planeCoordinates.CellCenterBackId);
                cellCenterBackBtn.Background = planeColor;

                CustomButton cellLeftBackWingBtn = GetButtonById(planeCoordinates.CellLeftBackWingId);
                cellLeftBackWingBtn.Background = planeColor;

                CustomButton cellRightBackWingBtn = GetButtonById(planeCoordinates.CellRightBackWingId);
                cellRightBackWingBtn.Background = planeColor;

                if (!preview)
                {
                    headBtn.IsSelected =
                        cellCenterFrontBtn.IsSelected                           =
                            cellLeftFrontWingBtn.IsSelected                     =
                                cellRightFrontWingBtn.IsSelected                =
                                    cellCenterMiddleBtn.IsSelected              =
                                        cellCenterBackBtn.IsSelected            =
                                            cellLeftBackWingBtn.IsSelected      =
                                                cellRightBackWingBtn.IsSelected = true;
                }
                else
                {
                    headBtn.IsSelected =
                        cellCenterFrontBtn.IsSelected                           =
                            cellLeftFrontWingBtn.IsSelected                     =
                                cellRightFrontWingBtn.IsSelected                =
                                    cellCenterMiddleBtn.IsSelected              =
                                        cellCenterBackBtn.IsSelected            =
                                            cellLeftBackWingBtn.IsSelected      =
                                                cellRightBackWingBtn.IsSelected = false;
                }
            }
        }
        private PlaneCoordinates GetHeadUpPlaneCoord(int headId)
        {
            PlaneCoordinates pCoord = new PlaneCoordinates();

            pCoord.HeadId               = headId;
            pCoord.CellCenterFrontId    = pCoord.HeadId + 10;
            pCoord.CellLeftFrontWingId  = pCoord.CellCenterFrontId - 1;
            pCoord.CellRightFrontWingId = pCoord.CellCenterFrontId + 1;
            pCoord.CellCenterMiddleId   = pCoord.CellCenterFrontId + 10;
            pCoord.CellCenterBackId     = pCoord.CellCenterMiddleId + 10;
            pCoord.CellLeftBackWingId   = pCoord.CellCenterBackId - 1;
            pCoord.CellRightBackWingId  = pCoord.CellCenterBackId + 1;
            return(pCoord);
        }
        private bool InvalidCoordonateFound(PlaneCoordinates planeCoordinates)
        {
            CustomButton headBtn               = GetButtonById(planeCoordinates.HeadId);
            CustomButton cellCenterFrontBtn    = GetButtonById(planeCoordinates.CellCenterFrontId);
            CustomButton cellLeftFrontWingBtn  = GetButtonById(planeCoordinates.CellLeftFrontWingId);
            CustomButton cellRightFrontWingBtn = GetButtonById(planeCoordinates.CellRightFrontWingId);
            CustomButton cellCenterMiddleBtn   = GetButtonById(planeCoordinates.CellCenterMiddleId);
            CustomButton cellCenterBackBtn     = GetButtonById(planeCoordinates.CellCenterBackId);
            CustomButton cellLeftBackWingBtn   = GetButtonById(planeCoordinates.CellLeftBackWingId);
            CustomButton cellRightBackWingBtn  = GetButtonById(planeCoordinates.CellRightBackWingId);

            if (headBtn.IsSelected == true ||
                cellCenterFrontBtn.IsSelected == true ||
                cellLeftFrontWingBtn.IsSelected == true ||
                cellRightFrontWingBtn.IsSelected == true ||
                cellCenterMiddleBtn.IsSelected == true ||
                cellCenterBackBtn.IsSelected == true ||
                cellLeftBackWingBtn.IsSelected == true ||
                cellRightBackWingBtn.IsSelected == true)
            {
                return(true);
            }
            return(false);
        }
        private void DrawPlane(Direction planeDirection, int headId, bool preview, Brush planeColor)
        {
            try
            {
                switch (planeDirection)
                {
                case Direction.Up:
                    PlaneCoordinates headUpCoord = GetHeadUpPlaneCoord(headId);
                    if (!InvalidCoordonateFound(headUpCoord))
                    {
                        CreatePlane(headUpCoord, planeColor, preview, Direction.Up);
                        if (planeColor == Brushes.Yellow)
                        {
                            NumberOfAddedPlanes++;
                        }
                        if (NumberOfAddedPlanes == 3 && planeColor == Brushes.Yellow)
                        {
                            SendMessage(new MessageWrapper()
                            {
                                PlanesReady = true
                            }, true);
                        }
                    }
                    break;

                case Direction.Down:
                    PlaneCoordinates headDownCoord = GetHeadDownPlaneCoord(headId);
                    if (!InvalidCoordonateFound(headDownCoord))
                    {
                        CreatePlane(headDownCoord, planeColor, preview, Direction.Down);
                        if (planeColor == Brushes.Yellow)
                        {
                            NumberOfAddedPlanes++;
                        }
                        if (NumberOfAddedPlanes == 3 && planeColor == Brushes.Yellow)
                        {
                            SendMessage(new MessageWrapper()
                            {
                                PlanesReady = true
                            }, true);
                        }
                    }
                    break;

                case Direction.Left:
                    PlaneCoordinates headLeftCoord = GetHeadLeftPlaneCoord(headId);
                    if (!InvalidCoordonateFound(headLeftCoord))
                    {
                        CreatePlane(headLeftCoord, planeColor, preview, Direction.Left);
                        if (planeColor == Brushes.Yellow)
                        {
                            NumberOfAddedPlanes++;
                        }
                        if (NumberOfAddedPlanes == 3 && planeColor == Brushes.Yellow)
                        {
                            SendMessage(new MessageWrapper()
                            {
                                PlanesReady = true
                            }, true);
                        }
                    }
                    break;

                case Direction.Right:
                    PlaneCoordinates headRightCoord = GetHeadRightPlaneCoord(headId);
                    if (!InvalidCoordonateFound(headRightCoord))
                    {
                        CreatePlane(headRightCoord, planeColor, preview, Direction.Right);
                        if (planeColor == Brushes.Yellow)
                        {
                            NumberOfAddedPlanes++;
                        }
                        if (NumberOfAddedPlanes == 3)
                        {
                            SendMessage(new MessageWrapper()
                            {
                                PlanesReady = true
                            }, true);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception)
            {
            }
        }