using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Snake
{
    public class Wormhole
    {
        const float SPEED = 0.5f;

        static Texture2D texture;

        Color color = Color.White;
        public Color Color
        {
            get { return color; }
        }

        Point coord = Point.Zero;
        public Point Coord
        {
            get { return coord; }
        }

        float angle = 0.0f;
        int cellSize;

        public Wormhole(int cellSize, string name, Point coord)
        {
            this.cellSize = cellSize;
            this.coord = coord;
            if (name.Contains("red"))
            {
                color = Color.Red;
            }
            else if (name.Contains("green"))
            {
                color = Color.Green;
            }
            else if (name.Contains("blue"))
            {
                color = Color.Blue;
            }
            else if (name.Contains("white"))
            {
                color = Color.White;
            }
            else if (name.Contains("black"))
            {
                color = Color.Black;
            }
            else
                throw new ArgumentException("Incorrect wormhole color");
        }

        public static void Load(ContentManager content)
        {
            texture = content.Load<Texture2D>("wormhole");
        }

        public void Update(GameTime gameTime)
        {
            float time = 1000.0f / gameTime.ElapsedGameTime.Milliseconds;
            angle += time * SPEED;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            Rectangle rect = new Rectangle(coord.X * cellSize + cellSize / 2, coord.Y * cellSize + cellSize / 2, cellSize, cellSize);
            spriteBatch.Draw(texture, rect, null, color, angle, new Vector2(cellSize / 2, cellSize / 2), SpriteEffects.None, 0);
        }
    }
}
