コード例 #1
0
        public Winner(Battle game)
        {
            InitializeComponent();
            int    highscore = 0;
            String winner    = "";

            //for every player in the battle find out their score
            GenericPlayer[] genericPlayers = new GenericPlayer[game.NumPlayers()];

            for (int i = 0; i < genericPlayers.Length; i++)
            {
                GenericPlayer gp = game.GetPlayerNumber(i + 1);
                if (gp.GetScore() > highscore)
                {
                    highscore = gp.GetScore();
                    winner    = String.Format("{0} won!", gp.PlayerName());
                }
                else if (gp.GetScore() == highscore)
                {
                    winner = "Tie!";
                }
                playerWon.Text = winner;
                listBox.Items.Add(String.Format("{0} ({1} Wins)", gp.PlayerName(), gp.GetScore()));
            }
        }
コード例 #2
0
        /// <summary>
        /// checks if a bullet is about to hit the tank that shot it
        /// </summary>
        /// <param name="owner">who owns the shot</param>
        /// <param name="x"> the location of explosion</param>
        /// <returns></returns>
        private bool CheckPlayerOwner(GenericPlayer owner, int x)
        {
            bool hittingSelf = false;

            for (int playerNum = 1; playerNum <= this.currrentGame.NumPlayers(); playerNum++)
            {
                // check the x of each player against the owner of bullet
                for (int rangeCheck = 0; rangeCheck < 5; rangeCheck++)
                {
                    if (this.currrentGame.GetBattleTank(playerNum).GetX() == x - rangeCheck ||
                        this.currrentGame.GetBattleTank(playerNum).GetX() == x + rangeCheck)
                    {
                        //this player is near the x value
                        //check player isnt owner
                        if (this.currrentGame.GetPlayerNumber(playerNum) == owner)
                        {
                            hittingSelf = true;
                            return(hittingSelf);
                        }
                    }
                }
            }

            return(hittingSelf);
        }
コード例 #3
0
        private void NewTurn()
        {
            BattleTank    player         = currentGame.CurrentPlayerTank();
            GenericPlayer tankController = player.GetPlayerById();

            this.Text          = "Tank Battle - Round " + currentGame.GetCurrentRound() + "of " + currentGame.GetRounds();
            BackColor          = tankController.GetTankColour();
            lblPlayerName.Text = tankController.Identifier();
            Aim(player.GetPlayerAngle());
            SetTankPower(player.GetPower());
            if (currentGame.WindSpeed() > 0)
            {
                lblWindValue.Text = currentGame.WindSpeed() + " E";
            }
            else
            {
                lblWindValue.Text = currentGame.WindSpeed() * -1 + " W";
            }
            scrollWeapon.Items.Clear();
            TankModel tank = player.CreateTank();

            String[] lWeaponsAvailable = tank.ListWeapons();
            scrollWeapon.Items.AddRange(lWeaponsAvailable);
            SetWeaponIndex(player.GetCurrentWeapon());
            tankController.BeginTurn(this, currentGame);
        }
コード例 #4
0
        public override void FireWeapon(int weapon, BattleTank playerTank, Game currentGame)
        {
            int           x          = playerTank.GetX();
            int           y          = playerTank.YPos();
            float         xPos       = (float)x + (TankModel.HEIGHT / 2);
            float         yPos       = (float)y + (TankModel.WIDTH / 2);
            GenericPlayer player     = playerTank.GetPlayerById();
            Boom          explosion  = new Boom(100, 4, 4);
            Bullet        projectile = new Bullet(xPos, yPos, playerTank.GetPlayerAngle(), playerTank.GetPower(), 0.01f, explosion, player);

            currentGame.AddEffect(projectile);
        }
コード例 #5
0
        /// <summary>
        /// This constructor stores player, tankX, tankY and game as private fields of GameplayTank.
        /// It then gets the Chassis by using the GenericPlayer's GetTank() method,
        /// then calls GetTankArmour() on it and stores this as the GameplayTank's current durability.
        /// This will go down as the tank takes damage.
        /// </summary>
        /// <param name="player">the player using the tank</param>
        /// <param name="tankX">coordinate</param>
        /// <param name="tankY">coordinate</param>
        /// <param name="game">the battle the tank is apart of</param>
        public GameplayTank(GenericPlayer player, int tankX, int tankY, Battle game)
        {
            this.player = player;
            this.tankX  = tankX;
            this.tankY  = tankY;
            this.game   = game;

            durability    = player.GetTank().GetTankArmour();
            angle         = 0;
            power         = 25;
            currentWeapon = 0;

            tankBitmap = player.GetTank().CreateTankBMP(player.GetColour(), angle);
        }
