Пример #1
0
 /// <summary>
 /// The constructor that passes the opponent's name, TankModel and colour. These values are stored
 /// as private members of Opponent.
 ///
 /// Author John Santias and Hoang Nguyen September 2017
 /// </summary>
 /// <param name="name">The name of the opponent</param>
 /// <param name="tank">The opponent's tank model</param>
 /// <param name="colour">The colour associated with the opponent/player</param>
 public Opponent(string name, TankModel tank, Color colour)
 {
     this.name   = name;
     this.tank   = tank;
     this.colour = colour;
     roundswon   = 0;
 }
Пример #2
0
        /// <summary>
        /// Newly-created method used to update form elemtns to reflect who the current player is. It involves
        /// a number of things like changing the colours, angles, power, round number etc.
        ///
        /// Author John Santias and Hoang Nguyen October 2017
        /// </summary>
        private void NewTurn()
        {
            currentControlledTank = currentGame.GetCurrentGameplayTank();
            currentOpponent       = currentControlledTank.GetPlayerNumber();
            Text = "Tank Battle - Round " + currentGame.GetRound() + " of " + currentGame.GetTotalRounds();
            controlPanel.BackColor = currentOpponent.GetColour();
            playerLabel.Text       = currentOpponent.Name();
            currentControlledTank.SetAimingAngle(angleSet);
            currentControlledTank.SetPower(powerSet);
            windSpeed = currentGame.GetWindSpeed();

            if (windSpeed > 0)
            {
                windStatusLabel.Text = windSpeed + " E";
            }
            else if (windSpeed < 0)
            {
                windStatusLabel.Text = -windSpeed + " W";
            }
            weaponComboBox.Items.Clear();
            currentTankModel = currentControlledTank.GetTank();
            string[] weapons = currentTankModel.WeaponList();

            for (int i = 0; i < weapons.Length; i++)
            {
                weaponComboBox.Items.Add(weapons[i]);
            }

            weaponSet = currentControlledTank.GetWeaponIndex();
            SetWeaponIndex(weaponSet);
            currentOpponent.BeginTurn(this, currentGame);
        }
Пример #3
0
        /// <summary>
        /// This method is used to update form elements to reflect who the current player is.
        /// </summary>
        private void NewTurn()
        {
            currentTank = currentGame.GetCurrentPlayerTank();

            Opponent opponentTank = currentTank.GetPlayer();

            Text                 = String.Format("Tank Battle - Round {0} of {1}", currentGame.GetRoundNumber(), currentGame.GetMaxRounds());
            BackColor            = opponentTank.GetColour();
            playerNameLabel.Text = opponentTank.Identifier();
            SetAngle(currentTank.GetTankAngle());
            SetPower(currentTank.GetCurrentPower());

            int currentWind = currentGame.GetWindSpeed();

            if (currentWind > 0)
            {
                currWindLabel.Text = String.Format("{0} E", currentWind);
            }
            else
            {
                currentWind        = currentWind * -1;
                currWindLabel.Text = String.Format("{0} W", currentWind);
            }
            weaponComboBox.Items.Clear();
            TankModel currentTankModel = currentTank.GetTank();

            foreach (String weapon in currentTankModel.WeaponList())
            {
                weaponComboBox.Items.Add(weapon);
            }
            SetWeapon(weaponComboBox.SelectedIndex);
            opponentTank.NewTurn(this, currentGame);
            controlPanel.BackColor = opponentTank.GetColour();
        }
Пример #4
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);
        }
Пример #5
0
        //public Opponent[] players;

        private void nextPlayerButton_Click(object sender, EventArgs e)
        {
            //setupGame = new SetupGameForm();

            //playerAmount = setupGame.getPlayerAmount();
            //roundAmount = setupGame.getRoundAmount();

            //game = new Gameplay(playerAmount, roundAmount);

            //players = new Opponent[setupGame.playerAmount];

            //for (int i = 0; i < players.Length; i++) {
            //    players[i] = new HumanOpponent("Player " + i, TankModel.GetTank(1), Gameplay.GetTankColour(1));
            //}

            //for (int i = 0; i < players.Length; i++) {
            //    game.SetPlayer(i + 1, players[i]);
            //}

            game = new Gameplay(2, 1);

            Opponent player1 = new HumanOpponent("Player 1", TankModel.GetTank(1), Gameplay.GetTankColour(1));
            Opponent player2 = new HumanOpponent("Player 2", TankModel.GetTank(1), Gameplay.GetTankColour(2));

            game.SetPlayer(1, player1);
            game.SetPlayer(2, player2);

            game.NewGame();
        }
