/// <summary> /// /// This constructor initializes a new instance of the ControlledTank class. /// It also stores the tankModel by usubg the Opponents GetTank() method, and /// GetArmour() for the current durability of the TankModel. In addition, it also /// stores the angle, power, current weapons and colour of the tank which is a bitmap. /// /// Author John Santias and Hoang Nguyen October 2017 /// /// </summary> /// <param name="player"> A reference of Opponent stored as player </param> /// <param name="tankX"> The x coordinate of the tank </param> /// <param name="tankY"> The y coordinate of the tank </param> /// <param name="game"> A reference of Gameplay stored as game </param> public ControlledTank(Opponent player, int tankX, int tankY, Gameplay game) { this.player = player; this.tankX = tankX; this.tankY = tankY; this.game = game; tankModel = player.GetTank(); currentDur = tankModel.GetArmour(); angle = 0; power = 25; tankWeapon = 0; colour = tankModel.CreateBitmap(player.GetColour(), angle); }
public BattleTank(GenericPlayer player, int tankX, int tankY, Game game) { //setting up the values we recieve to the variables in this class this.tPlayer = player; this.xCoord = tankX; this.yCoord = tankY; this.tGame = game; this.tPower = 25; this.tAngle = 0; this.tWeapon = 0; //creating a tank, getting color, setting angle and getting armour //seems like the order of things is very important //was failing tests coz of the null excpetion, took me couple of hours //to understand that it needs to be re-ordered. this.tTank = tPlayer.CreateTank(); this.tankBMP = tTank.CreateBMP(tPlayer.GetTankColour(), this.tAngle); this.health = tTank.GetArmour(); }
public void Paint(Graphics graphics, Size displaySize) { //copied from ams with slight changes //its drawing a tank int drawX1 = displaySize.Width * this.xCoord / Map.WIDTH; int drawY1 = displaySize.Height * this.yCoord / Map.HEIGHT; int drawX2 = displaySize.Width * (this.xCoord + TankModel.WIDTH) / Map.WIDTH; int drawY2 = displaySize.Height * (this.yCoord + TankModel.HEIGHT) / Map.HEIGHT; graphics.DrawImage(tankBMP, new Rectangle(drawX1, drawY1, drawX2 - drawX1, drawY2 - drawY1)); int drawY3 = displaySize.Height * (this.yCoord - TankModel.HEIGHT) / Map.HEIGHT; Font font = new Font("Arial", 8); Brush brush = new SolidBrush(Color.White); int pct = this.health * 100 / tTank.GetArmour(); if (pct < 100) { graphics.DrawString(pct + "%", font, brush, new Point(drawX1, drawY3)); } }
/// <summary> /// /// This method draws the ControlledTank to graphic, scaled /// to the provided display size. The durability of the tank is /// also shown as a percentage. /// /// Author John Santias and Hoang Nguyen October 2017 /// /// </summary> /// <param name="graphics"> The bitmap of the tank </param> /// <param name="displaySize"> Size of display </param> public void Draw(Graphics graphics, Size displaySize) { int x = tankX; int y = tankY; int drawX1 = displaySize.Width * x / Terrain.WIDTH; int drawY1 = displaySize.Height * y / Terrain.HEIGHT; int drawX2 = displaySize.Width * (x + TankModel.WIDTH) / Terrain.WIDTH; int drawY2 = displaySize.Height * (y + TankModel.HEIGHT) / Terrain.HEIGHT; graphics.DrawImage(colour, new Rectangle(drawX1, drawY1, drawX2 - drawX1, drawY2 - drawY1)); int drawY3 = displaySize.Height * (y - TankModel.HEIGHT) / Terrain.HEIGHT; Font font = new Font("Arial", 8); Brush brush = new SolidBrush(Color.White); int pct = currentDur * 100 / tankModel.GetArmour(); if (pct < 100) { graphics.DrawString(pct + "%", font, brush, new Point(drawX1, drawY3)); } }