Beispiel #1
0
 /// <summary>
 /// Returns the hash code for this instance.
 /// </summary>
 /// <returns>
 /// A 32-bit signed integer that is the hash code for this instance.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override int GetHashCode()
 {
     unchecked
     {
         return((UpperLeft.GetHashCode() * 397) ^ LowerRight.GetHashCode());
     }
 }
Beispiel #2
0
        /// <summary>
        /// Remove the square from the playing field.
        /// </summary>
        public void Remove()
        {
            // if we get here we can remove the square:
            SquareCompleted?.Invoke(this, EventArgs.Empty);

            UpperRight.RemoveCell();
            LowerRight.RemoveCell();
            UpperLeft.RemoveCell();
            LowerLeft.RemoveCell();
        }
Beispiel #3
0
 private void SetColorTheme(ColorTheme theme, bool force)
 {
     if (force || this.currentTheme != theme)
     {
         this.currentTheme = theme;
         UpperLeft.SetColorTheme(theme);
         UpperRight.SetColorTheme(theme);
         LowerLeft.SetColorTheme(theme);
         LowerRight.SetColorTheme(theme);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Returns a rectangle enclosing the corner points of the current instance, rotated
 /// by the specified amount.
 /// </summary>
 public RectangleD Rotate(Angle angle)
 {
     if (angle.IsEmpty)
     {
         return(this);
     }
     // Rotate each corner point
     PointD[] Points = new PointD[] { UpperLeft.RotateAt(angle, Center),
                                      UpperRight.RotateAt(angle, Center),
                                      LowerRight.RotateAt(angle, Center),
                                      LowerLeft.RotateAt(angle, Center) };
     // Now return the smallest rectangle which encloses these points
     return(RectangleD.FromArray(Points));
 }
Beispiel #5
0
        /// <summary>
        /// Returns a rectangle enclosing the corner points of the current instance, rotated
        /// by the specified amount around a specific point.
        /// </summary>
        /// <returns>A new <strong>RectangleD</strong> containing the rotated rectangle.</returns>
        /// <remarks><para>When a rectangle is rotated, the total width and height it occupies may be larger
        /// than the rectangle's own width and height.  This method calculates the smallest rectangle
        /// which encloses the rotated rectangle.</para>
        ///     <para>[TODO: Include before and after picture; this is confusing.]</para>
        /// </remarks>
        public RectangleD RotateAt(Angle _angle, PointD _center)
        {
            if (_angle.IsEmpty)
            {
                return(this);
            }
            // Rotate each corner point
            PointD[] points =
            {
                UpperLeft.RotateAt(_angle,  _center),
                UpperRight.RotateAt(_angle, _center),
                LowerRight.RotateAt(_angle, _center),
                LowerLeft.RotateAt(_angle,  _center)
            };

            // Now return the smallest rectangle which encloses these points
            return(FromArray(points));
        }
Beispiel #6
0
        private void DoResize()
        {
            //			int OldWidth=Horizontal.Width ;
            //			int OldHeight=Vertical.Height;
            int NewHeight = Height;
            int NewWidth  = Width;

            if (NewHeight != 0 && NewWidth != 0)
            {
                SuspendLayout();
                //				Horizontal.Top = (int)(NewHeight*HorizontalPos);
                //				Vertical.Left =(int)(NewWidth*VerticalPos);
                //
                //				int CenterY=(Horizontal.Top+Horizontal.Height /2)-Center.Height/2;
                //				int CenterX=(Vertical.Left+Vertical.Width /2)-Center.Width /2;
                //
                //				Center.Location =new Point (CenterX,CenterY);

                //ReSize (0,0);
                ReSize2();
                OnResizing();

                if (Horizontal.Top < 15)
                {
                    Horizontal.Top = 0 - Horizontal.Height;
                    OnHideTop();
                }

                if (Vertical.Left < 15)
                {
                    Vertical.Left = 0 - Vertical.Width;
                    OnHideLeft();
                }

                Horizontal.Width = Width;
                Vertical.Height  = Height;
                Horizontal.SendToBack();
                Vertical.SendToBack();
                Horizontal.BackColor = SystemColors.Control;
                Vertical.BackColor   = SystemColors.Control;

                //this.SendToBack ();
                int RightLeft     = Vertical.Left + Vertical.Width;
                int RightLowerTop = Horizontal.Top + Horizontal.Height;
                int RightWidth    = Width - RightLeft;
                int LowerHeight   = Height - RightLowerTop;
                int UpperHeight   = Horizontal.Top;
                int LeftWidth     = Vertical.Left;

                if (LowerRight != null)
                {
                    LowerRight.BringToFront();
                    LowerRight.SetBounds(RightLeft, RightLowerTop, RightWidth, LowerHeight);
                }
                if (UpperRight != null)
                {
                    UpperRight.BringToFront();
                    UpperRight.SetBounds(RightLeft, 0, RightWidth, UpperHeight);
                }

                if (LowerLeft != null)
                {
                    LowerLeft.BringToFront();
                    LowerLeft.SetBounds(0, RightLowerTop, LeftWidth, LowerHeight);
                }
                if (UpperLeft != null)
                {
                    UpperLeft.BringToFront();
                    UpperLeft.SetBounds(0, 0, LeftWidth, UpperHeight);
                }
                ResumeLayout(); //ggf
            }
        }
Beispiel #7
0
        private void NewGameButton_Click(object sender, EventArgs e)
        {
            // ignore new game requests if the ai is running
            if (aiThinking)
            {
                return;
            }

            okToRotateQuadrant = false;
            okToClickDots      = false;

            UpperLeft.Reset();
            UpperRight.Reset();
            LowerLeft.Reset();
            LowerRight.Reset();

            PopupPanel.Visibility = System.Windows.Visibility.Collapsed;

            masterBoard = new Board();

            this.currentGameStyle = settings.GameStyleSetting;

            if (this.currentGameStyle == GameStyle.VsAi && settings.PlayerColorSetting == PieceColor.Black)
            {
                playerColor = PieceColor.Black;

                if (0 == settings.AiStrengthSetting)
                {
                    Debug.Assert(false, "Easy");
                    masterAI = new FixedDepthPlayer(PieceColor.White, 0);
                }
                else if (1 == settings.AiStrengthSetting)
                {
                    Debug.Assert(false, "Med");
                    masterAI = new FixedDepthPlayer(PieceColor.White, 2);
                }
                else
                {
                    Debug.Assert(false, "Hard");
                    masterAI = new FixedTimePlayer(PieceColor.White, 5);
                }

                aiThinking = true;
                DoAiMove();
            }
            else if (this.currentGameStyle == GameStyle.VsAi && settings.PlayerColorSetting == PieceColor.White)
            {
                playerColor = PieceColor.White;
                if (0 == settings.AiStrengthSetting)
                {
                    masterAI = new FixedDepthPlayer(PieceColor.Black, 0);
                }
                else if (1 == settings.AiStrengthSetting)
                {
                    masterAI = new FixedDepthPlayer(PieceColor.Black, 2);
                }
                else
                {
                    masterAI = new FixedTimePlayer(PieceColor.Black, 5);
                }
                okToClickDots      = true;
                okToRotateQuadrant = false;
                BottomText.Text    = "your move";
            }
            else if (this.currentGameStyle == GameStyle.VsHuman)
            {
                playerColor = PieceColor.White;

                okToClickDots      = true;
                okToRotateQuadrant = false;
                BottomText.Text    = "white's move";
            }
        }
Beispiel #8
0
        private void AnimateMove(Move move)
        {
            if (move.xCoord <= 2 &&
                move.yCoord <= 2)
            {
                LowerLeft.ShowDotPlacement(move.xCoord % 3, move.yCoord % 3, move.pieceColor);
            }
            else if (move.xCoord <= 2 &&
                     move.yCoord > 2)
            {
                UpperLeft.ShowDotPlacement(move.xCoord % 3, move.yCoord % 3, move.pieceColor);
            }
            else if (move.xCoord > 2 &&
                     move.yCoord <= 2)
            {
                LowerRight.ShowDotPlacement(move.xCoord % 3, move.yCoord % 3, move.pieceColor);
            }
            else if (move.xCoord > 2 &&
                     move.yCoord > 2)
            {
                UpperRight.ShowDotPlacement(move.xCoord % 3, move.yCoord % 3, move.pieceColor);
            }

            // System.Threading.Thread.Sleep(1000);
            UpperLeft.ClearValue(Canvas.ZIndexProperty);
            UpperRight.ClearValue(Canvas.ZIndexProperty);
            LowerLeft.ClearValue(Canvas.ZIndexProperty);
            LowerRight.ClearValue(Canvas.ZIndexProperty);

            switch (move.rotation)
            {
            case Rotation.UpperLeftClockwise:
                UpperLeft.SetValue(Canvas.ZIndexProperty, 9);
                UpperLeft.ShowTwist(TwistDirection.Clockwise);
                break;

            case Rotation.UpperLeftAntiClockwise:
                UpperLeft.SetValue(Canvas.ZIndexProperty, 9);
                UpperLeft.ShowTwist(TwistDirection.AntiClockwise);
                break;

            case Rotation.UpperRightClockwise:
                UpperRight.SetValue(Canvas.ZIndexProperty, 9);
                UpperRight.ShowTwist(TwistDirection.Clockwise);
                break;

            case Rotation.UpperRightAntiClockwise:
                UpperRight.SetValue(Canvas.ZIndexProperty, 9);
                UpperRight.ShowTwist(TwistDirection.AntiClockwise);
                break;

            case Rotation.LowerLeftClockwise:
                LowerLeft.SetValue(Canvas.ZIndexProperty, 9);
                LowerLeft.ShowTwist(TwistDirection.Clockwise);
                break;

            case Rotation.LowerLeftAntiClockwise:
                LowerLeft.SetValue(Canvas.ZIndexProperty, 9);
                LowerLeft.ShowTwist(TwistDirection.AntiClockwise);
                break;

            case Rotation.LowerRightClockwise:
                LowerRight.SetValue(Canvas.ZIndexProperty, 9);
                LowerRight.ShowTwist(TwistDirection.Clockwise);
                break;

            case Rotation.LowerRightAntiClockwise:
                LowerRight.SetValue(Canvas.ZIndexProperty, 9);
                LowerRight.ShowTwist(TwistDirection.AntiClockwise);
                break;

            default:
                break;
            }
        }
Beispiel #9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // ignore new game requests if the ai is running
            if (aiThinking)
            {
                return;
            }

            HowTo.Visibility     = Visibility.Collapsed;
            HowToText.Visibility = Visibility.Collapsed;

            okToRotateQuadrant = false;
            okToClickDots      = false;

            UpperLeft.Reset();
            UpperRight.Reset();
            LowerLeft.Reset();
            LowerRight.Reset();

            masterBoard = new Board();

            if ((bool)playerBlackRadioButton.IsChecked)
            {
                playerColor = PieceColor.Black;

                if ((bool)aiEasyRadioButton.IsChecked)
                {
                    Debug.Assert(false, "Easy");
                    masterAI = new FixedDepthPlayer(PieceColor.White, 0);
                }
                else if ((bool)aiMediumRadioButton.IsChecked)
                {
                    Debug.Assert(false, "Med");
                    masterAI = new FixedDepthPlayer(PieceColor.White, 2);
                }
                else
                {
                    Debug.Assert(false, "Hard");
                    masterAI = new FixedTimePlayer(PieceColor.White, 5);
                }

                aiThinking = true;
                DoAiMove();
            }
            else
            {
                playerColor = PieceColor.White;
                if ((bool)aiEasyRadioButton.IsChecked)
                {
                    masterAI = new FixedDepthPlayer(PieceColor.Black, 0);
                }
                else if ((bool)aiMediumRadioButton.IsChecked)
                {
                    masterAI = new FixedDepthPlayer(PieceColor.Black, 2);
                }
                else
                {
                    masterAI = new FixedTimePlayer(PieceColor.Black, 5);
                }
                okToClickDots      = true;
                okToRotateQuadrant = false;
                BottomText.Text    = "Your move";
            }
        }