Пример #6
0
        public void Fire()
        {
            //getting the fireweapn

            TankModel tank = CreateTank();

            tank.FireWeapon(this.tWeapon, this, this.tGame);
        }
Пример #7
0
 /// <summary>
 /// sets up a player to begin playing the game
 /// </summary>
 /// <param name="name">name of a player</param>
 /// <param name="tank">player's tank</param>
 /// <param name="colour">colour of player's tank/s</param>
 public GenericPlayer(string name, TankModel tank, Color colour)
 {
     // set player up with all the passed information about the new player
     playerName   = name;
     playersTank  = tank;
     playerColour = colour;
     timesWon     = 0;
 }
Пример #8
0
 public GenericPlayer(string name, TankModel tank, Color colour)
 {
     //making sure when generic player is called it will have a color, name, and tankmodel
     //also checking how many times it has won
     this.hasWon       = 0;
     this.playerTank   = tank;
     this.playerColour = colour;
     this.playerName   = name;
 }
Пример #9
0
 /// <summary>
 /// constructor of AI player
 /// </summary>
 /// <param name="name"></param>
 /// <param name="tank"></param>
 /// <param name="colour"></param>
 public AIOpponent(string name, TankModel tank, Color colour) : base(name, tank, colour)
 {
     // call constructors for private variables
     firedShotLandingX = new List <float>();
     fireShotLandingY  = new List <float>();
     shotHit           = new List <bool>();
     myRandom          = new Random();
     aiSetting         = (difficulty)2;
 }
Пример #10
0
        public static TankModel GetTank(int tankNumber)
        {
            TankModel[] MyTanks = new TankModel[4];
            MyTanks[0] = new Aircraft_carrier();
            MyTanks[1] = new Battleship();
            MyTanks[2] = new Destroyer();
            MyTanks[3] = new Cruiser();
            Console.WriteLine(MyTanks[(tankNumber - 1)]);

            return(MyTanks[(tankNumber - 1)]);
        }
Пример #11
0
 /// <summary>
 ///
 /// This constructor initializes a new instance of the ControlledTank class.
 /// It also stores the tankModel by usubg the Opponents GetTank() method, and
 /// GetArmour() for the current durability of the TankModel. In addition, it also
 /// stores the angle, power, current weapons and colour of the tank which is a bitmap.
 ///
 /// Author John Santias and Hoang Nguyen October 2017
 ///
 /// </summary>
 /// <param name="player"> A reference of Opponent stored as player </param>
 /// <param name="tankX"> The x coordinate of the tank </param>
 /// <param name="tankY"> The y coordinate of the tank </param>
 /// <param name="game"> A reference of Gameplay stored as game </param>
 public ControlledTank(Opponent player, int tankX, int tankY, Gameplay game)
 {
     this.player = player;
     this.tankX  = tankX;
     this.tankY  = tankY;
     this.game   = game;
     tankModel   = player.GetTank();
     currentDur  = tankModel.GetArmour();
     angle       = 0;
     power       = 25;
     tankWeapon  = 0;
     colour      = tankModel.CreateBitmap(player.GetColour(), angle);
 }
Пример #12
0
 /// <summary>
 /// Changes the players in the array playersArray so that they are either playercontrolled or AIControlled
 /// Checks the AI or Human button checked with playerNameBox
 /// Author Greyden Scott & Sean O'Connell October 2017
 /// Written, edited and tested by both team members
 /// </summary>
 private void nextPlayerButton_Click_1(object sender, EventArgs e)
 {
     if (AIRButton.Checked)
     {
         //Create player with AIController
         playersArray[whichPlayer] = new AIPlayer(playerNameBox.Text, TankModel.GetTank(1), Gameplay.GetColour(whichPlayer + 1));
     }
     else
     {
         //Create player with PlayerController
         playersArray[whichPlayer] = new PlayerController(playerNameBox.Text, TankModel.GetTank(1), Gameplay.GetColour(whichPlayer + 1));
     }
     this.Close();
 }
