using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Client;

namespace WindowsGame2
{
    class Article
    { 
        public int[,] article;
        public static Texture2D articleSprite;
        public Vector2 articlePos;
        public Rectangle articleRect;

        public static Texture2D iceSprite;
        public static Rectangle iceRect;

        public static Texture2D kulouSprite;
        public static Rectangle kulouRect;

        public static Texture2D chibangSprite;
        public static Rectangle chibangRect;

        public static Texture2D slowshoeSprite;
        public static Rectangle slowshoeRect;

        public byte frame;
        public int delay;
        public int jump;

        public int yellowFrame;

        public Article()
        { 
            article = new int[Arena.Hight,Arena.Width];
            article[1, 0] = 1;
            article[3, 8] = 2;
            article[9, 5] = 3;
            article[4, 9] = 4;
            article[7, 11] = 51;
            article[9, 9] = 51;
            article[3, 3] = 51;
            article[5, 4] = 51;
            article[9, 10] = 51;
            article[4, 7] = 51;
            article[7, 10] = 51;
            article[2, 9] = 51;
            article[4, 3] = 51;
            article[11, 4] = 51;
            article[10, 10] = 31;
            article[9, 3] = 11;
            article[6, 4] = 21;
            article[9, 1] = 31;
            article[4, 6] = 11;
            article[7, 1] = 21;
            article[2, 9] = 31;
            article[4, 10] = 21;
            article[1, 4] = 31;
            article[1, 10] = 31;
            article[1, 9] = 31;
            article[1, 6] = 31;
             
            articleSprite = Game1.content.Load<Texture2D>(@"image\article"); 
            articleRect = new Rectangle(0, 0, 50, 50);

            iceSprite = Game1.content.Load<Texture2D>(@"image\bingkuai");
            iceRect = new Rectangle(5,5,50,50);

            kulouSprite = Game1.content.Load<Texture2D>(@"image\kulou");
            kulouRect = new Rectangle(0,0,50,50);

            chibangSprite = Game1.content.Load<Texture2D>(@"image\chibang");
            chibangRect = new Rectangle(0, 0, 50, 50);

            slowshoeSprite = Game1.content.Load<Texture2D>(@"image\jiansu");
            slowshoeRect = new Rectangle(1,0,38,50);

            articlePos = new Vector2(0, 0);

            frame = 0;
            delay = 0;
            jump = 0;

            yellowFrame = 0;

        }

        public static void useIce(Player p)
        {
            p.setSpeedH(0);
            p.setSpeedV(0);
            p.setStatus(1);
            p.setKulouEffect(1);
        }
        public static void useAngle()
        {

        }
        public static void useSlowShoe(Player p)
        {
            p.setStatus(0);
            p.setSpeedValue(1);
            p.setKulouEffect(1);
        }
        public static void useFastShoe(Player p)
        {
            p.setStatus(0);
            p.setSpeedValue(4);
            p.setKulouEffect(1);
        }
        public static void useMedi(Player p)
        {
            p.setStatus(0);
            p.setSpeedValue(3);
            p.setKulouEffect(1);
        }
        public static void useYin(Player p)
        {
            p.setStatus(2);
            p.setKulouEffect(1);
        }
        public static void useKulou(Player p)
        {
            p.setStatus(3); 

            p.setKulouEffect(-1);
        }


        public void update()
        {
            if (delay == 0)
            {
                delay = 8;
                //jump effect
                frame++;
                if ((frame & 1) != 0)
                    jump = 2;
                else
                    jump = 0;

                //yellow boy
                yellowFrame++;
                if (yellowFrame == 4)
                    yellowFrame = 0;
            }
            else
                delay--;
        }

        public void draw(int x,int y,Boolean isYellow)
        {
            //draw article
            if (isYellow == false)
            {
                articleRect.X = 0;

                if (article[x, y] == 1)
                {
                    articlePos.X = y * 40 + 25;
                    articlePos.Y = x * 40 + 20 + jump;
                    Game1.foreGround.Draw(Article.iceSprite, articlePos, iceRect, Color.White);
                    return;
                }
                else if (article[x, y] == 2)
                {
                    articlePos.X = y * 40 + 25;
                    articlePos.Y = x * 40 + 20 + jump;
                    Game1.foreGround.Draw(Article.kulouSprite, articlePos, kulouRect, Color.White);
                    return;
                }
                else if (article[x, y] == 3)
                {
                    articlePos.X = y * 40 + 25;
                    articlePos.Y = x * 40 + 20 + jump;
                    Game1.foreGround.Draw(Article.chibangSprite, articlePos, chibangRect, Color.White);
                    return;
                }
                else if (article[x, y] == 4)
                {
                    articlePos.X = y * 40 + 30;
                    articlePos.Y = x * 40 + 21 + jump;
                    Game1.foreGround.Draw(Article.slowshoeSprite, articlePos, slowshoeRect, Color.White);
                    return;
                }
                else
                {
                    articlePos.X = y * 40 + 25;
                    articlePos.Y = x * 40 + 20 + jump;
                    articleRect.Y = ((article[x, y] - article[x, y] % 10) / 10 - 1) * 50 ;
                    Game1.foreGround.Draw(Article.articleSprite,articlePos,articleRect,Color.White);
                    return;
                }
            }
            //draw yellow boy
            else if (isYellow == true)
            {
                articleRect.X = yellowFrame*50;
                articleRect.Y = ((article[x, y] - article[x, y] % 10) / 10 - 1) * 50;

                articlePos.X = y * 40 + 25;
                articlePos.Y = x * 40 + 20;
                Game1.foreGround.Draw(Article.articleSprite, articlePos, articleRect, Color.White);
                
            }

            

        }
    }
}
