Пример #1
0
        /// <summary>
        /// draws the tank to the grpahics , scaled to the provided displaySize.
        /// Also shows current durability as percentage
        /// </summary>
        /// <param name="graphics">draw tank on this graphic field</param>
        /// <param name="displaySize">scaling size of said feild</param>
        public void Paint(Graphics graphics, Size displaySize)
        {
            //work out where to draw tank in graphics
            int drawX1 = displaySize.Width * tankPosX / Battlefield.WIDTH;
            int drawY1 = displaySize.Height * tankPosY / Battlefield.HEIGHT;
            int drawX2 = displaySize.Width * (tankPosX + TankModel.WIDTH) / Battlefield.WIDTH;
            int drawY2 = displaySize.Height * (tankPosY + TankModel.HEIGHT) / Battlefield.HEIGHT;

            //draw tank on graphics
            graphics.DrawImage(tankBmp, new Rectangle(drawX1, drawY1, drawX2 - drawX1, drawY2 - drawY1));

            // draw current durability on tank
            // work out centre of tank
            int drawY3 = displaySize.Height * (tankPosY - TankModel.HEIGHT) / Battlefield.HEIGHT;
            //select font and colour of text
            Font  durFont  = new Font("Arial", 8);
            Brush durBrush = new SolidBrush(Color.White);
            //work out durability percentage of tank using the default value for tankModel
            int defaultDur    = tanksModel.GetTankHealth();
            int durPercentage = tankDurbility * 100 / defaultDur;

            //if tank has been damaged then show a percentage on tank
            if (durPercentage < 100)
            {
                //draw on tank
                graphics.DrawString(durPercentage + "%", durFont, durBrush, new Point(drawX1, drawY3));
            }
        }
Пример #2
0
        public BattleTank(TankModel player, int tankX, int tankY, GameController game)
        {
            bPlayer     = player;
            tankx       = tankX;
            tanky       = tankY;
            currentgame = game;

            TankModel current    = GetTank();
            int       durability = current.GetTankHealth();

            angle         = 0;
            power         = 25;
            currentweapon = 0;

            TankModel.TankColour();
        }
Пример #3
0
 /// <summary>
 ///  creates a new tank for a player
 /// </summary>
 /// <param name="player">The owner of new tank</param>
 /// <param name="tankX">Starting X coordinate of new tank</param>
 /// <param name="tankY">Starting Y coordinate of new tank</param>
 /// <param name="game">The current battle</param>
 public GameplayTank(GenericPlayer player, int tankX, int tankY, Battle game)
 {
     //sets up the default values of tank via passed information in constructor
     tanksPlayer = player;
     tankPosX    = tankX;
     tankPosY    = tankY;
     tankInGame  = game;
     //find the tank model via player
     tanksModel = tanksPlayer.GetTank();
     //gets the health of said model
     tankDurbility = tanksModel.GetTankHealth();
     //set the default values for angle , power and weapon
     currentAngle  = 0f;
     currentPower  = 25;
     currentWeapon = 0;
     //draw tank on feild of battle and save bitmap to class
     tankBmp = tanksModel.CreateTankBMP(tanksPlayer.PlayerColour(), currentAngle);
 }