Пример #13
0
        private void newGameButton_Click(object sender, EventArgs e)
        {
            Game          game    = new Game(3, 3);
            GenericPlayer player1 = new PlayerController("Player 1", TankModel.CreateTank(1), Game.GetTankColour(1));
            GenericPlayer player2 = new PlayerController("Player 2", TankModel.CreateTank(1), Game.GetTankColour(2));
            GenericPlayer player3 = new PlayerController("qr2", TankModel.CreateTank(1), Game.GetTankColour(3));


            game.SetPlayer(1, player1);
            game.SetPlayer(2, player2);
            game.SetPlayer(3, player3);


            game.CommenceGame();
        }
Пример #14
0
        public Bullet(float x, float y, float angle, float power, float gravity, Shrapnel explosion, TankModel player)
        {
            X          = x;
            Y          = y;
            angles     = angle;
            powers     = power;
            gravitys   = gravity;
            explosions = explosion;
            players    = player;
            float angleRadians = (90 - angle) * (float)Math.PI / 180;
            float magnitude    = power / 50;

            dx = (float)Math.Cos(angleRadians) * magnitude;
            dy = (float)Math.Sin(angleRadians) * (-magnitude);
        }
Пример #15
0
        public BattleTank(TankModel player, int tankX, int tankY, GameController game)
        {
            bPlayer     = player;
            tankx       = tankX;
            tanky       = tankY;
            currentgame = game;

            TankModel current    = GetTank();
            int       durability = current.GetTankHealth();

            angle         = 0;
            power         = 25;
            currentweapon = 0;

            TankModel.TankColour();
        }
Пример #16
0
 /// <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);
 }
Пример #17
0
        /// <summary>
        ///
        /// When this button is pressed, the next player can select their
        /// name, tank and controller. When all players have selected their loadouts
        /// the game will begin.
        ///
        /// Author John Santias and Hoang Nguyen October 2017
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nextPlayerButton_Click(object sender, EventArgs e)
        {
            playerNames.Add(playerNameInput.Text);
            if (humanRadioButton.Checked)
            {
                humans[player - 1] = "human";
            }
            else if (aiRadioButton.Checked)
            {
                AIs[player - 1] = "Ai";
            }

            // If not all players have not assign player name, tank types and controller
            if (player != playerAmount)
            {
                player++;
                PlayerLabel.Text     = "Player #" + player + "'s name:";
                playerNameInput.Text = "Player " + player;
                BackColor            = Gameplay.GetTankColour(player);

                // If all players have put in their details, game starts
            }
            else if (player == playerAmount)
            {
                Gameplay game = new Gameplay(playerAmount, roundAmount);

                //create human players
                for (int i = 0; i < playerAmount; i++)
                {
                    if (humans[i] == "human")
                    {
                        Opponent a = new HumanOpponent(playerNames[i], TankModel.GetTank(1), Gameplay.GetTankColour(i + 1));
                        game.SetPlayer(i + 1, a);
                    }
                    else if (AIs[i] == "Ai")
                    {
                        Opponent a = new AIOpponent(playerNames[i], TankModel.GetTank(1), Gameplay.GetTankColour(i + 1));
                        game.SetPlayer(i + 1, a);
                    }
                }
                game.NewGame();
                Close();
            }
        }
Пример #18
0
        /// <summary>
        /// Creates a BattleTank with the passed information
        /// Setting the colour with GetColour()
        /// Durability with GetTankArmour();
        /// TankModel with GetTank();
        /// Author Greyden Scott & Sean O'Connell October 2017
        /// Written, edited and tested by both team members
        /// </summary>
        /// <param name="player">The player associated with the Battle Tanks</param>
        /// <param name="tankX">The X Position</param>
        /// <param name="tankY">The Y position</param>
        /// <param name="game">Current games</param>
        /// <returns>explanation of return value</returns>
        public BattleTank(Opponent player, int tankX, int tankY, Gameplay game)
        {
            this.player = player;
            this.tankX  = tankX;
            this.tankY  = tankY;

            tankModel      = player.GetTank();
            currDurability = tankModel.GetTankArmour();

            angle       = 0;
            power       = 25;
            curr_weapon = 0;

            plColour = player.GetColour();

            tankBmp = tankModel.CreateBMP(plColour, angle);

            this.game = game;
        }
Пример #19
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();
        }
