Esempio n. 1
0
        private void Animation_OnMix(Cage cage)
        {
            List <Cage> deleteCages = Cages.Where(c => c.Number == -1).ToList();

            for (int i = 0; i < deleteCages.Count; i++)
            {
                MainForm.Controls.Remove(deleteCages[i]);
                Cages.Remove(deleteCages[i]);
            }

            cage.ApplyNumber();
            if (cage.Number > MaxNumberNow)
            {
                MaxNumberNow = cage.Number;
            }
            Score = new Score(args.GetLastScore().CountScore + cage.Number, CountMove);
            OnScore?.Invoke(args);
            if (cage.Number > 99)
            {
                cage.Font = new Font("Google Sans", 22, FontStyle.Regular);
            }
            if (cage.Number > 512)
            {
                cage.Font = new Font("Google Sans", 18, FontStyle.Regular);
            }
            if (cage.Number > 8192)
            {
                cage.Font = new Font("Google Sans", 14, FontStyle.Regular);
            }
        }
Esempio n. 2
0
        private List <Cage> CheckCagesNearly(Cage cage)
        {
            Point       position = cage.Position;
            List <Cage> cageList = new List <Cage>();

            cageList.Add(Cages.Where(c => c.Position.X == position.X - 1 && c.Position.Y == position.Y).FirstOrDefault());
            cageList.Add(Cages.Where(c => c.Position.X == position.X + 1 && c.Position.Y == position.Y).FirstOrDefault());
            cageList.Add(Cages.Where(c => c.Position.Y == position.Y - 1 && c.Position.X == position.X).FirstOrDefault());
            cageList.Add(Cages.Where(c => c.Position.Y == position.Y + -1 && c.Position.X == position.X).FirstOrDefault());
            cageList.RemoveAll(a => a == null);

            return(cageList);
        }
Esempio n. 3
0
        private Cage CheckCageNearly(Cage cage, Move move)
        {
            Point position = cage.Position;

            if (move == Move.Left)
            {
                return(Cages.Where(c => c.Position.X == position.X - 1 && c.Position.Y == position.Y).FirstOrDefault());
            }
            if (move == Move.Right)
            {
                return(Cages.Where(c => c.Position.X == position.X + 1 && c.Position.Y == position.Y).FirstOrDefault());
            }
            if (move == Move.Up)
            {
                return(Cages.Where(c => c.Position.Y == position.Y - 1 && c.Position.X == position.X).FirstOrDefault());
            }
            if (move == Move.Down)
            {
                return(Cages.Where(c => c.Position.Y == position.Y + 1 && c.Position.X == position.X).FirstOrDefault());
            }
            return(null);
        }
Esempio n. 4
0
 private bool CheckWays()
 {
     if (Cages.Count == CellSize.X * CellSize.Y)
     {
         for (int i = 0; i < CellSize.X; i++)
         {
             for (int j = 0; j < CellSize.Y; j++)
             {
                 Cage cage = Cages.Where(c => c.Position.X == j && c.Position.Y == i).FirstOrDefault();
                 if (cage == null)
                 {
                     return(true);
                 }
                 else if (CheckCagesCanMove())
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     return(true);
 }
Esempio n. 5
0
        private void GameLogic(Move move)
        {
            //if (Anim.IsProcess)
            //    return;

            bool isLeft     = move == Move.Left;
            bool isRight    = move == Move.Right;
            bool isUp       = move == Move.Up;
            bool isDown     = move == Move.Down;
            bool isMoveDone = false;

            for (int i = 0; isLeft || isRight ? i < CellSize.X : i < CellSize.Y; i++)
            {
                for (int j = isRight ? CellSize.Y - 1 : isDown ? CellSize.X - 1 : 0; isRight || isDown ? j >= 0 : isUp?j < CellSize.X : j < CellSize.Y; j += isRight || isDown ? -1 : 1)
                {
                    Cage cage = Cages.Where(c => c.Position.X == (isUp || isDown ? i : j) && c.Position.Y == (isUp || isDown ? j : i)).FirstOrDefault();
                    if (cage != null && cage.Number != -1 && CheckCageCanMove(cage, move))
                    {
                        for (int k = 1; isLeft || isRight ? k < CellSize.Y : k < CellSize.X; k++)
                        {
                            Cage nearlyCage = CheckCageNearly(cage, move);
                            if (CheckCageCanMove(cage, move))
                            {
                                if (nearlyCage?.Number == cage.Number && nearlyCage.CanMix)
                                {
                                    cage.Position = new Point(cage.Position.X + (isLeft ? -1 : isRight ? 1 : 0), cage.Position.Y + (isUp ? -1 : isDown ? 1 : 0));
                                    cage.Number  *= 2;
                                    cage.CanMix   = false;

                                    nearlyCage.Number   = -1;
                                    nearlyCage.Name     = cage.Name;
                                    nearlyCage.Position = new Point(-2, -2);

                                    Anim = new Animation(CageDistance, 20, IsAnimation, Animation_OnMix);
                                    Anim.Move(move, cage, true);
                                    Anim.Mix(cage);

                                    isMoveDone = true;
                                    break;
                                }
                                else if (nearlyCage == null)
                                {
                                    cage.Position = new Point(cage.Position.X + (isLeft ? -1 : isRight ? 1 : 0), cage.Position.Y + (isUp ? -1 : isDown ? 1 : 0));
                                    Anim          = new Animation(CageDistance, 20, IsAnimation);
                                    Anim.Move(move, cage, false);
                                    isMoveDone = true;
                                }
                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            Cages.ForEach(c => c.CanMix = true);
            //Cages.ForEach(c=> {
            //    args.History[args.History.Count - 1].Where(c2 => c2.Name == c.Name).FirstOrDefault().Position = c.Position;
            //});
            if (isMoveDone)
            {
                AddRandomCage();
                CountMove++;
                args.History.Add(new List <Cage>(Cages));
                OnMove?.Invoke(args);
            }
            if (!CheckWays())
            {
                OnNoWays?.Invoke(args);
                IsWin = false;
                GameOver();
            }
        }