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 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 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(); } }