Пример #1
0
        //private void TryPlay(Song backgroundMusic)
        //{
        //    try
        //    {
        //        MediaPlayer.Play(backgroundMusic);
        //    }
        //    catch (Exception)
        //    {
        //        MediaPlayer.Play(backgroundMusic);
        //    }
        //}

        private Dictionary <Type, List <List <float> > > GetLevelDictFromGameObjects(List <IGameObject> gameObjects)
        {
            Dictionary <Type, List <List <float> > > objects = new Dictionary <Type, List <List <float> > >();

            foreach (IGameObject obj in gameObjects)
            {
                if (obj is Body)
                {
                    Body b = obj as Body;
                    if (b is Floor)
                    {
                        Floor f = b as Floor;
                        if (objects.ContainsKey(f.GetType()))
                        {
                            objects[f.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                        else
                        {
                            objects.Add(f.GetType(), new List <List <float> >());
                            objects[f.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                    }
                    else if (b is Wall)
                    {
                        Wall w = b as Wall;
                        if (objects.ContainsKey(w.GetType()))
                        {
                            objects[w.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                        else
                        {
                            objects.Add(w.GetType(), new List <List <float> >());
                            objects[w.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                    }
                    else if (b is Robot)
                    {
                        Robot r = b as Robot;
                        if (objects.ContainsKey(r.GetType()))
                        {
                            objects[r.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                        else
                        {
                            objects.Add(r.GetType(), new List <List <float> >());
                            objects[r.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        };
                    }
                    else if (b is SuicideRobot)
                    {
                        SuicideRobot sr = b as SuicideRobot;
                        if (objects.ContainsKey(sr.GetType()))
                        {
                            objects[sr.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                        else
                        {
                            objects.Add(sr.GetType(), new List <List <float> >());
                            objects[sr.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                    }
                    else if (b is WinPoint)
                    {
                        WinPoint wp = b as WinPoint;
                        if (objects.ContainsKey(wp.GetType()))
                        {
                            objects[wp.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                        else
                        {
                            objects.Add(wp.GetType(), new List <List <float> >());
                            objects[wp.GetType()].Add(new List <float>()
                            {
                                b.Position.X, b.Position.Y, b.Rotation
                            });
                        }
                    }
                }
            }

            return(objects);
        }