Exemplo n.º 1
0
        public static bool CollisionWithOtherTanks(
            ICTank iTank,
            LinkedList <ICTank> oTanks,
            int iPosXInt,
            int iPosYInt,
            int iDamage,
            bool iDoDamage)
        {
            if (IndicesOutsideWindow(iPosXInt, iPosYInt))
            {
                return(false);
            }

            foreach (ICTank tank in oTanks)
            {
                if (tank == iTank)
                {
                    continue;
                }

                if (tank.GetPosX() > iPosXInt || tank.GetPosX() + tank.GetSize() <= iPosXInt ||
                    tank.GetPosY() > iPosYInt || tank.GetPosY() + tank.GetSize() <= iPosYInt)
                {
                    continue;
                }

                if (iDoDamage)
                {
                    tank.HitPoints.TakeDamagedFromMissile(iDamage);
                }

                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        private void RedrawFrameAndBasicMapElements(
            Graphics iFormGraphics,
            ICTank iTank,
            int iBoardElementSize,
            int iElemenstFirstXIndex,
            int iElemenstFirstYIndex,
            int iFirstWindowElementX,
            int iAmountOfWindowElementsX,
            int iAmountOfWindowElementsY)
        {
            SolidBrush solidBrush = new SolidBrush(Color.Red);

            int xIndex = iElemenstFirstXIndex;

            for (int currentWindowPartX = 0; currentWindowPartX < iAmountOfWindowElementsX; currentWindowPartX++)
            {
                CBoardElement[][] boardElements = mController.Elements;

                int yIndex = iElemenstFirstYIndex - 1;
                for (int currentWindowPartY = iTank.HitPoints.GetBarHeight();
                     currentWindowPartY <= iAmountOfWindowElementsY; currentWindowPartY++)
                {
                    yIndex++;
                    if (Algorithm.IndicesOutsideWindow(xIndex, yIndex))
                    {
                        solidBrush = new SolidBrush(mFrameColor);
                    }
                    else
                    {
                        if (boardElements[xIndex][yIndex].IsTank() ||
                            boardElements[xIndex][yIndex].IsMissile() ||
                            boardElements[xIndex][yIndex].IsBonus())
                        {
                            continue;
                        }

                        solidBrush = new SolidBrush(boardElements[xIndex][yIndex].View.Color);

                        if (boardElements[xIndex][yIndex].IsDestroyed())
                        {
                            solidBrush = new SolidBrush(mDestroyedMapColor);
                        }

                        if (boardElements[xIndex][yIndex].IsFortressWall())
                        {
                            solidBrush = new SolidBrush(mFortressWallColor);
                        }
                    }
                    iFormGraphics.FillRectangle(
                        solidBrush,
                        new Rectangle(
                            iBoardElementSize * (currentWindowPartX + iFirstWindowElementX),
                            iBoardElementSize * currentWindowPartY,
                            iBoardElementSize,
                            iBoardElementSize));
                }
                xIndex++;
            }
            solidBrush.Dispose();
        }
Exemplo n.º 3
0
 public void Redraw(
     ICTank iTank,
     EPartOfScreen iPartOfScreen)
 {
     mView.Redraw(
         iTank,
         iPartOfScreen);
 }
Exemplo n.º 4
0
 public CTankProxy(
     int iPosX,
     int iPosY,
     ICTank iPlayerTank,
     ETankOwner iTankOwner)
     :
     base(iPosX, iPosY)
 {
     SetModel(new MProxyTank(iPosX, iPosY, iTankOwner));
 }
Exemplo n.º 5
0
        public CLaserGunTank(
            ICTank iDecoratedTank,
            TimeSpan iDecorationDuration)
            :
            base(iDecoratedTank)
        {
            mModel = new MLaserGunTank(this,
                                       iDecorationDuration);

            mLaserBeamParts = new LinkedList <CMissile>();
        }
Exemplo n.º 6
0
        private void CheckTankCurrentBonuses(ICTank iTank)
        {
            CLaserGunTank laserTank = iTank as CLaserGunTank;

            if (laserTank != null)
            {
                if (DateTime.Now > laserTank.GetDecorationEndTime())
                {
                    mChildTanks.Find(laserTank).Value = laserTank.GetDecoratedTank();
                }
            }
        }
Exemplo n.º 7
0
        public CMissile(
            ICTank iParentTank,
            int iPosX,
            int iPosY,
            EDirection iDirection)
        {
            mParentTank = iParentTank;

            mModel            = new MMissile();
            mModel.Controller = this;

            mModel.SetPosX(iPosX);
            mModel.SetPosY(iPosY);
            mModel.Direction = iDirection;
        }
Exemplo n.º 8
0
        public void OnKeyReleased(Keys iKeyCode)
        {
            ICTank firstTank  = GetFirstTank();
            ICTank secondTank = GetSecondTank();

            switch (iKeyCode)
            {
            case SECOND_TANK_MOVE_DOWN:
                secondTank.SetMoveDown(false);
                break;

            case SECOND_TANK_MOVE_LEFT:
                secondTank.SetMoveLeft(false);
                break;

            case SECOND_TANK_MOVE_RIGHT:
                secondTank.SetMoveRight(false);
                break;

            case SECOND_TANK_MOVE_UP:
                secondTank.SetMoveUp(false);
                break;

            case SECOND_TANK_SHOOT:
                secondTank.SetUsingWeapon(false);
                break;

            case FIRST_TANK_MOVE_DOWN:
                firstTank.SetMoveDown(false);
                break;

            case FIRST_TANK_MOVE_LEFT:
                firstTank.SetMoveLeft(false);
                break;

            case FIRST_TANK_MOVE_RIGHT:
                firstTank.SetMoveRight(false);
                break;

            case FIRST_TANK_MOVE_UP:
                firstTank.SetMoveUp(false);
                break;

            case FIRST_TANK_SHOOT:
                firstTank.SetUsingWeapon(false);
                break;
            }
        }
Exemplo n.º 9
0
        private void RedrawTank(
            Graphics iFormGraphics,
            ICTank iTank,
            int iBoardElementSize,
            int iElemenstFirstXIndex,
            int iElemenstFirstYIndex,
            int iFirstWindowElementX,
            int iAmountOfWindowElementsX,
            int iAmountOfWindowElementsY)
        {
            CBoardElement[][] boardElements = mController.Elements;
            SolidBrush        solidBrush;

            int xIndex = iElemenstFirstXIndex;

            for (int currentWindowPartX = 0; currentWindowPartX < iAmountOfWindowElementsX; currentWindowPartX++)
            {
                int yIndex = iElemenstFirstYIndex - 1;
                for (int currentWindowPartY = iTank.HitPoints.GetBarHeight();
                     currentWindowPartY <= iAmountOfWindowElementsY; currentWindowPartY++)
                {
                    yIndex++;
                    if (Algorithm.IndicesOutsideWindow(xIndex, yIndex))
                    {
                        continue;
                    }

                    if (boardElements[xIndex][yIndex].IsTank())
                    {
                        solidBrush = new SolidBrush(iTank.View.TankColor);

                        if (boardElements[xIndex][yIndex].IsCanon())
                        {
                            solidBrush = new SolidBrush(iTank.View.CanonColor);
                        }
                        iFormGraphics.FillRectangle(
                            solidBrush,
                            new Rectangle(
                                iBoardElementSize * (currentWindowPartX + iFirstWindowElementX),
                                iBoardElementSize * currentWindowPartY,
                                iBoardElementSize,
                                iBoardElementSize));
                        solidBrush.Dispose();
                    }
                }
                xIndex++;
            }
        }
Exemplo n.º 10
0
        private void RedrawHitPointsBar(
            Graphics iFormGraphics,
            ICTank iTank,
            int iBoardElementSize,
            int iFirstWindowElementX,
            int iAmountOfWindowElementsX)
        {
            SolidBrush solidBrush;
            double     tankHitPointsPercentage = iTank.HitPoints.GetAmountAsPercentage();

            for (int currentWindowPartX = 0; currentWindowPartX < iAmountOfWindowElementsX; currentWindowPartX++)
            {
                double hitPointsBarPart        = (double)currentWindowPartX / (double)iAmountOfWindowElementsX;
                bool   markHitPointsAsPositive = hitPointsBarPart < tankHitPointsPercentage;

                for (int currentWindowPartY = 0; currentWindowPartY < iTank.HitPoints.GetBarHeight();
                     currentWindowPartY++)
                {
                    if (markHitPointsAsPositive)
                    {
                        solidBrush = new SolidBrush(mHitPointsPositiveColor);
                    }
                    else
                    {
                        solidBrush = new SolidBrush(mHitPointsNegativeColor);
                    }

                    iFormGraphics.FillRectangle(
                        solidBrush,
                        new Rectangle(
                            iBoardElementSize * (currentWindowPartX + iFirstWindowElementX),
                            iBoardElementSize * currentWindowPartY,
                            iBoardElementSize,
                            iBoardElementSize));
                    solidBrush.Dispose();
                }
            }
        }
Exemplo n.º 11
0
        private void CheckBonuses(ICTank iTank)
        {
            CheckTankCurrentBonuses(iTank);

            int bonusIndex = iTank.GetIndexOfPickedBonus(mChildBonuses);

            if (bonusIndex < 0)
            {
                return;
            }

            CBaseBonus bonus = mChildBonuses.ElementAt(bonusIndex);

            CLaserBonus laserBonus = bonus as CLaserBonus;

            if (laserBonus != null)
            {
                mChildTanks.Find(iTank).Value = new CLaserGunTank(iTank,
                                                                  laserBonus.GetDuration());
            }

            mChildBonuses.Remove(bonus);
        }
Exemplo n.º 12
0
        private void SetDirectionToPlayerPosition()
        {
            ICTank playerTank = mController.ParentGameWindow.GetPlayerTank();

            int playerTankSize = playerTank.GetSize();

            if (mPosition.GetPosX() > playerTank.GetPosX() + playerTankSize)
            {
                base.SetMoveLeft(true);
            }
            else if (mPosition.GetPosX() < playerTank.GetPosX() - playerTankSize)
            {
                base.SetMoveRight(true);
            }

            if (mPosition.GetPosY() > playerTank.GetPosY() + playerTankSize)
            {
                base.SetMoveUp(true);
            }
            else if (mPosition.GetPosY() < playerTank.GetPosY() - playerTankSize)
            {
                base.SetMoveDown(true);
            }
        }
 protected CBaseTankDecorator(ICTank iDecoratedTank)
 {
     mDecoratedTank = iDecoratedTank;
 }
Exemplo n.º 14
0
        public void Redraw(
            ICTank iTank,
            EPartOfScreen iPartOfScreen)
        {
            Graphics formGraphics = mController.ParentGameWindow.View.CreateGraphics();

            Rectangle windowBounds = mController.ParentGameWindow.View.Bounds;

            int halfTankSize = iTank.GetSize() / 2;

            int tankPosX = iTank.GetPosX();
            int amountOfWindowElementsX = (windowBounds.Width / mController.ParentGameWindow.GetElementSize()) / 2;
            int elementsFirstXIndex     = tankPosX - (amountOfWindowElementsX / 2 - halfTankSize);

            int firstWindowElementX = 0;

            if (iPartOfScreen == EPartOfScreen.RIGHT)
            {
                firstWindowElementX = amountOfWindowElementsX + 1;
            }

            int tankPosY = iTank.GetPosY();
            int amountOfWindowElementsY = windowBounds.Height / mController.ParentGameWindow.GetElementSize();
            int elementsFirstYIndex     = tankPosY - (amountOfWindowElementsY / 2 - halfTankSize);

            CBoardElement[][] boardElements = mController.Elements;

            int boardElementSize = mController.ParentGameWindow.GetElementSize();

            RedrawFrameAndBasicMapElements(
                formGraphics,
                iTank,
                boardElementSize,
                elementsFirstXIndex,
                elementsFirstYIndex,
                firstWindowElementX,
                amountOfWindowElementsX,
                amountOfWindowElementsY);

            RedrawTank(
                formGraphics,
                iTank,
                boardElementSize,
                elementsFirstXIndex,
                elementsFirstYIndex,
                firstWindowElementX,
                amountOfWindowElementsX,
                amountOfWindowElementsY);

            RedrawBonuses(
                formGraphics,
                iTank,
                boardElementSize,
                elementsFirstXIndex,
                elementsFirstYIndex,
                firstWindowElementX,
                amountOfWindowElementsX,
                amountOfWindowElementsY);

            RedrawMissiles(
                formGraphics,
                iTank,
                boardElementSize,
                elementsFirstXIndex,
                elementsFirstYIndex,
                firstWindowElementX,
                amountOfWindowElementsX,
                amountOfWindowElementsY);

            RedrawHitPointsBar(
                formGraphics,
                iTank,
                boardElementSize,
                firstWindowElementX,
                amountOfWindowElementsX);

            RedrawRightBorder(
                formGraphics,
                boardElementSize,
                firstWindowElementX,
                amountOfWindowElementsX,
                amountOfWindowElementsY);

            formGraphics.Dispose();
        }