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; }
private void NewTurn() { PlayerTank player = currentGame.CurrentPlayerTank(); TankController tankController = player.Player(); this.Text = "Tank Battle - Round " + currentGame.CurrentRound() + "of " + currentGame.GetTotalRounds(); BackColor = tankController.PlayerColour(); lblPlayerName.Text = tankController.Identifier(); SetAimingAngle(player.GetTankAngle()); SetPower(player.GetTankPower()); if (currentGame.Wind() > 0) { lblWindValue.Text = currentGame.Wind() + " E"; } else { lblWindValue.Text = currentGame.Wind() * -1 + " W"; } cmbWeapon.Items.Clear(); Tank tank = player.CreateTank(); String[] lWeaponsAvailable = tank.ListWeapons(); cmbWeapon.Items.AddRange(lWeaponsAvailable); ChangeWeapon(player.GetCurrentWeapon()); tankController.StartTurn(this, currentGame); }
//Add new player to the array //playerNum - 1 because array index start from 0 public void SetPlayer(int playerNum, TankController player) { if (playerNum >= 1 && playerNum <= numPlayers) { vTankControllers[playerNum - 1] = player; } }
private void NewTurn() { //throw new NotImplementedException(); //currentGame.GetPlayerTank().GetPlayerById(); PlayerTank currentTankPlayer = currentGame.GetPlayerTank(); TankController currentId = currentTankPlayer.GetPlayerById(); // Setting Form Title Caption to Current Round this.Text = "Tank Battle - Round " + currentGame.CurrentRound() + " of " + currentGame.GetMaxRounds(); // Set back color of control panel controlPanel.BackColor = currentId.GetTankColour(); // Set player name to tank name label1.Text = currentId.Identifier(); // Call AimTurret() to set current angle AimTurret(currentTankPlayer.GetPlayerAngle()); // Call SetPower() to set current power SetPower(currentTankPlayer.GetTankPower()); label7.Text = trackBar1.Value.ToString(); // Updating wind label if (currentGame.WindSpeed() < 0) { label3.Text = currentGame.WindSpeed() + "W"; } else { label3.Text = currentGame.WindSpeed() + "E"; } // Clearing Combobox comboBox1.Items.Clear(); // Adding to the Combobox foreach (string x in currentTankPlayer.CreateTank().WeaponList()) { comboBox1.Items.Add(x); } // Setting the current weapon to the current player SetWeaponIndex(currentTankPlayer.GetCurrentWeapon()); // Calling BeginTurn() currentId.BeginTurn(this, currentGame); /* * button1.TabStop = false; * comboBox1.TabStop = false; * numericUpDown1.TabStop = false; * trackBar1.TabStop = false;*/ label7.Text = trackBar1.Value.ToString(); debounce = 0; }
public void SetPlayer(int playerNum, TankController player) { /// <summary> /// /// This method takes a player number(guaranteed to be between 1 and the number of players) /// and sets the appropriate field in Game's TankController array to player. /// /// </summary> _numPlayers[playerNum - 1] = player; //-1 accounts for array index }
public override void FireWeapon(int weapon, PlayerTank playerTank, Game currentGame) { int x = playerTank.X(); int y = playerTank.Y(); float xPos = (float)x + (Tank.HEIGHT / 2); float yPos = (float)y + (Tank.WIDTH / 2); TankController player = playerTank.Player(); Explosion explosion = new Explosion(100, 4, 4); Projectile projectile = new Projectile(xPos, yPos, playerTank.GetTankAngle(), playerTank.GetTankPower(), 0.01f, explosion, player); currentGame.AddWeaponEffect(projectile); }
public Projectile(float x, float y, float angle, float power, float gravity, Shrapnel explosion, TankController player) { // Initialising the projectile properties xPos = x; yPos = y; graV = gravity; exP = explosion; tankPlayer = player; float angleRadians = (90 - angle) * (float)Math.PI / 180; float magnitude = power / 50; xVel = (float)Math.Cos(angleRadians) * magnitude; yVel = (float)Math.Sin(angleRadians) * -magnitude; }
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); }
public Projectile(float x, float y, float angle, float power, float gravity, Explosion explosion, TankController player) { this.angle = angle; this.power = power; this.gravity = gravity; this.explosion = explosion; this.player = player; this.x = x; this.y = y; float angleRadiant = (90 - angle) * (float)Math.PI / 180; float magnitude = power / 50; this.xVelocity = (float)Math.Cos(angleRadiant) * magnitude; this.yVelocity = (float)Math.Sin(angleRadiant) * magnitude; }
public PlayerTank(TankController player, int tankX, int tankY, GameController game) { // Initialising the player, tank coordinates, and tankGame fields tankPlayer = player; tankXPos = tankX; tankYPos = tankY; tankGame = game; tank = player.CreateTank(); currentDurability = tank.GetHealth(); tankAngle = 0; tankPower = 25; currentWeap = 0; tankBMP = tank.CreateTankBMP(tankPlayer.GetTankColour(), tankAngle); }
public override void FireWeapon(int weapon, PlayerTank playerTank, GameController currentGame) { // Firing the specified weapon from playerTank float xPos = playerTank.GetX(); float yPos = playerTank.GetYPos(); xPos += Chassis.WIDTH / 2; yPos += Chassis.HEIGHT / 2; TankController tankContr = playerTank.GetPlayerById(); Shrapnel newShrapnel = new Shrapnel(100, 4, 4); Projectile newProj = new Projectile(xPos, yPos, playerTank.GetPlayerAngle(), playerTank.GetTankPower(), 0.01f, newShrapnel, tankContr); currentGame.AddEffect(newProj); }
public Bullet(float x, float y, float angle, float power, float gravity, Explosion explosion, TankController player) { /// <summary> /// /// This method constructs a new Bullet. The x, y, gravity, explosion /// and player fields should all be stored in private fields of Bullet. /// /// </summary> _x = x; _y = y; _explosion = explosion; _player = player; _gravity = gravity; float angleRadians = (90 - angle) * (float)Math.PI / 180; float magnitude = power / 50; _xVelocity = (float)Math.Cos(angleRadians) * magnitude; _yVelocity = (float)Math.Sin(angleRadians) * -magnitude; }
private void NewTurn() { /// <summary> /// /// This newly-created method is used to update form elements to reflect who the current player is. /// /// </summary> ControlledTank _tank = currentGame.GetPlayerTank(); Tank _type = _tank.GetTank(); TankController _player = _tank.GetPlayerById(); float angle = _tank.GetTankAngle(); int power = _tank.GetTankPower(); Text = "Round" + currentGame.GetCurrentRound() + "of" + currentGame.GetCurrentRound(); BackColor = _player.TankColour(); Player.Text = _player.Name(); SetAimingAngle(angle); SetPower(power); if (currentGame.Wind() >= 0) { WindSpeed.Text = currentGame.Wind() + "E"; } else { WindSpeed.Text = currentGame.Wind() + "W"; } WeaponSelect.Items.Clear(); string[] avaliableWeapons = _type.ListWeapons(); for (int i = 0; i < avaliableWeapons.Length; i++) { WeaponSelect.Items.Add(avaliableWeapons[i]); } SelectWeapon(WeaponSelect.SelectedIndex); _player.NewTurn(this, currentGame); }
public Bullet(float x, float y, float angle, float power, float gravity, Boom explosion, TankController player) { throw new NotImplementedException(); }
public override void BeginTurn(GameplayForm gameplayForm, GameController currentGame) { // Initiating random function Random rand = new Random(); PlayerTank currentTankPlayer = currentGame.GetPlayerTank(); TankController currentId = currentTankPlayer.GetPlayerById(); int posX, posY; int[] playerPositions; int numX; posX = currentTankPlayer.GetX(); posY = currentTankPlayer.GetYPos(); // Initiating list for easier removal of players (!Exist()) playerPositions = GameController.GetPlayerPositions(currentGame.TotalPlayers()); List <int> playerPos = new List <int>(playerPositions); // Removing players that don't exist for (int i = 0; i < playerPos.Count; i++) { if (!currentGame.GetGameplayTank(i + 1).Exists()) { playerPos.Remove(currentGame.GetGameplayTank(i + 1).GetX()); } } // Calculating the closest tank to the current PlayerTank int distance = Math.Abs(playerPos[0] - posX); int idx = 0; for (int i = 1; i < playerPos.Count; i++) { int cdistance = Math.Abs(playerPos[i] - posX); if (cdistance < distance && playerPos[i] != posX) { idx = i; distance = cdistance; } } numX = playerPos[idx]; /* * // Testing to see the tank position stuff * Console.WriteLine("Current Tank:"); * Console.WriteLine(posX); * Console.WriteLine("Closest Tank Position:"); * Console.WriteLine(numX); * Console.WriteLine("Tank Positions:"); * for (int i = 0; i < playerPos.Count; i++) * { * Console.WriteLine(playerPos[i]); * }*/ // Aiming the turret in the direction of the closest tank if (numX < posX) { gameplayForm.AimTurret(rand.Next(-90, -10)); } else { gameplayForm.AimTurret(rand.Next(10, 90)); } // Setting tank power to a random number gameplayForm.SetPower(rand.Next(5, 100)); // Making the tank to fire if (currentTankPlayer.Exists()) { gameplayForm.Fire(); } }
public void RegisterPlayer(int playerNum, TankController player) { throw new NotImplementedException(); }
public void SetPlayer(int playerNum, TankController player) { // Setting appropriate field in TankController array to player playersArray[playerNum - 1] = player; }
public BattleTank(TankController player, int tankX, int tankY, GameController game) { throw new NotImplementedException(); }