示例#1
0
        private bool CreateActor(Pos EnvPos, ActorID ID)
        {
            if (MyMap.MCell[EnvPos.X, EnvPos.Y].LEnvir == null)
            {
                Envir env = null;
                switch (ID)
                {
                case ActorID.Chestnut:
                    env = new Envirs.Chestnut(EnvPos, MyMap.MCell[EnvPos.X, EnvPos.Y].GlCoord);
                    break;

                case ActorID.Carrot:
                    env = new Envirs.Carrot(EnvPos, MyMap.MCell[EnvPos.X, EnvPos.Y].GlCoord);
                    break;
                }
                if (env != null)
                {
                    if (env.GetCanPlace(MyMap.MCell[EnvPos.X, EnvPos.Y].ID, MyMap.MCell[EnvPos.X, EnvPos.Y].LAnimal))
                    {
                        Envirs.Add(env);
                        MyMap.AddEnvir(env, EnvPos);
                        env.IGetCell += MyMap.GetCellP;
                        env.IDeath   += Delete;
                        return(true);
                    }
                    else
                    {
                        env.Dispose();
                    }
                }
            }
            if (MyMap.MCell[EnvPos.X, EnvPos.Y].LAnimal == null)
            {
                Animal anim = null;
                switch (ID)
                {
                case ActorID.Rabbit:
                    anim = new Animals.Rabbit(EnvPos, MyMap.MCell[EnvPos.X, EnvPos.Y].GlCoord);
                    break;

                case ActorID.Wolf:
                    anim = new Animals.Wolf(EnvPos, MyMap.MCell[EnvPos.X, EnvPos.Y].GlCoord);
                    break;

                case ActorID.Deer:
                    anim = new Animals.Deer(EnvPos, MyMap.MCell[EnvPos.X, EnvPos.Y].GlCoord);
                    break;
                }
                if (anim != null)
                {
                    if (anim.GetCanPlace(MyMap.MCell[EnvPos.X, EnvPos.Y].ID, MyMap.MCell[EnvPos.X, EnvPos.Y].LEnvir))
                    {
                        Animals.Add(anim);
                        MyMap.AddAnim(anim, EnvPos);
                        anim.IGoAct       += MyMap.GoAnimal;
                        anim.ILookAct     += MyMap.LookAnimal;
                        anim.ISearchWay   += MyMap.SearchWayAnimal;
                        anim.IlookGlCoord += MyMap.GetGlobalCoord;
                        anim.IGetCell     += MyMap.GetCellP;
                        anim.IDeath       += Delete;
                        return(true);
                    }
                    else
                    {
                        anim.Dispose();
                        return(false);
                    }
                }
            }

            return(false);
        }