Пример #20
0
 public TankModel(string name, TankModel tank, Color colour)
 {
     names = name;
     tanks = tank;
     color = colour;
 }
Пример #21
0
 public ComputerOpponent(string name, TankModel tank, Color colour) : base(name, tank, colour)
 {
 }
Пример #22
0
 public PlayerController(string name, TankModel tank, Color colour) : base(name, tank, colour)
 {
 }
Пример #23
0
 /// <summary>
 /// Constructor for the HumanOpponent class. All functionality is handled by Opponent so this
 /// method doesn't need to do anything.
 ///
 /// Author John Santias September 2017
 /// </summary>
 /// <param name="name"></param>
 /// <param name="tank"></param>
 /// <param name="colour"></param>
 public HumanOpponent(string name, TankModel tank, Color colour) : base(name, tank, colour)
 {
     this.name   = name;
     this.tank   = tank;
     this.colour = colour;
 }
Пример #24
0
        /// <summary>
        /// Gets the current Tank and Activates the weapon
        /// Author Greyden Scott & Sean O'Connell October 2017
        /// Written, edited and tested by both team members
        /// </summary>
        public void Fire()
        {
            tankModel = GetTank();

            tankModel.ActivateWeapon(curr_weapon, this, game);
        }
Пример #25
0
 public PlayerController(string name, TankModel tank, Color colour) : base(name, tank, colour)
 {
     //do nothing here as this is a human player
 }
Пример #26
0
        /// <summary>
        /// used to move to the next player
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void NextPlayer_Click(object sender, EventArgs e)
        {
            string playerName;
            int    tankChoice = 1;

            //check that a choice has been made for both controller and tank
            if (!(humanChoice.Checked || computerChoice.Checked))
            {
                MessageBox.Show("Looks like you haven't setup a controller for this player \n please choose either human or computer");
                return;
            }
            if (!(basicTank.Checked || HeavyTank.Checked || quickFireTank.Checked || armoredTank.Checked))
            {
                MessageBox.Show("Looks like you haven't setup a tank for this player \n please select one to continue");
                return;
            }
            //find the choice of tank for this player
            if (basicTank.Checked)
            {
                tankChoice = 1;
            }
            if (quickFireTank.Checked)
            {
                tankChoice = 2;
            }
            if (HeavyTank.Checked)
            {
                tankChoice = 3;
            }
            if (armoredTank.Checked)
            {
                tankChoice = 4;
            }
            //stub more choices to come for future references

            //find the player's name
            if (inputtedName.Text == "")
            {
                // if no name inputted then go to basic name
                playerName = string.Format("Player {0}", setupPlayers + 1);
            }
            else
            {
                //if name inputted then set player to that name
                playerName = inputtedName.Text;
            }

            // add player to array of GenericPlayers
            if (humanChoice.Checked)
            {
                // Human player made
                Players[setupPlayers] = new PlayerController(playerName, TankModel.GetTank(tankChoice), Battle.TankColour(setupPlayers + 1));
            }
            if (computerChoice.Checked)
            {
                Players[setupPlayers] = new AIOpponent(playerName, TankModel.GetTank(tankChoice), Battle.TankColour(setupPlayers + 1));
            }

            // add entry of new player into the game
            currentBattle.SetPlayer(setupPlayers + 1, Players[setupPlayers]);

            // now move to the next player to setup

            setupPlayers++;

            //check to see if the next player is the last player
            if (setupPlayers + 1 == totalPlayers)
            {
                //change the nextplayer text to show that it will start the game on next click
                NextPlayer.Text      = "Start Game!!!";
                NextPlayer.ForeColor = Color.Red;
            }
            //check to see if all players are setup
            if (setupPlayers == totalPlayers)
            {
                //start the game
                currentBattle.NewGame();
                this.Dispose();
                return;
            }

            //reset for next player
            Reset();
        }
Пример #27
0
 public ComputerPlayer(string name, TankModel tank, Color colour) : base(name, tank, colour)
 {
     throw new NotImplementedException();
 }
Пример #28
0
 public AIPlayer(string name, TankModel tank, Color colour) : base(name, tank, colour)
 {
     this.name   = name;
     this.tank   = tank;
     this.colour = colour;
 }
Пример #29
0
 public void RegisterPlayer(int playerNum, TankModel player)
 {
     TankController[playerNum - 1] = player;
 }