none
Extension method must be defined in a non-generic static class RRS feed

  • Question

  • using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Text;  
    using Microsoft.Xna.Framework;  
    using Microsoft.Xna.Framework.Audio;  
    using Microsoft.Xna.Framework.Content;  
    using Microsoft.Xna.Framework.GamerServices;  
    using Microsoft.Xna.Framework.Graphics;  
    using Microsoft.Xna.Framework.Input;  
    using Microsoft.Xna.Framework.Input.Touch;  
    using Microsoft.Xna.Framework.Media;  
    namespace WPFreeCell  
    {  
        /// <summary>  
        /// This is a game component that implements IUpdateable.  
        /// </summary>  
     
        public class ObjectManager  
        {  
            public Random Rand;  
            public Vector2 TouchPos;  
            SpriteFont Font;  
            List<Card> Cards;  
            //Top Final Cards  
            TFCardsSpots TFCards;  
            //Bottom Row Cards  
            BottomCardManager BCM;  
            //Top Movable Cards  
            TMCardsSpots TMCards;  
            List<Sprite> Particles;  
            List<Sprite> Buttons;  
            Dictionary<String, Texture2D> Map;  
            public SpriteBatch spriteBatch;  
            float timer = 0;  
            public ObjectManager()  
            {  
                // TODO: Construct any child components here  
            }  
            public void Delete()  
            {  
                for (int i = 0; i < Particles.Count; )  
                {  
                    Particles.RemoveAt(i);  
                }  
                for (int i = 0; i < Buttons.Count; )  
                {  
                    Buttons.RemoveAt(i);  
                }  
            }  
            public void DeleteDeathState()  
            {  
                for (int i = 0; i < Buttons.Count; )  
                {  
                    Buttons.RemoveAt(i);  
                }  
                Globals.Level = 0;  
            }  
            /// <summary>  
            /// Allows the game component to perform any initialization it needs to before starting  
            /// to run.  This is where it can query for any required services and load content.  
            /// </summary>  
            public void Initialize()  
            {  
                // TODO: Add your initialization code here  
                Rand = new Random();  
                this.Particles = new List<Sprite>();  
                this.Buttons = new List<Sprite>();  
                Cards = new List<Card>();  
                BCM = new BottomCardManager();  
                TFCards = new TFCardsSpots();  
                TMCards = new TMCardsSpots();  
                //Loading in the land  
     
     
            }  
            public void LoadContant(SpriteBatch spritebatch, Dictionary<String, Texture2D> Map, SpriteFont font)  
            {  
                Font = font;  
                this.Map = Map;  
                //Blocks.Add(new Enemy(Map["Enemy"], spritebatch, new Vector2((float)Rand.NextDouble() * 200 + 600, 100)));  
                //Loading in the Player  
                //AddMenuButtons(spritebatch);  
                AddDeathMenuButtons(spritebatch);  
                this.spriteBatch = spritebatch;  
                //sky = new ScrollingBackGround();  
                //sky.Initialize(Map["Sky"], 800, .1f);  
                //Blocks.Add(new ProgressBar(Map["Spike"], spritebatch, new Vector2(0, 0), new Vector2(800, 10)));  
     
            }  
            public void AddCards()  
            {  
                for(int i = 0;i<4;++i)  
                    for(int j = 0;j<13;++j)  
                        Cards.Add(new Card(Map["Card"],Vector2.Zero,spriteBatch,j,i));  
            }  
            public void ShuffleCards()  
            {  
                int card1, card2;  
                for (int i = 0; i < 1000; ++i)  
                {  
                    card1 = Rand.Next(Cards.Count());  
                    card2 = Rand.Next(Cards.Count());  
                    Swap(Cards,card1, card2);  
                }  
            }  
            static void Swap<T>(this List<T> list, int index1, int index2)  
            {  
                T temp = list[index1];  
                list[index1] = list[index2];  
                list[index2] = temp;  
     
            }  
            public void DealCards()  
            {  
                BCM.Initialize(Cards);  
            }  
            public void ReloadContant(SpriteBatch spritebatch)  
            {  
                //Blocks.Add(new Enemy(Map["Enemy"], spritebatch, new Vector2((float)Rand.NextDouble() * 200 + 600, 100)));  
                //Loading in the Player  
                AddMenuButtons(spritebatch);  
     
            }  
            public void AddMenuButtons(SpriteBatch spriteBatch)  
            {  
                Buttons.Add(new Button(Map["Logo"], spriteBatch, new Vector2(160, 425), new Vector2(300, 100)));  
                Buttons.Add(new Button(Map["Resume"], spriteBatch, new Vector2(100, 325), new Vector2(150, 75), Button.ButtonType.RESUME));  
                Buttons.Add(new Button(Map["Exit"], spriteBatch, new Vector2(100, 225), new Vector2(150, 75), Button.ButtonType.EXIT));  
                Buttons.Add(new Button(Map["Rate"], spriteBatch, new Vector2(675, 325), new Vector2(125, 60), Button.ButtonType.REVIEW));  
                Buttons.Add(new Button(Map["Sound"], spriteBatch, new Vector2(650, 400), new Vector2(50, 50), Button.ButtonType.SOUND));  
                Buttons.Add(new Button(Map["Music"], spriteBatch, new Vector2(700, 400), new Vector2(50, 50), Button.ButtonType.MUSIC));  
            }  
            public void AddDeathMenuButtons(SpriteBatch spriteBatch)  
            {  
                Buttons.Add(new Button(Map["Logo"], spriteBatch, new Vector2(160, 425), new Vector2(300, 100)));  
                Buttons.Add(new Button(Map["Restart"], spriteBatch, new Vector2(100, 325), new Vector2(150, 75), Button.ButtonType.RESTART));  
                Buttons.Add(new Button(Map["Exit"], spriteBatch, new Vector2(100, 225), new Vector2(150, 75), Button.ButtonType.EXIT));  
                Buttons.Add(new Button(Map["Rate"], spriteBatch, new Vector2(675, 325), new Vector2(125, 60), Button.ButtonType.REVIEW));  
                Buttons.Add(new Button(Map["Sound"], spriteBatch, new Vector2(650, 400), new Vector2(50, 50), Button.ButtonType.SOUND));  
                Buttons.Add(new Button(Map["Music"], spriteBatch, new Vector2(700, 400), new Vector2(50, 50), Button.ButtonType.MUSIC));  
            }  
            public void UnloadContant()  
            {  
            }  
            /// <summary>  
            /// Allows the game component to update itself.  
            /// </summary>  
            /// <param name="gameTime">Provides a snapshot of timing values.</param>  
            ///     
            public void AddParticles(Texture2D texture, SpriteBatch sprt, Vector2 pos, int number)  
            {  
                Color color;  
                color = new Color();  
                while (number-- != 0)  
                {  
                    color.B = (byte)(Rand.NextDouble() * 255);  
                    color.A = (byte)(Rand.NextDouble() * 255);  
                    color.R = (byte)(Rand.NextDouble() * 255);  
                    color.G = (byte)(Rand.NextDouble() * 255);  
                    double randnum = (Rand.NextDouble() * 360) * Math.PI / 180;  
                    //vel.X *= (float)Rand.NextDouble() + 1;  
                    //vel.Y *= (float)Rand.NextDouble() + 1;  
                }  
            }  
            public void AddRadialParticles(Vector2 pos, int number)  
            {  
                Vector2 vel = Vector2.Zero;  
                vel.X = (float)Rand.NextDouble() * 30.0f;  
                vel.Y = vel.X;  
                //float angle = player.GetAngle();  
                //float playervel = 10f;// (float)(vel.X / Math.Cos((double)angle));  
                Color color;  
                color = new Color();  
                while (number-- != 0)  
                {  
                    color.B = (byte)(Rand.NextDouble() * 255);  
                    color.A = (byte)(Rand.NextDouble() * 255);  
                    color.R = (byte)(Rand.NextDouble() * 255);  
                    color.G = (byte)(Rand.NextDouble() * 255);  
                    //double randnum = (Rand.NextDouble() * 360) * Math.PI / 180;  
                    //randnum += angle;  
                    //vel.X = playervel * (float)Math.Cos(randnum);  
                    //vel.Y = playervel * (float)Math.Sin(randnum);  
                    //vel *= (float)Rand.NextDouble();  
                    //vel.X *= (float)Rand.NextDouble() + 1;  
                    //vel.Y *= (float)Rand.NextDouble() + 1;  
                }  
            }  
            public void AddObjects(Type obj, SpriteBatch spriteBatch)  
            {  
                double angle = (Rand.NextDouble() * 360) * Math.PI / 180;  
                Vector2 newpos = Vector2.Zero;  
                newpos.X = (float)(1200 * Math.Cos(angle));  
                newpos.Y = (float)(700 * Math.Sin(angle));  
            }  
            public void AddObjects(Type obj, SpriteBatch spriteBatch, Vector2 pos, float angle, float velocity)  
            {  
     
            }  
            public void UpdateTouchPosition()  
            {  
                TouchPos = Vector2.Zero;  
                while (TouchPanel.IsGestureAvailable)  
                {  
                    GestureSample gesture = TouchPanel.ReadGesture();  
                    if (gesture.GestureType == GestureType.Tap)  
                    {  
                        TouchPos = gesture.Position;  
                        //TouchPos.Y = (240f + (240f - gesture.Position.Y));  
                    }  
     
                }  
     
            }  
            public void Update(GameTime gameTime, SpriteBatch spriteBatch)  
            {  
                //TODO: Add your update code here  
                if (Globals.GSM.states == GameStateManager.State.MENU)  
                {  
                    UpdateTouchPosition();  
                    for (int i = 0; i < Buttons.Count; ++i)  
                    {  
                        Buttons[i].Update(gameTime, this);  
                    }  
                }  
                else 
                {  
                    //else if (Globals.ScoreToNextLevel * Globals.Level - 1000== Globals.PlayerScore)  
                    //{  
                    //    ChangeTimeToSwarmTrue();  
                    //}  
                    // TODO: Add your update logic here  
                    //CheckCollision  
                    //CheckOutOfBounds  
                    //UpdateParticles  
                      
                    for (int i = 0; i < Particles.Count; ++i)  
                    {  
                        Particles[i].Update(gameTime, this);  
                        if (Particles[i].IsDead())  
                        {  
                            Particles.RemoveAt(i);  
                            --i;  
                        }  
     
                    }  
                }  
            }  
            public void UpdateDeathState(GameTime gameTime, SpriteBatch spriteBatch)  
            {  
                UpdateTouchPosition();  
                for (int i = 0; i < Buttons.Count; ++i)  
                {  
                    Buttons[i].Update(gameTime, this);  
                }  
     
                for (int i = 0; i < Particles.Count; ++i)  
                {  
                    Particles[i].Update(gameTime, this);  
                    if (Particles[i].IsDead())  
                    {  
                        Particles.RemoveAt(i);  
                    }  
                }  
            }  
            public void Draw(SpriteBatch spritebatch, GameTime gameTime)  
            {  
                //float FPS = 1.0f / (gameTime.ElapsedGameTime.Milliseconds / 1000.0f);  
                //Vector2 origion = new Vector2(480 / 2, 800 / 2);  
                //draw backgrounds  
                //sky.Draw(spritebatch);  
                //spritebatch.DrawString(Font, "FPS: " + gameTime.ElapsedGameTime.Milliseconds, new Vector2(300, 0), Color.White);  
                for (int i = 0; i < Particles.Count; ++i)  
                {  
                    Particles[i].Draw(gameTime);  
                }  
                if (Globals.GSM.states == GameStateManager.State.MENU)  
                {  
                    for (int i = 0; i < Buttons.Count; ++i)  
                    {  
                        Buttons[i].Draw(gameTime);  
                    }  
                }  
                else 
                {  
     
                }  
            }  
            public void DrawDeathState(SpriteBatch spritebatch, GameTime gameTime)  
            {  
     
            }  
        }  
    }  
     
    I have no idea why I am getting this error. I am using the same object manager as in my other game and i have yet to get this error. I am also not using this as an extension method.Any idea on how to fix this error?
    Wednesday, April 25, 2012 11:42 PM

All replies

  • Can you give some more details?  Which line in that block of code?  We have no idea what code or extension method you are talking about.
    Thursday, April 26, 2012 12:22 AM
  • Hey thanks man it was the swap function also im used to programing in c++ so if you call list.Clear() it would only remove the pointers not the actual objects. Which creates a memory leak thanks for the help on this!
    Monday, April 30, 2012 5:33 PM