示例#1
0
 internal void UserBoneGrid_MouseDown(object sender, MouseEventArgs e) // клик на своих костях
 {
     if (!IsTurnToMove || HasAlreadyMadeMove)
     {
         return;
     }
     Grid         grid = (Grid)sender;
     BoneGraphics bone = BonesRepository.UserZone.Bones[grid.Name.Length == 2 ? int.Parse($"{grid.Name[^1]}") : int.Parse($"{grid.Name[^2]}{grid.Name[^1]}")];
        internal override void AddBone(BoneGraphics bone, bool isAddAtEnd = true)
        {
            bool isTranspose = false;

            if (Bones.Count != 0)
            {
                if (isAddAtEnd)
                {
                    if (Bones[^ 1].PointsQty1 == bone.PointsQty1)
示例#3
0
 internal override void AddBone(BoneGraphics bone, bool isToEnd = true)
 {
     if (Bones.Count == 0)
     {
         RestGridHeight = ".8*";
     }
     bone.State = StateOfBone.ClosedVertical;
     bone.BoneGrid.MouseDown += BonesRepository.UserZone.RestBoneGrid_MouseDown;
     AddingBone(bone);
 }
示例#4
0
        private static void ShuffleBones()
        {
            Random random = new Random();

            for (int i = bones.Length - 1; i >= 1; i--)
            {
                int          j   = random.Next(0, i + 1);
                BoneGraphics tmp = bones[j];
                bones[j] = bones[i];
                bones[i] = tmp;
            }
        }
示例#5
0
        internal static void SetBones() // изначальная инициализация всех игральных костей
        {
            int k = 0;

            for (int i = 0; i < 7; i++)
            {
                for (int j = i; j < 7; j++)
                {
                    bones[k] = new BoneGraphics(i, j);
                    k++;
                }
            }
        }
示例#6
0
        internal virtual void TransferBone(BonesZone zoneTo, int index, bool isToEnd, bool isNeedToTransferMove, System.Windows.Point startPoint)
        {
            BoneGraphics boneTmp = Bones[index];

            if (zoneTo.GetType() == BonesRepository.PlayedZone.GetType())
            {
                AddCountersInRepository(boneTmp.PointsQty1, boneTmp.PointsQty2);
            }
            RemoveAtIndex(index);
            StartAnimation(zoneTo, boneTmp, isToEnd, isNeedToTransferMove, startPoint);
            if (!isNeedToTransferMove)
            {
                zoneTo.AddBone(boneTmp, isToEnd);
            }
        }
示例#7
0
        private bool TryGetBoneFromRest()
        {
            if (BonesRepository.RestZone.Bones.Count > 1)
            {
                Random random = new Random();
                int    r      = random.Next(0, BonesRepository.RestZone.Bones.Count);
                BonesRepository.RestZone.TransferBone(this, r, true, false, BonesRepository.RestZone.Bones[r].BoneGrid.PointFromScreen(new Point(0, 0)));

                if (BonesRepository.RestZone.Bones.Count == 1)
                {
                    BonesRepository.RestZone.SetOpenState();
                    AddCountersInRepository(BonesRepository.RestZone.Bones[0].PointsQty1, BonesRepository.RestZone.Bones[0].PointsQty2);
                }
                BackgroundBrush = BoneGraphics.SetBackgroundBrush(IsTurnToMove, GetIndexOfMaxElement(BonesRepository.PlayedZone.PointsLeftSide, BonesRepository.PlayedZone.PointsRightSide) != -1);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        internal void SetOpenState()
        {
            for (int i = Bones.Count - 1; i > -1; i--)
            {
                BoneGraphics bg = Bones[i];
                RemoveAtIndex(i);
                switch (bg.State)
                {
                case StateOfBone.ClosedHorizontal:
                    bg.State = StateOfBone.OpenHorizontal;
                    break;

                case StateOfBone.ClosedVertical:
                    bg.State = StateOfBone.OpenVertical;
                    break;

                case StateOfBone.ClosedVerticalWithMargin:
                    bg.State = StateOfBone.OpenVerticalWithMargin;
                    break;
                }
                AddingBone(bg);
            }
        }
        private protected override void StartAnimation(BonesZone zoneTo, BoneGraphics bone, bool isToEnd, bool isNeedToTransferMove, System.Windows.Point startPoint)
        {
            this.isNeedToTransferMove = isNeedToTransferMove;
            this.bone    = bone;
            this.zoneTo  = zoneTo;
            this.isToEnd = isToEnd;

            if (bone.AreHalfsEquil)
            {
                bone.State = StateOfBone.OpenVertical;
            }
            else
            {
                if (BonesRepository.PlayedZone.Bones.Count == 0)
                {
                    bone.State = StateOfBone.OpenHorizontal;
                }
                else
                {
                    if (isToEnd)
                    {
                        bone.State = BonesRepository.PlayedZone.PointsRightSide == bone.PointsQty1 ? StateOfBone.OpenHorizontal : StateOfBone.OpenHorizontalTransposed;
                    }
                    else
                    {
                        bone.State = BonesRepository.PlayedZone.PointsLeftSide == bone.PointsQty2 ? StateOfBone.OpenHorizontal : StateOfBone.OpenHorizontalTransposed;
                    }
                }
            }

            var windowPoint = mainWindow.PointFromScreen(new System.Windows.Point(0, 0));
            var borderPoint = mainWindow.border.PointFromScreen(new System.Windows.Point(0, 0));

            borderPoint.Y       -= mainWindow.borderRest.ActualHeight / 2.0;
            bone.BoneGrid.Margin = new Thickness(Math.Abs(startPoint.X) - Math.Abs(windowPoint.X), Math.Abs(startPoint.Y) - Math.Abs(windowPoint.Y) - 23, 0, 0);
            canvasForAnimation.Children.Add(bone.BoneGrid);

            Storyboard myStoryboard = new Storyboard();

            myStoryboard.Completed += MyStoryboard_Completed;
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();

            Storyboard.SetTarget(animation, bone.BoneGrid);
            Storyboard.SetTargetProperty(animation, new PropertyPath("Margin"));

            System.Windows.Point target = BonesRepository.PlayedZone.GetTargetPoint(isToEnd, bone.AreHalfsEquil);
            if (target.X == -1 && target.Y == -1)
            {
                target = new System.Windows.Point(
                    Math.Floor(Math.Abs(borderPoint.X) + Math.Abs(mainWindow.border.ActualWidth / 2)) - Math.Min(bone.BoneGrid.Width, bone.BoneGrid.Height),
                    Math.Floor(Math.Abs(borderPoint.Y) + Math.Abs(mainWindow.border.ActualHeight / 2)) - Math.Min(bone.BoneGrid.Width, bone.BoneGrid.Height) * (bone.AreHalfsEquil ? 1 : 0.5));
            }

            double diffX = Math.Abs(startPoint.X) - target.X;
            double diffY = Math.Abs(startPoint.Y) - target.Y;

            for (int count = 1; count < 101; count++)
            {
                double left = bone.BoneGrid.Margin.Left - (diffX / 100.0 * count);
                double top  = bone.BoneGrid.Margin.Top - (diffY / 100.0 * count);
                DiscreteObjectKeyFrame keyFrame = new DiscreteObjectKeyFrame(new
                                                                             Thickness(left, top, 0, 0), TimeSpan.FromMilliseconds(0.01 * DelayInMs * count));
                animation.KeyFrames.Add(keyFrame);
            }
            myStoryboard.Children.Add(animation);
            myStoryboard.Begin();
        }
示例#10
0
 private protected virtual void AddingBone(BoneGraphics bone)
 {
     Bones.Add(bone);
     Grids.Add(bone.BoneGrid);
     Grids[^ 1].Name = $"G{Grids.Count - 1}";
示例#11
0
 private protected virtual void StartAnimation(BonesZone zoneTo, BoneGraphics bone, bool isToEnd, bool isNeedToTransferMove, System.Windows.Point startPoint)
 {
 }
示例#12
0
 internal override void AddBone(BoneGraphics bone, bool isToEnd = true)
 {
     bone.State = State;
     AddingBone(bone);
 }
示例#13
0
 internal override void AddBone(BoneGraphics bone, bool isToEnd = true)
 {
     bone.State = StateOfBone.OpenVerticalWithMargin;
     bone.BoneGrid.MouseDown += UserBoneGrid_MouseDown;
     AddingBone(bone);
 }