GAM456-SpaceInvaders / SpaceInvaders / 7_Player / Player.cs
Player.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class Player
    {
        //-------------------------------------------------------------------
        //  FIELDS
        //-------------------------------------------------------------------

        public enum PlayerType
        {
            Player1,
            Player2,
            Uninitialized
        }

        PlayerType playerType;

        static int totalLives = 3;  
        int totalPoints;


        //-------------------------------------------------------------------
        //  CONSTRUCTION
        //-------------------------------------------------------------------

        public Player(Player.PlayerType type = PlayerType.Uninitialized)
        {
            this.playerType = type;
            this.totalPoints = 0;
        }


        //-------------------------------------------------------------------
        //  PUBLIC METHODS
        //-------------------------------------------------------------------

        public Player.PlayerType GetPlayerType()
        {
            return this.playerType;
        }

        public void AddPoints(int points)
        {
            this.totalPoints += points;
        }

        public int GetPoints()
        {
            return this.totalPoints;
        }

        public int GetLives()
        {
            return totalLives;
        }

        public void LoseLife()
        {
            //cap it at zero
            if( totalLives > 0)
            {
                totalLives--;
            }
            else
            {
                totalLives = 0;
            }
        }

        public void BonusLife()
        {
            //1 bonus at 1500 pts
            totalLives++;
        }

        public void Reset()
        {
            this.totalPoints = 0;
            totalLives = 3;
        }

        public void ResetPoints()
        {
            this.totalPoints = 0;
        }

    } // end class

} // end namespace