/// <summary> /// used to handle firing the specified weapon from the tank playerTank. /// </summary> /// <param name="weapon">The weapon chosen from ListWeapons</param> /// <param name="playerTank">The tank that is shooting the weapons</param> /// <param name="currentGame">The battle the shot takes place in</param> public override void ShootWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float x = playerTank.XPos(); float y = playerTank.GetY(); //find the center of the tank x = x + Chassis.WIDTH / 2; y = y + Chassis.HEIGHT / 2; GenericPlayer player = playerTank.GetPlayerNumber(); Boom boom = new Boom(100, 4, 4); Shell shell = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower(), 0.01f, boom, player); Shell shell2 = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower() + 10, 0.01f, boom, player); Shell shell3 = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower() - 10, 0.01f, boom, player); currentGame.AddWeaponEffect(shell); currentGame.AddWeaponEffect(shell2); currentGame.AddWeaponEffect(shell3); }
private void NewTurn() { // find the next player and their tank currentTank = currentGame.GetPlayerTank(); currentPlayer = currentTank.GetPlayerNumber(); //set the title of a form to current round of total rounds this.Text = string.Format("Tank battle - Round {0} of {1}", currentGame.CurrentRound(), currentGame.GetNumRounds()); // set backcolor of controlpanel to currentplayers colour controlPanel.BackColor = currentPlayer.PlayerColour(); // show the current player's name currentPlayerLabel.Text = currentPlayer.Name(); // set angle to current gameplaytank's angle this.Aim(currentTank.GetTankAngle()); //show current tank's power this.SetTankPower(currentTank.GetPower()); //show current windspeed //postive values should state its a eastly wind while negative values come from windly west if (currentGame.GetWind() >= 0) { windspeedLabel.Text = string.Format("{0} E", currentGame.GetWind()); } else { windspeedLabel.Text = string.Format("{0} W", (currentGame.GetWind() * -1)); // times by a negative number to shows a flat value for wind } //clear weapon choices in weaponSelect weaponSelect.Items.Clear(); // find all weapons available to current tank foreach (string weapon in currentTank.GetTank().ListWeapons()) { // add each weapon to selection choice of weaponSelect weaponSelect.Items.Add(weapon); } //set the current weapon to be used of current tank SetWeapon(currentTank.GetWeapon()); if (currentPlayer is PlayerController) { // give controls for firing a weapon currentPlayer.BeginTurn(this, currentGame); } else if (currentPlayer is AIOpponent) { //run the firing command on currentplayer currentPlayer.BeginTurn(this, currentGame); } }
private string weaponName = "Iron shell"; // used to storage the tank's weapon /// <summary> /// Fire a specified weapon from the tank /// </summary> /// <param name="weapon">Weapon selected</param> /// <param name="playerTank">The tank firing</param> /// <param name="currentGame">The current battle</param> public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float tankX; // used to storage the firing position of a tank float tankY; GenericPlayer firingPlayer; //used to storage owner of tank int damage, explosionRadius, earthDestruction; // get the current position of tank tankX = playerTank.GetX(); tankY = playerTank.Y(); // find the centre of tank by add half the width and height tankX = tankX + TankModel.WIDTH / 2; tankY = tankY + TankModel.HEIGHT / 2; // get the firing player of tank firingPlayer = playerTank.GetPlayerNumber(); // create new explosion Explosion basicExplosion; //set power of weapon damage = 100; // damage done by bullet explosionRadius = 4; //size of explosion earthDestruction = 4; //damage to area around explosion basicExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create new bullet Bullet basicBullet; basicBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.01f, //gravity basicExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(basicBullet); }
private void NewTurn() { GameplayTank tank = currentGame.GetCurrentGameplayTank(); GenericPlayer player = tank.GetPlayerNumber(); //Sets the form caption Text = String.Format("Tank Battle - Round {0} of {1}", currentGame.GetCurrentRound(), currentGame.GetRounds()); controlPanel.BackColor = player.GetColour(); playerLabel.Text = player.PlayerName(); SetAngle(tank.GetTankAngle()); SetForce(tank.GetTankPower()); int wind = currentGame.WindSpeed(); if (wind >= 0) { windLabel.Text = String.Format("{0} E", wind); } else { windLabel.Text = String.Format("{0} W", Math.Abs(wind)); } //Remove all the current selectable weapons and replace them with the current tanks weapons. weaponSelector.Items.Clear(); String[] weapons = tank.GetTank().ListWeapons(); foreach (String weapon in weapons) { weaponSelector.Items.Add(weapon); } //tank.SelectWeapon SelectWeapon(tank.GetCurrentWeapon()); player.NewTurn(this, currentGame); }
/// <summary> /// Fire a specified weapon from the tank /// </summary> /// <param name="weapon">Weapon selected</param> /// <param name="playerTank">The tank firing</param> /// <param name="currentGame">The current battle</param> public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float tankX; // used to storage the firing position of a tank float tankY; GenericPlayer firingPlayer; //used to storage owner of tank int damage, explosionRadius, earthDestruction; Random unaccurateShot = new Random(); // used to make the missles fly off course a bit // get the current position of tank tankX = playerTank.GetX(); tankY = playerTank.Y(); // find the centre of tank by add half the width and height tankX = tankX + TankModel.WIDTH / 2; tankY = tankY + TankModel.HEIGHT / 2; // get the firing player of tank firingPlayer = playerTank.GetPlayerNumber(); //set power of weapon damage = 80; // damage done by bullet explosionRadius = 4; //size of explosion earthDestruction = 4; //damage to area around explosion //check which sort of shot to fire; if ((WeaponChoice)weapon == WeaponChoice.IronShell) { //fire a normal shot //create a explosion for the shot Explosion basicExplosion; basicExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create new bullet Bullet basicBullet; basicBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.01f, //gravity basicExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(basicBullet); } if ((WeaponChoice)weapon == WeaponChoice.PierceShot) { //fire a shot which will pierce the first thing it hits and cause a second explosion //fire a piecre shot with a weaker strength int weakerStr = 60; int makePercentageOfOrginial = 100; //create a explosion for the shot Explosion pierceExplosion; pierceExplosion = new Explosion((damage * weakerStr) / makePercentageOfOrginial, (explosionRadius * weakerStr) / makePercentageOfOrginial, (earthDestruction * weakerStr) / makePercentageOfOrginial ); //create new bullet PierceBullet pierceBullet; pierceBullet = new PierceBullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.01f, //gravity pierceExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(pierceBullet); } }
/// <summary> /// Fire a specified weapon from the tank /// </summary> /// <param name="weapon">Weapon selected</param> /// <param name="playerTank">The tank firing</param> /// <param name="currentGame">The current battle</param> public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float tankX; // used to storage the firing position of a tank float tankY; GenericPlayer firingPlayer; //used to storage owner of tank int damage, explosionRadius, earthDestruction; Random unaccurateShot = new Random(); // used to make the missles fly off course a bit // get the current position of tank tankX = playerTank.GetX(); tankY = playerTank.Y(); // find the centre of tank by add half the width and height tankX = tankX + TankModel.WIDTH / 2; tankY = tankY + TankModel.HEIGHT / 2; // get the firing player of tank firingPlayer = playerTank.GetPlayerNumber(); //set power of weapon damage = 5; // damage done by bullet explosionRadius = 10; //size of explosion earthDestruction = 10; //damage to area around explosion //check which sort of shot to fire if ((WeaponChoice)weapon == WeaponChoice.BigBang) { //create a explosion for the bullet Explosion firstExplosion; firstExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create a bullet for the shot Bullet firstBullet; firstBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.03f, firstExplosion, playerTank.GetPlayerNumber() ); //add the bullet to the battle environment currentGame.AddEffect(firstBullet); } if ((WeaponChoice)weapon == WeaponChoice.SmallBangs) { //this weapon choice fires multiple 1-3 smaller bullets Random shotsFired = new Random(); int numberOfShots = shotsFired.Next(1, 4); //create a explosion for the bullet Explosion firstExplosion; //create a weaker shot than a normal shot int makeWeaker = 60; int makePertcentageOfOrginalValue = 100; firstExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue, (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue, (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue) ; //create a bullet for the shot Bullet firstBullet; firstBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.01f, firstExplosion, playerTank.GetPlayerNumber() ); //add the bullet to the battle environment currentGame.AddEffect(firstBullet); if (numberOfShots > 1) { //fire a second shot //create a explosion for the bullet Explosion secondExplosion; secondExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue, (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue, (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue) ; //create a bullet for the shot Bullet secondBullet; secondBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.015f, secondExplosion, playerTank.GetPlayerNumber() ); //add the bullet to the battle environment currentGame.AddEffect(secondBullet); } if (numberOfShots > 2) { //fire a third shot //create a explosion for the bullet Explosion thirdExplosion; thirdExplosion = new Explosion((damage * makeWeaker) / makePertcentageOfOrginalValue, (explosionRadius * makeWeaker) / makePertcentageOfOrginalValue, (earthDestruction * makeWeaker) / makePertcentageOfOrginalValue) ; //create a bullet for the shot Bullet thirdBullet; thirdBullet = new Bullet(tankX, tankY, playerTank.GetTankAngle(), playerTank.GetPower(), 0.02f, thirdExplosion, playerTank.GetPlayerNumber() ); //add the bullet to the battle environment currentGame.AddEffect(thirdBullet); } } }
/// <summary> /// Fire a specified weapon from the tank /// </summary> /// <param name="weapon">Weapon selected</param> /// <param name="playerTank">The tank firing</param> /// <param name="currentGame">The current battle</param> public override void ActivateWeapon(int weapon, GameplayTank playerTank, Battle currentGame) { float tankX; // used to storage the firing position of a tank float tankY; GenericPlayer firingPlayer; //used to storage owner of tank int damage, explosionRadius, earthDestruction; Random unaccurateShot = new Random(); // used to make the missles fly off course a bit // get the current position of tank tankX = playerTank.GetX(); tankY = playerTank.Y(); // find the centre of tank by add half the width and height tankX = tankX + TankModel.WIDTH / 2; tankY = tankY + TankModel.HEIGHT / 2; // get the firing player of tank firingPlayer = playerTank.GetPlayerNumber(); //set power of weapon damage = 50; // damage done by bullet explosionRadius = 3; //size of explosion earthDestruction = 2; //damage to area around explosion //check which sort of shot to fire if ((WeaponChoice)weapon == WeaponChoice.DoubleTap) { // fire two to semi accurate missiles // create explosions for missiles Explosion firstExplosion; Explosion secondExplosion; firstExplosion = new Explosion(damage, explosionRadius, earthDestruction); secondExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create new missile bullets Bullet firstMissile; Bullet secondMissile; firstMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-2, 3)), playerTank.GetPower() + (unaccurateShot.Next(-3, 4)), 0.01f, //gravity firstExplosion, firingPlayer) ; secondMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-2, 3)), playerTank.GetPower() + (unaccurateShot.Next(-3, 4)), 0.01f, //gravity secondExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(firstMissile); currentGame.AddEffect(secondMissile); } if ((WeaponChoice)weapon == WeaponChoice.Barrage) { // fire four missiles but they are very inaccurate shots //create explosions Explosion firstExplosion; Explosion secondExplosion; Explosion thridExplosion; Explosion fourthExplosion; firstExplosion = new Explosion(damage, explosionRadius, earthDestruction); secondExplosion = new Explosion(damage, explosionRadius, earthDestruction); thridExplosion = new Explosion(damage, explosionRadius, earthDestruction); fourthExplosion = new Explosion(damage, explosionRadius, earthDestruction); //create new missile bullets Bullet firstMissile; Bullet secondMissile; Bullet thridMissile; Bullet fourthMissile; firstMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)), playerTank.GetPower() + (unaccurateShot.Next(-4, 9)), 0.01f, //gravity firstExplosion, firingPlayer) ; secondMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)), playerTank.GetPower() + (unaccurateShot.Next(-4, 9)), 0.01f, //gravity secondExplosion, firingPlayer) ; thridMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)), playerTank.GetPower() + (unaccurateShot.Next(-4, 9)), 0.01f, //gravity thridExplosion, firingPlayer) ; fourthMissile = new Bullet(tankX, tankY, playerTank.GetTankAngle() + (unaccurateShot.Next(-4, 9)), playerTank.GetPower() + (unaccurateShot.Next(-4, 9)), 0.01f, //gravity fourthExplosion, firingPlayer) ; //add bullet to games current effects to continue flying through the environment currentGame.AddEffect(firstMissile); currentGame.AddEffect(secondMissile); currentGame.AddEffect(thridMissile); currentGame.AddEffect(fourthMissile); } }
/// <summary> /// allows the use of a keyboard to control the firing of a tank /// </summary> /// <param name="sender"></param> /// <param name="keypressed"></param> private void BattleForm_KeyDown(object sender, KeyEventArgs keypressed) { if (keypressed.KeyCode == Keys.Enter) { // if enter was hit then the player wants to fire their bullet if (controlPanel.Enabled) { //if a human player is active then allow a shot to be fired Fire(); } } if (keypressed.KeyCode == Keys.Left) { // if key pressed was left then reduce firing angle // but check it doesnt go outside bounds of -90 if (currentTank.GetTankAngle() - 5 >= -90) { currentTank.Aim(currentTank.GetTankAngle() - 5); currentTank.Paint(gameplayGraphics.Graphics, displayPanel.Size); } // update form with new angle angleUpDown.Value = (decimal)currentTank.GetTankAngle(); } if (keypressed.KeyCode == Keys.Right) { // if key pressed was right then increase firing angle //but check it doesn't go outsides bounds of 90 if (currentTank.GetTankAngle() + 5 <= 90) { currentTank.Aim(currentTank.GetTankAngle() + 5); currentTank.Paint(gameplayGraphics.Graphics, displayPanel.Size); } //update form with new angle angleUpDown.Value = (decimal)currentTank.GetTankAngle(); } if (keypressed.KeyCode == Keys.Up) { //if the key pressed was up then increase firing power // but check it doesn't go outside bounds of 100% if (currentTank.GetPower() + 2 <= 100) { currentTank.SetTankPower(currentTank.GetPower() + 2); } //update form with new power setting powerTrack.Value = (currentTank.GetPower()); powerLabel.Text = string.Format("Power: {0}", currentTank.GetPower()); } if (keypressed.KeyCode == Keys.Down) { //if the key pressed was up then decrease firing power // but check it doesn't go outside bounds of 0% if (currentTank.GetPower() - 1 >= 0) { currentTank.SetTankPower(currentTank.GetPower() - 2); } //update form with new power setting powerTrack.Value = (currentTank.GetPower()); powerLabel.Text = string.Format("Power: {0}", currentTank.GetPower()); } }