public void StartRound()
        {
            /// <summary>
            ///
            /// This method begins a new round of gameplay. A game consists of multiple rounds,
            /// and a round consists of multiple turns.
            ///
            /// </summary>

            Random rand = new Random();

            _playerLoc     = GetPlayerLocations(_numPlayers.Length);
            _currentPlayer = _startPlayer;
            _currentBattle = new Battlefield();
            _numTanks      = new ControlledTank[_numPlayers.Length];
            _wind          = rand.Next(-100, 100);

            foreach (TankController value in _numPlayers)
            {
                value.BeginRound();
            }
            Rearrange(_playerLoc);
            for (int i = 0; i < _numPlayers.Length; i++)
            {
                int xPos = _playerLoc[i];
                int yPos = _currentBattle.TankVerticalPosition(xPos);
                _numTanks[i] = new ControlledTank(_numPlayers[i], xPos, yPos, this);
            }
            BattleForm battle = new BattleForm(this);

            battle.Show();
            SetupForm setup = new SetupForm();

            setup.Show();
        }
Exemple #2
0
 public override void BeginTurn(BattleForm gameplayForm, Gameplay currentGame)
 {
     Console.WriteLine("ComputerBeginturnCalled");
     gameplayForm.ChangeWeapon(0);
     gameplayForm.AimTurret(rnd.Next(-66, 66));
     gameplayForm.SetForce(rnd.Next(20, 60));
 }
Exemple #3
0
 /// <summary>
 /// fires a shot from a tank
 /// </summary>
 /// <param name="aim"></param>
 /// <param name="firepower"></param>
 /// <param name="gameplay"></param>
 private void TakeAimAndFire(float aim, int firepower, BattleForm gameplay)
 {
     // set firepower and angle
     gameplay.Aim((float)aim);
     gameplay.SetTankPower(firepower);
     //fire the shot
     gameplay.Fire();
 }
        public override void NewTurn(BattleForm gameplayForm, Game currentGame)
        {
            /// <summary>
            ///
            /// This method is called when it's this player's turn. Because this player is human-controlled, this method calls EnableControlPanel() on the BattleForm passed to this method.
            ///
            /// </summary>

            gameplayForm.EnableControlPanel();
        }
Exemple #5
0
        /// <summary>
        /// function to fire a bad shot
        /// </summary>
        private void TakeACrappyShot(BattleForm gameplayForm)
        {
            // choose a random angle to fire at
            float randomAngle = (myRandom.Next(-90, 91));
            //choose a random firepwoer
            int randomFirepower = (myRandom.Next(10, 101));

            //fire shot
            TakeAimAndFire(randomAngle, randomFirepower, gameplayForm);
        }
Exemple #6
0
        /// <summary>
        /// Runs when a computer play gets a turn , works out how to fire shot depending on aiSetting
        /// </summary>
        /// <param name="gameplayForm"></param>
        /// <param name="currentGame"></param>
        public override void BeginTurn(BattleForm gameplayForm, Battle currentGame)
        {
            //grab the current fight
            currentFight = currentGame;

            if (aiSetting == difficulty.easy)
            {
                // this ai only knows how to fire and doesn't remember if it hits
                //take a random angle and power and fire
                TakeACrappyShot(gameplayForm);
            }
            else if (aiSetting == difficulty.medium)
            {
                //this ai knows how to fire , if it hit last time and where to shoot to hit a tank
                //check if last hit hit a player
                if (this.shotHit.Count() > 0 && this.shotHit.Last())
                {
                    // re aim for previous shot so it might still hit tank again
                    CalForWind(currentGame);
                    // fire shot
                    gameplayForm.Fire();
                    // remove entry to reset in case shot doesnt hit
                    this.shotHit.Clear();
                }
                else // didnt hit with last shot
                {
                    //grab the current wind speed
                    windOfLastTurn = currentGame.GetWind();
                    // work out which way to shoot
                    int    maxAngleFacing = 90;
                    int    minAngleFacing = -90;
                    int [] fireRange;
                    // check where the tank is , if it close to the edge make sure to fire to the inside of battlfeild
                    fireRange = CalMinAndMaxAngle(minAngleFacing, maxAngleFacing, currentGame);
                    //grab min and max from fireRange
                    minAngleFacing = fireRange[0];
                    maxAngleFacing = fireRange[1];
                    // choose a random angle to fire at
                    float randomAngle = (myRandom.Next(minAngleFacing, maxAngleFacing));
                    //choose a random firepwoer
                    int randomFirepower = (myRandom.Next(10, 101));
                    //fire shot
                    TakeAimAndFire(randomAngle, randomFirepower, gameplayForm);
                }
            }
            else if (aiSetting == difficulty.hard)
            {
                //stub
            }
        }
Exemple #7
0
        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();
        }
Exemple #8
0
        /// <summary>
        /// Begins a new round of gameplay , which consists of multiple turns
        /// </summary>
        public void StartRound()
        {
            int[] positions;

            int    minWindSpeed = -100;
            int    maxWindSPeed = 100;
            Random randomvalue  = new Random();

            currentPlayer  = startingPlayer; // sets the first turn to the starting player
            newBattlefield = new Battlefield();
            positions      = CalcPlayerLocations(Players.Length);

            foreach (GenericPlayer player in Players)
            {
                player.NewRound(); // setup each player for a new round
            }

            RandomReorder(positions);                                                         //shuffle array of positions
            Tanks = new GameplayTank[Players.Length];                                         // set the number of tanks to the number of players

            for (int i = 0; i < Tanks.Length; i++)                                            // initialising Tanks array
            {
                Tanks[i] = new GameplayTank(Players[i],                                       // the player
                                            positions[i],                                     // random Hoz position
                                            newBattlefield.PlaceTankVertically(positions[i]), // cals Vert position
                                            this                                              // reference to this class
                                            );
            }
            windSpeed       = randomvalue.Next(minWindSpeed, maxWindSPeed); // set the current windspeed
            roundBattleForm = new BattleForm(this);
            roundBattleForm.Show();
            // check to see if a player is human
            if (Players[currentPlayer] is PlayerController)
            {
                // activite controls for firing a weapon
                Players[currentPlayer].BeginTurn(roundBattleForm, this);
            }
        }
 public override void BeginTurn(BattleForm gameplayForm, Battle currentGame)
 {
     gameplayForm.EnableTankButtons(); // give player controls to fire
     gameplayForm.Focus();             // make sure the form has focus for keyboard controls
 }
Exemple #10
0
 public abstract void BeginTurn(BattleForm gameplayForm, Gameplay currentGame);
Exemple #11
0
 public override void BeginTurn(BattleForm gameplayForm, Gameplay currentGame)
 {
     gameplayForm.EnableTankButtons();
 }
 public override void NewTurn(BattleForm gameplayForm, Game currentGame)
 {
     throw new NotImplementedException();
 }