コード例 #1
0
        private Game _game;                     // game


        public ControlledTank(TankController player, int tankX, int tankY, Game game)
        {
            /// <summary>
            ///
            /// This constructor stores player, tankX, tankY and game as private fields of ControlledTank. It then gets the Tank by using the TankController's GetTank() method,
            /// then calls GetArmour() on it and stores this as the ControlledTank's current durability. This will go down as the tank takes damage.
            ///
            /// The constructor also initialises the angle, power and current weapon private variables, which start at 0, 25 and 0 respectively.
            /// Angle should be stored as a private float, while power and current weapon should be stored as private ints.
            ///
            /// Finally, it should also call Tank's CreateBitmap method, passing in the colour (retrieved from TankController's TankColour()) and current angle.
            /// The return value should then be stored as yet another private field.
            ///
            /// </summary>

            _tankX           = tankX;
            _tankY           = tankY;
            _player          = player;
            _type            = GetTank();
            _durability      = _type.GetArmour();
            _deltadurability = _durability;
            _angle           = 0;
            _tankPower       = 25;
            _weapon          = 0;
            _image           = _type.CreateBitmap(_player.TankColour(), _angle);
            _game            = game;
        }
コード例 #2
0
ファイル: PlayerTank.cs プロジェクト: tdiego95/TankBattle
        public PlayerTank(TankController player, int tankX, int tankY, Game game)
        {
            this.tankX          = tankX;
            this.tankY          = tankY;
            this.game           = game;
            this.tankController = player;

            angle  = 0;
            power  = 25;
            weapon = 0;

            tank    = tankController.CreateTank();
            health  = tank.GetArmour();
            tankBmp = tank.CreateTankBitmap(tankController.PlayerColour(), angle);
        }
コード例 #3
0
ファイル: PlayerTank.cs プロジェクト: tdiego95/TankBattle
        public void Render(Graphics graphics, Size displaySize)
        {
            int drawX1 = displaySize.Width * tankX / Map.WIDTH;
            int drawY1 = displaySize.Height * tankY / Map.HEIGHT;
            int drawX2 = displaySize.Width * (tankX + Tank.WIDTH) / Map.WIDTH;
            int drawY2 = displaySize.Height * (tankY + Tank.HEIGHT) / Map.HEIGHT;

            graphics.DrawImage(tankBmp, new Rectangle(drawX1, drawY1, drawX2 - drawX1, drawY2 - drawY1));

            int drawY3 = displaySize.Height * (tankY - Tank.HEIGHT) / Map.HEIGHT;

            Font  font  = new Font("Arial", 8);
            Brush brush = new SolidBrush(Color.White);

            int pet = health * 100 / tank.GetArmour();

            if (pet < 100)
            {
                graphics.DrawString(pet + "%", font, brush, new Point(drawX1, drawY3));
            }
        }