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); }
public bool CheckCollidedTank(float projectileX, float projectileY) { if (projectileX < 0 || projectileY < 0 || projectileX > Battlefield.WIDTH || projectileY > Battlefield.HEIGHT) { return(false); } if (map.IsTileAt((int)projectileX, (int)projectileY)) { return(true); } for (int i = 0; i < Playertanks.Length; i++) { current_tank = Playertanks[i]; if (i == currentplayer) { return(false); } int current_tankY = current_tank.GetY(); int current_tankX = current_tank.XPos(); int current_tankRight = current_tankX + Chassis.WIDTH; int current_tankBott = current_tankY + Chassis.HEIGHT; if (projectileX >= current_tankX && projectileX <= current_tankRight) { if (projectileY >= current_tankY && projectileY <= current_tankBott) { return(true); } } } return(false); }
public void CommenceRound() { // Initialising variables to begin a round currentPlayer = tankStart; tankBattlefield = new Battlefield(); int[] tankConstPositions = GetPlayerPositions(playersCount); foreach (TankController x in playersArray) { x.BeginRound(); } // Shuffling the tank position array to randomise spawn Shuffle(tankConstPositions); playerTankArray = new PlayerTank[playersCount]; for (int i = 0; i < playersCount; i++) { playerTankArray[i] = new PlayerTank(playersArray[i], tankConstPositions[i], tankBattlefield.TankVerticalPosition(tankConstPositions[i]), this); } // Initiating wind speed Random rand = new Random(); windSpeed = rand.Next(-100, 100); //GameplayForm newForm = new GameplayForm(this); newForm = new GameplayForm(this); newForm.Show(); }
public void StartRound() { currentPlayer = startingController; map = new Map(); vPlayerTanks = new PlayerTank[100]; int[] tankControllerPositions = CalcPlayerLocations(vTankControllers.Count()); for (int i = 0; i < vTankControllers.Count(); i++) { if (vTankControllers[i] != null) { vTankControllers[i].NewRound(); RandomReorder(tankControllerPositions); int horizontalTankPos = tankControllerPositions[i]; int verticalTankPos = map.TankPlace(horizontalTankPos); PlayerTank player = new PlayerTank(vTankControllers[i], horizontalTankPos, verticalTankPos, this); vPlayerTanks[i] = player; } else { //when i meet the first null i break the cicle cause that means //there are not other tankController in the array break; } } Random nRandom = new Random(); windSpeed = nRandom.Next(-100, 100); GameForm gf = new GameForm(this); gf.Show(); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { PlayerTank currentTankPlayer = currentGame.GetPlayerTank(); currentTankPlayer.SetWeaponIndex(currentTankPlayer.GetCurrentWeapon()); displayPanel.Invalidate(); }
public void Launch() { PlayerTank player = currentGame.CurrentPlayerTank(); player.Launch(); controlPanel.Enabled = false; timer.Enabled = true; }
private void trackBar1_Scroll(object sender, EventArgs e) { PlayerTank currentTankPlayer = currentGame.GetPlayerTank(); currentTankPlayer.SetPower(trackBar1.Value); label7.Text = trackBar1.Value.ToString(); displayPanel.Invalidate(); }
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; }
private void numericUpDown1_ValueChanged(object sender, EventArgs e) { PlayerTank currentTankPlayer = currentGame.GetPlayerTank(); currentTankPlayer.AimTurret((float)numericUpDown1.Value); DrawGameplay(); displayPanel.Invalidate(); }
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); }
protected void NewTurn() { //<Summary> //Alex Holm N9918205 //</Summary> Debug.WriteLine("CurrentTank Get Start"); current_tank = currentGame.GetCurrentPlayerTank(); Debug.WriteLine("CurrentTank Get Finalized"); Debug.WriteLine("CurrentPlayer Get Start"); current_player = current_tank.GetPlayer(); Debug.WriteLine("CurrentTank Get Finalized"); Debug.WriteLine("CurrentForm Title Get Start"); string Title = ("Tank Battle - Round " + currentGame.CurrentRound() + " of " + currentGame.GetMaxRounds()); this.Text = Title; Debug.WriteLine("CurrentForm Title Get Finalized"); Debug.WriteLine("Current Player colour to control panel start"); controlPanel.BackColor = current_player.GetColour(); Debug.WriteLine("Current player colour to control panel done"); PlayerLabel.Text = current_player.Identifier(); AimTurret(current_tank.GetAngle()); PowerIndicatorLabel.Text = current_tank.GetPower().ToString(); SetForce(current_tank.GetPower()); if (currentGame.WindSpeed() > 0) { Wind.Text = currentGame.WindSpeed().ToString() + " E"; } else { Wind.Text = Math.Abs(currentGame.WindSpeed()).ToString() + " W"; } weaponComboBox.Items.Clear(); Chassis current_chassiss = current_tank.GetTank(); foreach (String weapon in current_chassiss.Weapons()) { weaponComboBox.Items.Add(weapon); } ChangeWeapon(weaponComboBox.SelectedIndex); current_player.BeginTurn(this, currentGame); Debug.WriteLine("Newturn"); }
public override void WeaponLaunch(int weapon, PlayerTank playerTank, Gameplay currentGame) { Debug.WriteLine("Chassis WeaponLaunch Start"); //Alex Holm N9918205 float x = (playerTank.XPos()); float y = (playerTank.GetY()); x += (Chassis.WIDTH) / 2; y += (Chassis.HEIGHT) / 2; Opponent player = playerTank.GetPlayer(); Shrapnel shrap = new Shrapnel(100, 4, 4); Shell Std_shell = new Shell(x, y, playerTank.GetAngle(), playerTank.GetPower(), 0.01f, shrap, player); currentGame.AddEffect(Std_shell); Debug.WriteLine("Chassis WeaponLaunch Complete"); }
private void GameplayForm_KeyDown(object sender, KeyEventArgs e) { PlayerTank currentTankPlayer = currentGame.GetPlayerTank(); // Left Key if (e.KeyCode == Keys.Left) { if (numericUpDown1.Value > -90) { numericUpDown1.Value--; } currentTankPlayer.AimTurret((float)numericUpDown1.Value); } // Right Key else if (e.KeyCode == Keys.Right) { if (numericUpDown1.Value < 90) { numericUpDown1.Value++; } currentTankPlayer.AimTurret((float)numericUpDown1.Value); } // Up Key else if (e.KeyCode == Keys.Up) { if (trackBar1.Value < 100) { trackBar1.Value++; label7.Text = trackBar1.Value.ToString(); } currentTankPlayer.SetPower(trackBar1.Value); } //Down Key else if (e.KeyCode == Keys.Down) { if (trackBar1.Value > 5) { trackBar1.Value--; label7.Text = trackBar1.Value.ToString(); } currentTankPlayer.SetPower(trackBar1.Value); } DrawGameplay(); displayPanel.Invalidate(); }
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 void BeginRound() { //<Summary> //Alex Holm N9918205 //</summary> Debug.WriteLine("Begin Begin Round"); //Initialising a private field of Gameplay representing the current player to the value of the starting Opponent field(see CommenceGame). Debug.WriteLine("Currentplayer = starting player" + currentplayer + ":" + startingplayer); currentplayer = startingplayer; Debug.WriteLine("Currentplayer = starting player" + currentplayer + ":" + startingplayer); //Creating a new Battlefield, which is also stored as a private field of Gameplay. map = new Battlefield(); //Creating an array of Opponent positions by calling GetPlayerPositions with the number of Opponents playing the game(hint: get the length of the Opponents array playerpos = GetPlayerPositions(opponents.Length); //Looping through each Opponent and calling its StartRound method. for (int i = 0; i < opponents.Length; i++) { opponents[i].StartRound(); } //Shuffling that array of positions with the RandomReorder method. RandomReorder(playerpos); //Creating an array of PlayerTank as a private field.There should be the same number of PlayerTanks as there are Opponents in the Opponent array. Playertanks = new PlayerTank[opponents.Length]; //Initialising the array of PlayerTank by finding the horizontal position of the PlayerTank //(by looking up the appropriate index of the array returned by GetPlayerPositions and shuffled with the RandomReorder method) //the vertical position of the PlayerTank(by calling TankYPosition() on the Battlefield with the horizontal position as an argument) //and then calling PlayerTank's constructor to create that PlayerTank (passing in the appropriate Opponent, the horizontal position, the vertical position and a reference to this) for (int i = 0; i < playerpos.Length; i++) { Playertanks[i] = new PlayerTank(opponents[i], playerpos[i], map.TankYPosition(playerpos[i]), this); } //Initialising the wind speed, another private field of Gameplay, to a random number between -100 and 100. WindSpeed(); //Creating a new BattleForm and Show()ing it. BattleForm Form = new BattleForm(this); Form.Show(); }
public abstract void WeaponLaunch(int weapon, PlayerTank playerTank, Gameplay currentGame);
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 abstract void FireWeapon(int weapon, PlayerTank playerTank, GameController currentGame);