/// <summary> /// begins a new round of gameplay. A game consists of multiple rounds, and a round consists of multiple turns. /// </summary> public void CommenceRound() { //Initialising a private field of Battle representing the current player to the value of the starting GenericPlayer field (see NewGame). currentPlayer = startingGenericPlayer; //Creating a new Battlefield, which is also stored as a private field of Battle. battlefield = new Battlefield(); //Creating an array of GenericPlayer positions by calling CalculatePlayerPositions with the number of GenericPlayers playing the game int[] positions = CalculatePlayerPositions(GenericPlayers.Length); //Looping through each GenericPlayer and calling its BeginRound method. foreach (GenericPlayer genricPlayer in GenericPlayers) { genricPlayer.BeginRound(); //is only currently used for computer players } Rearrange(positions);//Shuffling that array of positions with the Rearrange method. GameplayTanks = new GameplayTank[GenericPlayers.Length]; for (int i = 0; i < GameplayTanks.Length; i++) { GameplayTanks[i] = new GameplayTank(GenericPlayers[i], positions[i], battlefield.TankVerticalPosition(positions[i]), this); } Random random = new Random(); windSpeed = random.Next(-100, 100); //create a wind that will be used to move the shell GameplayForm gameForm = new GameplayForm(this); gameForm.Show(); }
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(); }
/// <summary> /// Called when it's this player's turn. The player will need to call methods in gameplayForm /// such as SetWeaponIndex(), SetAimingAngle(), SetPower() and finally Attack() to aim and fire the weapon. /// /// Author John Santias October 2017 /// </summary> /// <param name="gameplayForm"></param> /// <param name="currentGame"></param> public override void BeginTurn(GameplayForm gameplayForm, Gameplay currentGame) { gameplayform = gameplayForm; gameplayform.SetWeaponIndex(1); float angle = rnd.Next(-90, 91); gameplayform.SetAimingAngle(angle); int power = rnd.Next(0, 101); gameplayForm.SetPower(power); gameplayForm.Attack(); }
public override void NewTurn(GameplayForm gameplayForm, Gameplay currentGame) { this.gameplayForm = gameplayForm; angle = rng.Next(angle_min, angle_max) * 5; gameplayForm.SetAngle(angle); power = rng.Next(5, 100); gameplayForm.SetPower(power); gameplayForm.SetWeapon(0); gameplayForm.Fire(); }
/// <summary> ///This method is called when it's this player's turn ///The player will need to call methods in gameplayForm ///such as SelectWeapon(), SetAngle(), SetForce() and finally Launch() to aim and fire the weapon. /// </summary> public override void NewTurn(GameplayForm gameplayForm, Battle currentGame) { GameplayTank gameplayTank = currentGame.GetCurrentGameplayTank(); int numPlayers = currentGame.NumPlayers(); //for each player find the first player who still exists and aim at them. //There has to be an easier way Random random = new Random(); int angle = random.Next(-90, 91); int power = random.Next(25, 101); gameplayForm.SetForce(power); gameplayForm.SetAngle(angle); gameplayForm.Launch(); }
/// <summary> /// Begins new round of gamplay. A game consists of multiple rounds and rounds consists of multiple /// turns. The method initialises the private field of Gameplay setting currentplayer to starting /// opponent. Creates new Terrain and an shuffled array of opponent's positions. Tanks are then placed /// on their positions. The wind speed of the game is set. /// Finally, the gameplay form is shown and game is ready to be played. /// /// Author John Santias September 2017 /// </summary> public void BeginRound() { currentPlayer = opponent; newTerrain = new Terrain(); int[] thepos = CalculatePlayerPositions(theOppo.Length); for (int i = 0; i < theOppo.Length - 1; i++) { theOppo[i].StartRound(); } Shuffle(thepos); theTank = new ControlledTank[theOppo.Length]; for (int i = 0; i < theTank.Length; i++) { theTank[i] = new ControlledTank(theOppo[i], thepos[i], newTerrain.TankYPosition(thepos[i]), this); } GetWindSpeed(); GameplayForm newForm = new GameplayForm(this); newForm.Show(); }
/// <summary> /// Sets the current player to the starting player /// Creates a new map /// populates a list of player positions and calls commence round on each player /// Shuffles the positions /// Createsa a list of battle tanks and stores the battle tanks in the list /// Sets the windspeed for the game /// Calsl teh gameplayForm and shows it /// Author Greyden Scott & Sean O'Connell October 2017 /// Written, edited and tested by both team members /// </summary> public void CommenceRound() { curr_player = start_player; arena = new Map(); //Setup players positions and change them about int [] positions = GetPlayerLocations(noPlayers.Length); for (int i = 0; i < noPlayers.Length; i++) { noPlayers[i].CommenceRound(); } Shuffle(positions); //Setup BattleTanks in their given positions battleTanks = new BattleTank[noPlayers.Length]; for (int i = 0; i < noPlayers.Length; i++) { int X_pos = positions[i]; int Y_pos = arena.TankYPosition(X_pos); battleTanks[i] = new BattleTank(noPlayers[i], X_pos, Y_pos, this); } wind = GetWindSpeed(); //Show Form GameplayForm gameplayForm = new GameplayForm(this); gameplayForm.Show(); }
public override void NewTurn(GameplayForm gameplayForm, Gameplay currentGame) { gameplayForm.EnableControlPanel(); }
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(); } }
/// <summary> /// Called when it's this player's turn. As this player is human-controlled, this method should /// call EnableTankButton() on the GameplayForm passed onto this method. /// /// Author John Santias September 2017 /// </summary> /// <param name="gameplayForm">The current gameplayform being used</param> /// <param name="currentGame">The current Game being played</param> public override void BeginTurn(GameplayForm gameplayForm, Gameplay currentGame) { gameplayForm.EnableTankButtons(); }
/// <summary> /// Implemented by the AIOpponent and HumanOpponent classes, called when it's this player's turn to /// move. /// </summary> /// <param name="gameplayForm">The current gameplayForm thats being used</param> /// <param name="currentGame">The current Game being played</param> public abstract void BeginTurn(GameplayForm gameplayForm, Gameplay currentGame);
public abstract void NewTurn(GameplayForm gameplayForm, Battle currentGame);
public abstract void BeginTurn(GameplayForm gameplayForm, GameController currentGame);
/// <summary> /// Allows the current player to control the gamePlayform /// </summary> /// <param name="gameplayForm">The form the player interacts with</param> /// <param name="currentGame">Not used by human player</param> public override void NewTurn(GameplayForm gameplayForm, Battle currentGame) { gameplayForm.EnableTankControls(); }
public override void BeginTurn(GameplayForm gameplayForm, GameController currentGame) { // Enabling the Control Panel gameplayForm.EnableHumanControl(); }