private string ComplexDeflectionImageSource(Position position)
 {
     string imgSrc = string.Empty;
     LightBoxDirection direction = Direction(position);
     switch (direction)
     {
         case LightBoxDirection.LightBoxLeft:
             imgSrc = "/icons/LightBox.ComplexDeflection.Right.png";
             break;
         case LightBoxDirection.LightBoxRight:
             imgSrc = "/icons/LightBox.ComplexDeflection.Left.png";
             break;
         case LightBoxDirection.LightBoxTop:
             imgSrc = "/icons/LightBox.ComplexDeflection.Bottom.png";
             break;
         case LightBoxDirection.LightBoxBottom:
             imgSrc = "/icons/LightBox.ComplexDeflection.Top.png";
             break;
         default:
             break;
     }
     return imgSrc;
 }
Esempio n. 2
0
        private BitmapImage ComplexDeflectionImageSource(Position position)
        {
            BitmapImage bitmapImage = null;

            switch (Direction(position))
            {
                case LightBoxDirection.LightBoxLeft:
                    bitmapImage = BlackboxImageUtils.Image(BlackboxImageType.LightBoxComplexDeflectionRight);
                    break;
                case LightBoxDirection.LightBoxRight:
                    bitmapImage = BlackboxImageUtils.Image(BlackboxImageType.LightBoxComplexDeflectionLeft);
                    break;
                case LightBoxDirection.LightBoxTop:
                    bitmapImage = BlackboxImageUtils.Image(BlackboxImageType.LightBoxComplexDeflectionTop);
                    break;
                case LightBoxDirection.LightBoxBottom:
                    bitmapImage = BlackboxImageUtils.Image(BlackboxImageType.LightBoxComplexDeflectionBottom);
                    break;
                default:
                    break;
            }

            return bitmapImage;
        }
 private LightBoxDirection Direction(Position position)
 {
     LightBoxDirection direction = LightBoxDirection.LightBoxLeft;
     if (position.Row == 0)
     {
         direction = LightBoxDirection.LightBoxLeft;
     }
     else if (position.Column == 0)
     {
         direction = LightBoxDirection.LightBoxTop;
     }
     else if (position.Row == BlackboxConfig.GameBoardRow - 1)
     {
         direction = LightBoxDirection.LightBoxRight;
     }
     else
     {
         direction = LightBoxDirection.LightBoxBottom;
     }
     return direction;
 }
Esempio n. 4
0
        bool SlopeTest( Direction dir, Position pos )
        {
            bool ret = false;

            switch (dir)
                {
                case Direction.DirTop:
                    {
                    if ( _lightBox.Helper.HasMirror( pos.Row - 1, pos.Column - 1 )
                        || _lightBox.Helper.HasMirror(pos.Row + 1, pos.Column - 1))
                        {
                            ret = true;
                        }
                    break;
                    }
                case Direction.DirBottom:
                    {
                    if ( _lightBox.Helper.HasMirror( pos.Row - 1, pos.Column + 1 )
                        || _lightBox.Helper.HasMirror( pos.Row + 1, pos.Column + 1 ) )
                        {
                            ret = true;
                        }
                    break;
                    }
                case Direction.DirLeft:
                    {
                    if ( _lightBox.Helper.HasMirror( pos.Row - 1, pos.Column - 1 )
                        || _lightBox.Helper.HasMirror( pos.Row - 1, pos.Column + 1 ) )
                        {
                            ret = true;
                        }
                    break;
                    }
                case Direction.DirRight:
                    {
                    if ( _lightBox.Helper.HasMirror( pos.Row + 1, pos.Column - 1 )
                        || _lightBox.Helper.HasMirror( pos.Row + 1, pos.Column + 1 ) )
                        {
                            ret = true;
                        }
                    break;
                    }
                case Direction.DirTopLeft:
                case Direction.DirTopRight:
                case Direction.DirBottomLeft:
                case Direction.DirBottomRight:
                case Direction.DirCenter:
                default:
                    break;
                }
            return ret;
        }
Esempio n. 5
0
        Point SendOutPosition( Direction dir, Position position )
        {
            Point pos = new Point();
            Rect rect = _lightBox.Helper.BoxRect(position.Row, position.Column);
            switch (dir)
            {
                case Direction.DirTop:
                    pos.X = rect.X + rect.Width / 2;
                    pos.Y = rect.Y;
                    break;
                case Direction.DirBottom:
                    pos.X = rect.X + rect.Width / 2;
                    pos.Y = rect.Y + rect.Height;
                    break;
                case Direction.DirLeft:
                    pos.X = rect.X;
                    pos.Y = rect.Y + rect.Height / 2;
                    break;
                case Direction.DirRight:
                    pos.X = rect.X + rect.Width;
                    pos.Y = rect.Y + rect.Height / 2;
                    break;
                case Direction.DirCenter:
                    pos.X = rect.X + rect.Width / 2;
                    pos.Y = rect.Y + rect.Height / 2;
                    break;

                case Direction.DirTopLeft:
                case Direction.DirTopRight:
                case Direction.DirBottomLeft:
                case Direction.DirBottomRight:
                default:
                    break;
            }
            return pos;
        }
