예제 #1
0
 public void RemoveSquare(MySquare mySquare)
 {
     if (_MySquareList.Contains(mySquare))
     {
         _MySquareList.Remove(mySquare);
     }
 }
예제 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            try
            {
                using (new SolidBrush(Color.Blue))
                {
                    for (int i = 0; i < _XCount; i++)
                    {
                        for (int j = 0; j < _YCount; j++)
                        {
                            MySquare sq = _PlayBlockArray[i, j].MyFirstSquare;
                            if (sq != null)
                            {
                                sq.Draw(e.Graphics);
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
예제 #3
0
        private void ChangeSquareBlock()
        {
            List <MySquare> ListToRemove = new List <MySquare>();
            List <int>      ListX        = new List <int>();
            List <int>      ListY        = new List <int>();

            for (int i = 0; i < _XCount; i++)
            {
                for (int j = 0; j < _YCount; j++)
                {
                    foreach (MySquare sq in _PlayBlockArray[i, j].MySquareList)
                    {
                        if (sq.DestinationReached)
                        {
                            ListToRemove.Add(sq);
                            ListX.Add(i);
                            ListY.Add(j);
                        }
                    }
                }
            }

            for (int z = 0; z < ListToRemove.Count; z++)
            {
                MySquare sq = ListToRemove[z];
                for (int i = 0; i < _XCount; i++)
                {
                    for (int j = 0; j < _YCount; j++)
                    {
                        if (sq.Position == _PlayBlockArray[i, j].Position)
                        {
                            _PlayBlockArray[i, j].AddSquare(ref sq);
                            _PlayBlockArray[ListX[z], ListY[z]].RemoveSquare(sq);
                        }
                    }
                }
            }
        }
예제 #4
0
        private void NewGame()
        {
            for (int i = 0; i < _XCount; i++)
            {
                for (int j = 0; j < _YCount; j++)
                {
                    _PlayBlockArray[i, j].ClearSquare();
                }
            }

            MySquare.ResetScores();
            _MoveQueue.Clear();

            NewSquare();
            NewSquare();

            int x = 0;

            for (int i = 0; i < _XCount; i++)
            {
                for (int j = 0; j < _YCount; j++)
                {
                    if (_PlayBlockArray[i, j].MySquareCount > 0)
                    {
                        x = x + _PlayBlockArray[i, j].MySquareCount;

                        foreach (MySquare sq in _PlayBlockArray[i, j].MySquareList)
                        {
                            //Debug.WriteLine("Square : ");
                            //Debug.WriteLine(sq.ToString());
                            //Debug.WriteLine(sq.Position);
                        }
                    }
                }
            }

            _Saved = false;
        }
예제 #5
0
        private FlagsCheck CheckMovingSquare()
        {
            //bit flags ang return nito subok lang
            FlagsCheck ret = 0;

            for (int i = 0; i < _XCount; i++)
            {
                for (int j = 0; j < _YCount; j++)
                {
                    MySquare sq = _PlayBlockArray[i, j].MyFirstSquare;
                    if (sq != null)
                    {
                        if (sq.Animate)
                        {
                            ret = ret | FlagsCheck.ANIMATE;
                        }

                        if (sq.SquareState == MySquare.SquareStates.Animating)
                        {
                            ret = ret | FlagsCheck.ANIMATING;
                        }

                        if (!sq.DestinationReached)
                        {
                            ret = ret | FlagsCheck.MOVE;
                        }

                        if (sq.SquareState == MySquare.SquareStates.Moving)
                        {
                            ret = ret | FlagsCheck.MOVING;
                        }
                    }
                }
            }

            return(ret);
        }
예제 #6
0
        public int Combine()
        {
            int ret         = 0;
            int squareCount = _MySquareList.Count;

            if (_MySquareList.Count > 1)
            {
                int  num = 0, prev = 0, ttl = 0;
                bool flag = true;
                for (int i = 0; i < _MySquareList.Count; i++)
                {
                    if (i == 0)
                    {
                        int.TryParse(_MySquareList[0].ToString(), out prev);
                    }
                    int.TryParse(_MySquareList[i].ToString(), out num);
                    ttl += num;

                    if (prev != num)
                    {
                        flag = false;
                    }
                }

                if (flag)
                {
                    ClearSquare();
                    //MySquare.DecreaseTotalCreated(squareCount);
                    MySquare newSquare = new MySquare((int)_Size.Width, ttl.ToString(), _Position);
                    _MySquareList.Add(newSquare);
                    ret = ttl;
                }
            }

            return(ret);
        }
예제 #7
0
 public void AddSquare(ref MySquare mySquare)
 {
     _MySquareList.Add(mySquare);
 }
예제 #8
0
        private bool NewSquare()
        {
            int  XrndNumber = 0, YrndNumber = 0;
            bool Flag = false;

            bool[] XrndArray = new bool[_XCount];

            for (; ;)
            {
                XrndNumber = _Random.Next(_XCount);

                if (XrndArray.Contains(false) == false)
                {
                    return(false);
                }

                if (XrndArray[XrndNumber])
                {
                    continue;
                }
                else
                {
                    XrndArray[XrndNumber] = true;
                }

                for (int j = 0; j < _XCount; j++)
                {
                    if (_PlayBlockArray[XrndNumber, j].MySquareCount <= 0)
                    {
                        Flag = true;
                        break;
                    }
                }

                if (Flag)
                {
                    break;
                }
            }

            Flag = false;
            for (; ;)
            {
                YrndNumber = _Random.Next(_YCount);
                if (_PlayBlockArray[XrndNumber, YrndNumber].MySquareCount <= 0)
                {
                    Flag = true;
                    break;
                }
            }

            //Para mas mataas chance na 2 ang lumabas
            int sqText = _Random.Next(4) + 1;

            if (sqText > 3)
            {
                sqText = 4;
            }
            else
            {
                sqText = 2;
            }

            MySquare newSq = new MySquare(_PlayBlockWidth, sqText.ToString(), _PlayBlockArray[XrndNumber, YrndNumber].Position);

            _PlayBlockArray[XrndNumber, YrndNumber].AddSquare(ref newSq);

            return(true);
        }
예제 #9
0
        private void MoveSquares()
        {
            List <MySquare> ListToRemove = new List <MySquare>();

            for (int i = 0; i < _XCount; i++)
            {
                for (int j = 0; j < _YCount; j++)
                {
                    foreach (MySquare sq in _PlayBlockArray[i, j].MySquareList)
                    {
                        sq.Move();
                        //Kunin mySquare na nakarating na sa Destination para ilipat
                        if (sq.DestinationReached)
                        {
                            ListToRemove.Add(sq);
                        }
                    }


                    if (_PlayBlockArray[i, j].MySquareList.Count > 5)
                    {
                        Debug.WriteLine(" Test " + _PlayBlockArray[i, j].MySquareList.Count());
                    }
                }
            }

            //Ilipat sa bagong PlayBlock nakuhang mySquare
            //foreach (MySquare sq in ListToRemove)  //ayaw mapasa as ref pag galing sa for each
            for (int z = 0; z < ListToRemove.Count(); z++)
            {
                MySquare sq    = ListToRemove[z];
                bool     found = false;

                for (int i = 0; i < _XCount; i++)
                {
                    for (int j = 0; j < _YCount; j++)
                    {
                        foreach (MySquare sqInner in _PlayBlockArray[i, j].MySquareList)
                        {
                            if (sq.Equals(sqInner))
                            {
                                found = true;
                                break;
                            }
                        }

                        if (found == true)
                        {
                            _PlayBlockArray[i, j].RemoveSquare(sq);
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                }

                found = false;
                for (int i = 0; i < _XCount; i++)
                {
                    for (int j = 0; j < _YCount; j++)
                    {
                        if (_PlayBlockArray[i, j].Position == sq.Position)
                        {
                            found = true;
                            _PlayBlockArray[i, j].AddSquare(ref sq);
                        }
                    }
                }
            }

            for (int i = 0; i < _XCount; i++)
            {
                for (int j = 0; j < _YCount; j++)
                {
                    if (_PlayBlockArray[i, j].MySquareList.Count > 1)
                    {
                        int             ttl      = 0;
                        int             sqNum    = 0;
                        List <MySquare> toRemove = new List <MySquare>();
                        foreach (MySquare sq in _PlayBlockArray[i, j].MySquareList)
                        {
                            if (sq.DestinationReached)
                            {
                                toRemove.Add(sq);
                            }
                        }

                        if (toRemove.Count > 0)
                        {
                            for (int k = 0; k < toRemove.Count; k++)
                            {
                                MySquare sq = toRemove[k];
                                int.TryParse(sq.ToString(), out sqNum);
                                ttl = ttl + sqNum;
                                _PlayBlockArray[i, j].RemoveSquare(sq);
                                //MySquare.DecreaseTotalCreated();
                            }

                            MySquare newSquare = new MySquare(_PlayBlockWidth, ttl.ToString(), _PlayBlockArray[i, j].Position);
                            _PlayBlockArray[i, j].AddSquare(ref newSquare);

                            if (ttl == 2048)
                            {
                                SetPlayState(PlayStates.WIN);
                            }
                        }
                    }
                }
            }
        }