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); }
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(); }
public void Redraw( ICTank iTank, EPartOfScreen iPartOfScreen) { mView.Redraw( iTank, iPartOfScreen); }
public CTankProxy( int iPosX, int iPosY, ICTank iPlayerTank, ETankOwner iTankOwner) : base(iPosX, iPosY) { SetModel(new MProxyTank(iPosX, iPosY, iTankOwner)); }
public CLaserGunTank( ICTank iDecoratedTank, TimeSpan iDecorationDuration) : base(iDecoratedTank) { mModel = new MLaserGunTank(this, iDecorationDuration); mLaserBeamParts = new LinkedList <CMissile>(); }
private void CheckTankCurrentBonuses(ICTank iTank) { CLaserGunTank laserTank = iTank as CLaserGunTank; if (laserTank != null) { if (DateTime.Now > laserTank.GetDecorationEndTime()) { mChildTanks.Find(laserTank).Value = laserTank.GetDecoratedTank(); } } }
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; }
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; } }
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++; } }
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(); } } }
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); }
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; }
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(); }