コード例 #6
0
        /// <summary>
        /// Constructs a new Shell.
        /// </summary>
        /// <param name="x">the x coordinate of the tank</param>
        /// <param name="y">y position of the tank</param>
        /// <param name="angle">angle shell is leaving</param>
        /// <param name="power">power of the shell</param>
        /// <param name="gravity">The gravity the shell experiences</param>
        /// <param name="explosion">the explosion to produce</param>
        /// <param name="player">the player who fired the shell</param>
        public Shell(float x, float y, float angle, float power, float gravity, Boom explosion, GenericPlayer player)
        {
            this.x         = x;
            this.y         = y;
            this.gravity   = gravity;
            this.explosion = explosion;
            this.player    = player;

            float angleRadians = (90 - angle) * (float)Math.PI / 180;
            float magnitude    = power / 50;

            //use the angle to determine which way to send the shell
            xVelocity = (float)Math.Cos(angleRadians) * magnitude;
            yVelocity = (float)Math.Sin(angleRadians) * -magnitude;
        }
コード例 #7
0
        public Bullet(float x, float y, float angle, float power, float gravity, Boom explosion, GenericPlayer 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;
        }
コード例 #8
0
        private void NewTurn()
        {
            // find the next player and their tank
            currentTank   = currentGame.GetPlayerTank();
            currentPlayer = currentTank.GetPlayerNumber();
            //set the title of a form to current round of total rounds
            this.Text = string.Format("Tank battle - Round {0} of {1}", currentGame.CurrentRound(), currentGame.GetNumRounds());
            // set backcolor of controlpanel to currentplayers colour
            controlPanel.BackColor = currentPlayer.PlayerColour();
            // show the current player's name
            currentPlayerLabel.Text = currentPlayer.Name();
            // set angle to current gameplaytank's angle
            this.Aim(currentTank.GetTankAngle());
            //show current tank's power
            this.SetTankPower(currentTank.GetPower());
            //show current windspeed
            //postive values should state its a eastly wind while negative values come from windly west
            if (currentGame.GetWind() >= 0)
            {
                windspeedLabel.Text = string.Format("{0} E", currentGame.GetWind());
            }
            else
            {
                windspeedLabel.Text = string.Format("{0} W", (currentGame.GetWind() * -1)); // times by a negative number to shows a flat value for wind
            }
            //clear weapon choices in weaponSelect
            weaponSelect.Items.Clear();
            // find all weapons available to current tank
            foreach (string weapon in currentTank.GetTank().ListWeapons())
            {
                // add each weapon to selection choice of weaponSelect
                weaponSelect.Items.Add(weapon);
            }
            //set the current weapon to be used of current tank
            SetWeapon(currentTank.GetWeapon());

            if (currentPlayer is PlayerController)
            {
                // give controls for firing a weapon
                currentPlayer.BeginTurn(this, currentGame);
            }
            else if (currentPlayer is AIOpponent)
            {
                //run the firing command on currentplayer
                currentPlayer.BeginTurn(this, currentGame);
            }
        }
コード例 #9
0
        private float velocityY;           // how fast the bullet is moving

        /// <summary>
        /// creates a new bullet projectile
        /// </summary>
        /// <param name="x">Starting X coordinate position</param>
        /// <param name="y">Starting Y coordinate position</param>
        /// <param name="angle">Firing angle from tank</param>
        /// <param name="power">Firing power from tank</param>
        /// <param name="gravity">current gravity on battlefield</param>
        /// <param name="explosion">explosion that occurs when bullet hits</param>
        /// <param name="player">firing player</param>
        public Bullet(float x, float y, float angle, float power, float gravity, Explosion explosion, GenericPlayer player)
        {
            // set default values of the new bullet
            bulletX         = x;
            bulletY         = y;
            bulletGravity   = gravity;
            bulletExplosion = explosion;
            bulletOwner     = player;
            // now work out how fast this bullet is moving
            // workout direction and quickness of bullet
            float angleRadians = (90 - angle) * (float)Math.PI / 180; // direction of bullet
            float magnitude    = power / 50;                          // movement vector of bullet

            // calculate velocity of the projectile
            velocityX = (float)Math.Cos(angleRadians) * magnitude;
            velocityY = (float)Math.Sin(angleRadians) * -magnitude;
        }
コード例 #10
0
ファイル: GameplayTank.cs プロジェクト: AdamBanham/TankFight
 /// <summary>
 ///  creates a new tank for a player
 /// </summary>
 /// <param name="player">The owner of new tank</param>
 /// <param name="tankX">Starting X coordinate of new tank</param>
 /// <param name="tankY">Starting Y coordinate of new tank</param>
 /// <param name="game">The current battle</param>
 public GameplayTank(GenericPlayer player, int tankX, int tankY, Battle game)
 {
     //sets up the default values of tank via passed information in constructor
     tanksPlayer = player;
     tankPosX    = tankX;
     tankPosY    = tankY;
     tankInGame  = game;
     //find the tank model via player
     tanksModel = tanksPlayer.GetTank();
     //gets the health of said model
     tankDurbility = tanksModel.GetTankHealth();
     //set the default values for angle , power and weapon
     currentAngle  = 0f;
     currentPower  = 25;
     currentWeapon = 0;
     //draw tank on feild of battle and save bitmap to class
     tankBmp = tanksModel.CreateTankBMP(tanksPlayer.PlayerColour(), currentAngle);
 }