Esempio n. 6
0
        Direction ReflectionDirection( Line line, Position mirrorPos )
        {
            Direction direction = line.Dir();
            Rect rect = _lightBox.Helper.BoxRect(mirrorPos.Row, mirrorPos.Column);
            Point mirrorPoint = new Point();
            mirrorPoint.X = rect.X + rect.Width / 2;
            mirrorPoint.Y = rect.Y + rect.Height / 2;

            if (line.To.X < mirrorPoint.X && line.To.Y > mirrorPoint.Y) // top right
            {
                if (direction == Direction.DirRight)
                {
                    direction = Direction.DirBottom;
                }
                if (direction == Direction.DirTop)
                {
                    direction = Direction.DirLeft;
                }
            }
            else if (line.To.X < mirrorPoint.X && line.To.Y < mirrorPoint.Y) // bottom right
            {
                if (direction == Direction.DirRight)
                {
                    direction = Direction.DirTop;
                }
                if (direction == Direction.DirBottom)
                {
                    direction = Direction.DirLeft;
                }
            }
            else if (line.To.X > mirrorPoint.X && line.To.Y > mirrorPoint.Y) // top left
            {
                if (direction == Direction.DirLeft)
                {
                    direction = Direction.DirBottom;
                }
                if (direction == Direction.DirTop)
                {
                    direction = Direction.DirRight;
                }
            }
            else if (line.To.X > mirrorPoint.X && line.To.Y < mirrorPoint.Y) // bottom left
            {
                if (direction == Direction.DirLeft)
                {
                    direction = Direction.DirTop;
                }
                if (direction == Direction.DirBottom)
                {
                    direction = Direction.DirRight;
                }
            }
            else
            {
                direction = Direction.DirCenter;
            }
            return direction;
        }
Esempio n. 7
0
 bool LightboxTest( Position pos )
 {
     if ( pos.Row == 0
         || pos.Column == 0
         || pos.Row == BlackboxConfig.GameBoardRow - 1
         || pos.Column == BlackboxConfig.GameBoardColumn - 1 )
         {
         return true;
         }
     return false;
 }
Esempio n. 8
0
 void GetNearestMirror( out List<Position> mirrorList, Position pos )
 {
     mirrorList = new List<Position>();
     for ( int i = pos.Row - 1; i <= pos.Row + 1; i++ )
         for ( int j = pos.Column - 1; j <= pos.Column + 1; j++ )
             {
             if ( _lightBox.Helper.HasMirror( i, j ) )
                 {
                 mirrorList.Add( new Position( i, j ) );
                 }
             }
 }
Esempio n. 9
0
 private void Forward( Direction dir, ref Position position )
 {
     switch ( dir )
         {
         case Direction.DirTop:
             position.Column -= 1;
             break;
         case Direction.DirBottom:
             position.Column += 1;
             break;
         case Direction.DirLeft:
             position.Row -= 1;
             break;
         case Direction.DirRight:
             position.Row += 1;
             break;
         case Direction.DirTopLeft:
             position.Row -= 1;
             position.Column -= 1;
             break;
         case Direction.DirTopRight:
             position.Row += 1;
             position.Column -= 1;
             break;
         case Direction.DirBottomLeft:
             position.Row -= 1;
             position.Column += 1;
             break;
         case Direction.DirBottomRight:
             position.Row += 1;
             position.Column += 1;
             break;
         case Direction.DirCenter:
         default:
             break;
         }
 }
Esempio n. 10
0
        private void BuildRays()
        {
            // Clears old lines
            _lineList.Clear();

            // Starts to build reays
            Direction direction;
            GetLightboxDirection(out direction);

            Position position = new Position(_lightBox.Position);
            Point start = SendOutPosition(direction, position);

            Line line = new Line();
            line.From = start;

            int state; // lightbox state

            while (true)
            {
                Forward(direction, ref position); // try to get the next position

                if (_lightBox.Helper.HasMirror(position.Row, position.Column))
                {
                    line.To = line.From;
                    _lineList.Add(new Line(line));
                    _lightBox.State = LightBox.ReflectionState;
                    break;
                }
                else if (NeighbourTest(direction, position))
                {
                    line.To = line.From;
                    _lineList.Add(new Line(line));
                    _lightBox.State = LightBox.ReflectionState;
                    break;
                }
                else if (FrontTest(direction, position))
                {
                    line.To = SendInPosition(direction, position); // ???
                    _lineList.Add(new Line(line));

                    if (_lineList.Count >= 2)
                    {
                        _lightBox.State = LightBox.ComplexReflectionState;
                    }
                    else
                    {
                        _lightBox.State = LightBox.ReflectionState;
                    }

                    break;
                }
                else if (SlopeTest(direction, position))
                {
                    line.To = SendInPosition(Direction.DirCenter, position);
                    _lineList.Add(new Line(line.From, line.To));

                    List<Position> array;
                    GetNearestMirror(out array, position);
                    if (array.Count > 1)
                    {
                        array.Clear();

                        if (_lineList.Count > 2)
                        {
                            _lightBox.State = LightBox.ComplexReflectionState;
                        }
                        else
                        {
                            _lightBox.State = LightBox.ReflectionState;
                        }

                        break;
                    }
                    else
                    {
                        direction = ReflectionDirection(line, array[0]);
                        array.Clear();
                        line.From = line.To;
                        continue;
                    }
                }
                else if (LightboxTest(position))
                {
                    line.To = SendInPosition(direction, position);
                    _lineList.Add(new Line(line));

                    if (_lineList.Count > 2)
                    {
                        state = LightBox.ComplexDeflectionState;
                    }
                    else
                    {
                        state = LightBox.DeflectionState;
                    }

                    if (position != _lightBox.Position)
                    {
                        _lightBox.State = state;
                        Box box = _lightBox.Helper.Box(position.Row, position.Column);
                        if (box!=null)
                        {
                            box.State = state + 2;
                            ((LightBox)box).Index = (_lightBox.Helper.RaysCount() + 1).ToString();
                            _lightBox.Index = (_lightBox.Helper.RaysCount() + 1).ToString();
                        }
                    }
                    break;
                }
                else
                {
                    continue;
                }
            }

            BuildMiniLanguage();
        }