0

縦型プラットフォーマーを作っています。私がプラットフォームを配置する方法は、リストを使用することです。

      public void LoadPlatforms(ContentManager content, Mechanic_Levels mech, Clide clide)
    {
        platforms.Add(new Entity_Platform());
        platforms.Add(new Entity_Platform());
        platforms.Add(new Entity_Platform());
        platforms.Add(new Entity_Platform());
        platforms.Add(new Entity_Platform());
        platforms.Add(new Entity_Platform());
        platforms.Add(new Entity_Platform());
        platforms.Add(new Entity_Platform());
        platforms.Add(new Entity_Platform());


       // factory.Add(new Entity_Factory());

        foreach (Entity_Platform platform in platforms)
        {
            platform.position = new Vector2(rand.Next(20, 280), rand.Next(20, 580));
            platform.currentlevel = rand.Next(12);
            platform.LoadPlatform(content);
           }
        }

これは、プラットフォームをランダムに配置したい場合に機能しますが、現在のレベルに応じてプラットフォームが個別に再配置されるように設定するにはどうすればよいですか? これはおそらくリストを使用できないことを意味することを認識しています。

4

2 に答える 2

0

100% を取得できるかどうかはわかりませんが、次のような比較方法を提供することで、Entity_Platform内で sを並べ替えることができますList<Entity_Platform>

private static int ComparePlatforms(Entity_Platform x, Entity_Platform y)
{
        //compare your platforms according to chosen critieria
        //should return 1 if x > y, 0 if x == y, and -1 if x < y
}

その後、使用できます

platforms.Sort(ComparePlatforms);

MSDN の例については、こちらを参照してください。

于 2013-04-10T08:10:51.330 に答える