コード例 #11
0
        public BattleTank(GenericPlayer player, int tankX, int tankY, Game game)
        {
            //setting up the values we recieve to the variables in this class
            this.tPlayer = player;
            this.xCoord  = tankX;
            this.yCoord  = tankY;
            this.tGame   = game;
            this.tPower  = 25;
            this.tAngle  = 0;
            this.tWeapon = 0;

            //creating a tank, getting color, setting angle and getting armour
            //seems like the order of things is very important
            //was failing tests coz of the null excpetion, took me couple of hours
            //to understand that it needs to be re-ordered.
            this.tTank   = tPlayer.CreateTank();
            this.tankBMP = tTank.CreateBMP(tPlayer.GetTankColour(), this.tAngle);
            this.health  = tTank.GetArmour();
        }
コード例 #12
0
ファイル: coolTank.cs プロジェクト: garaxer/QUT-CAB201
        /// <summary>
        /// used to handle firing the specified weapon from the tank playerTank.
        /// </summary>
        /// <param name="weapon">The weapon chosen from ListWeapons</param>
        /// <param name="playerTank">The tank that is shooting the weapons</param>
        /// <param name="currentGame">The battle the shot takes place in</param>
        public override void ShootWeapon(int weapon, GameplayTank playerTank, Battle currentGame)
        {
            float x = playerTank.XPos();
            float y = playerTank.GetY();

            //find the center of the tank
            x = x + Chassis.WIDTH / 2;
            y = y + Chassis.HEIGHT / 2;

            GenericPlayer player = playerTank.GetPlayerNumber();
            Boom          boom   = new Boom(100, 4, 4);
            Shell         shell  = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower(), 0.01f, boom, player);
            Shell         shell2 = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower() + 10, 0.01f, boom, player);
            Shell         shell3 = new Shell(x, y, playerTank.GetTankAngle(), playerTank.GetTankPower() - 10, 0.01f, boom, player);

            currentGame.AddWeaponEffect(shell);
            currentGame.AddWeaponEffect(shell2);
            currentGame.AddWeaponEffect(shell3);
        }
コード例 #13
0
        private void NewTurn()
        {
            GameplayTank  tank   = currentGame.GetCurrentGameplayTank();
            GenericPlayer player = tank.GetPlayerNumber();

            //Sets the form caption
            Text = String.Format("Tank Battle - Round {0} of {1}", currentGame.GetCurrentRound(), currentGame.GetRounds());

            controlPanel.BackColor = player.GetColour();

            playerLabel.Text = player.PlayerName();

            SetAngle(tank.GetTankAngle());
            SetForce(tank.GetTankPower());

            int wind = currentGame.WindSpeed();

            if (wind >= 0)
            {
                windLabel.Text = String.Format("{0} E", wind);
            }
            else
            {
                windLabel.Text = String.Format("{0} W", Math.Abs(wind));
            }

            //Remove all the current selectable weapons and replace them with the current tanks weapons.
            weaponSelector.Items.Clear();
            String[] weapons = tank.GetTank().ListWeapons();
            foreach (String weapon in weapons)
            {
                weaponSelector.Items.Add(weapon);
            }
            //tank.SelectWeapon
            SelectWeapon(tank.GetCurrentWeapon());

            player.NewTurn(this, currentGame);
        }
コード例 #14
0
ファイル: Battle.cs プロジェクト: AdamBanham/TankFight
 /// <summary>
 /// sets which slot the player is in the players array
 /// </summary>
 /// <param name="playerNum"></param>
 /// <param name="player"></param>
 public void SetPlayer(int playerNum, GenericPlayer player)
 {
     // set the player in the players array , playerNum is indexed from 1 must be reduced by one to set in array which is indexed from 0
     Players[playerNum - 1] = player;
 }
コード例 #15
0
ファイル: Battle.cs プロジェクト: garaxer/QUT-CAB201
 /// <summary>
 /// Adds a player to the game
 /// </summary>
 /// <param name="playerNum">Which position the player is in. Player num must be between 1 and the number of players</param>
 /// <param name="player">The player to add the player array</param>
 public void RegisterPlayer(int playerNum, GenericPlayer player)
 {
     GenericPlayers[playerNum - 1] = player;
 }
コード例 #16
0
 //setting the player model based on the number recievd -1 because the array starts from 0
 public void SetPlayer(int playerNum, GenericPlayer player)
 {
     this.modelPlayerController[playerNum - 1] = player;
 }