Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void GameLoop()
        {
            _Stopwatch.Start();
            do
            {
                _StartTick = _Stopwatch.Elapsed;
                this.Invalidate();

                if (_NewGame)
                {
                    SetPlayState(PlayStates.PLAYING);
                }
                else if (_PlayState == PlayStates.GAMEOVER)
                {
                    if (_Saved == false)
                    {
                        _ScoreDT.AddRow("Test", MySquare.TotalSquareScore, MySquare.TotalSquareCreated);;
                        _Saved = true;
                    }
                }
                else if (_PlayState == PlayStates.PAUSED)
                {
                }
                else if (_PlayState == PlayStates.WIN)
                {
                    if (_Saved == false)
                    {
                        _ScoreDT.AddRow("Test", MySquare.TotalSquareScore, MySquare.TotalSquareCreated);;
                        _Saved = true;
                    }
                }
                else
                {
                    FlagsCheck checkMoving = CheckMovingSquare();

                    if (checkMoving == FlagsCheck.NONE)
                    {
                        //Pag Destination Reached na ilipat ng PlayBlock ang mySquare
                        ChangeSquareBlock();
                        //Combine squares na nasa isang PlayBlock
                        CombineSquares();

                        if (_CreateNewSquare)
                        {
                            if (NewSquare())
                            {
                                _CreateNewSquare = false;
                                if (CheckGameOver())
                                {
                                    SetPlayState(PlayStates.GAMEOVER);
                                    continue;
                                }
                                checkMoving = checkMoving | FlagsCheck.ANIMATE;
                            }
                        }

                        if (_SetDestinations && _MoveQueue.Count > 0)
                        {
                            _Direction = _MoveQueue.Dequeue();
                            if (SetDestination())
                            {
                                _CreateNewSquare = true;
                            }
                            if (_MoveQueue.Count <= 0)
                            {
                                _SetDestinations = false;
                            }
                        }
                    }

                    if ((checkMoving & FlagsCheck.ANIMATE) == FlagsCheck.ANIMATE | (checkMoving & FlagsCheck.ANIMATING) == FlagsCheck.ANIMATING)
                    {
                        AnimateSquare();
                    }
                    else if ((checkMoving & FlagsCheck.MOVE) == FlagsCheck.MOVE | (checkMoving & FlagsCheck.MOVING) == FlagsCheck.MOVING)
                    {
                        MoveSquares2();
                    }
                }

                do
                {
                } while (_Stopwatch.Elapsed.TotalMilliseconds - _StartTick.TotalMilliseconds < 8.33);
            } while (this.Created);
        }