using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using StrategicCombat.Maps;
using StrategicCombat.CombatUnits;
using StrategicCombat.PowerUps;

namespace StrategicCombat.GameLogic
{
    /// <summary>
    /// This class represent gameplay logic for a game.
    /// </summary>
    public abstract class GamePlayLogic
    {
        #region Variables

        // Network session
        public NetworkSession networkSession;

        // Game end logic
        public bool hasGameEnded = false;
        public String winningPlayer = "Unknown";

        // Power ups.
        public List<PowerUp> powerUps;
        public int powerUpCounter = 0;
        public Texture2D health100PowerUpTexture;
        public Texture2D damagePowerUpTexture;
        public Texture2D shotPowerUpTexture;
        public Texture2D shotDelayPowerUpTexture;
        public Texture2D health200PowerUpTexture;

        // Gamertags
        public String leftGamerTag;
        public String rightGamerTag;

        // Textures
        public Texture2D blueCircleTexture;
        public Texture2D redCircleTexture;

        // Random generator.
        public Random rnd;

        #endregion

        #region Constructors

        /// <summary>
        /// Create new gameplay logic.
        /// </summary>
        /// <param name="content"></param>
        public GamePlayLogic(NetworkSession networkSession, ContentManager content)
        {
            // Set the network session
            this.networkSession = networkSession;

            // Create a new list with power ups
            this.powerUps = new List<PowerUp>(20);

            // Load power up textures
            this.damagePowerUpTexture = content.Load<Texture2D>("PowerUps/damageX2");
            this.health100PowerUpTexture = content.Load<Texture2D>("PowerUps/health100");
            this.shotPowerUpTexture = content.Load<Texture2D>("PowerUps/shotSpeedX2");
            this.shotDelayPowerUpTexture = content.Load<Texture2D>("PowerUps/shotDelay50");
            this.health200PowerUpTexture = content.Load<Texture2D>("PowerUps/health200");

            // Load circle textures.
            this.blueCircleTexture = content.Load<Texture2D>("MenuAssets/blueCircle");
            this.redCircleTexture = content.Load<Texture2D>("MenuAssets/redCircle");

            // Create a new random generator.
            this.rnd = new Random();
        }

        #endregion

        #region Methods

        /// <summary>
        /// Handles player input.
        /// </summary>
        /// <param name="playerIndex"></param>
        public abstract void PlayerInputOnBoard(LocalNetworkGamer gamer, PlayerIndex playerIndex, Map currentMap);
        public abstract void PlayerInputInCombat(LocalNetworkGamer gamer, Viewport viewPort, PlayerIndex playerIndex, CombatScene currentCombatScene);

        /// <summary>
        /// Handles updates.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="currentMap"></param>
        public abstract void UpdateOnBoard(GameTime gameTime, Map currentMap);
        public abstract void UpdateInCombat(GameTime gameTime, CombatScene combatScene);
        public abstract bool CheckIfCombatHasEnded();
        public abstract void CheckIfGameHasEnded();

        /// <summary>
        /// Handles the drawing.
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="spriteFont"></param>
        /// <param name="currentMap"></param>
        public abstract void DrawOnBoard(SpriteBatch spriteBatch, SpriteFont font, Map currentMap);
        public abstract void DrawInCombat(SpriteBatch spriteBatch);

        /// <summary>
        /// Handles collision detection.
        /// </summary>
        /// <returns></returns>
        public abstract bool CollisionBetweenCombatUnits();

        /// <summary>
        /// Handles power ups.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="combatScene"></param>
        public abstract void PowerUpManagement(GameTime gameTime, CombatScene combatScene);

        #endregion

    } // End of class

} // End of namespace
