コード例 #1
0
        public GameState(Game1 gameSystem)
        {
            //Add in spawning code. Not yet used.
            Content = gameSystem.Content;
            EntitySpawners.Add("flytrap",delegate(Rectangle position) {return new FlytrapEntity(position);});
            EntitySpawners.Add ("wolf", delegate(Rectangle position) {return null;});
            EntitySpawners.Add ("fireElemental", delegate(Rectangle position) {return null;});
            EntitySpawners.Add("torch",delegate(Rectangle position) {return new TorchEntity(position);});
            EntitySpawners.Add("Terrain",delegate(Rectangle position) {return new TerrainEntity(position);});
            EntitySpawners.Add("boulder",delegate(Rectangle position) {return new BoulderEntity(position);});
            EntitySpawners.Add("pit",delegate(Rectangle position) {return new PitEntity(position);});
            EntitySpawners.Add("water",delegate(Rectangle position) {return new WaterEntity(position);});
            EntitySpawners.Add ("scroll", delegate(Rectangle position) {return null;});
            EntitySpawners.Add ("nothing", delegate(Rectangle position) {return null;});

            scene = new GameScene (this);
            this.gamesystem = gameSystem;

            //Add in level names from a file
            String line;

            //Note that this file name is hard coded!
            System.IO.StreamReader file =
                new System.IO.StreamReader(Path.Combine(Content.RootDirectory,"level_list.txt"));
            while((line = file.ReadLine()) != null)
            {
                line = line.Trim ();
                if (line.StartsWith ("#") || line.Equals("")) {
                    //Skip comments and blank lines.
                    continue;
                }

                //Cheesy arrow separator probably won't be in names.
                //There is no current way to escape it; so avoid putting "==>" in names!
                String[] separator = { "==>" };
                String[] fields = line.Split(separator,StringSplitOptions.RemoveEmptyEntries);

                if (fields.Length != 2) {
                    Console.Out.WriteLine ("Couldn't parse level list: \"" + line + "\"");
                } else {
                    //HACK: These two names are special, and must point to a previously set name.
                    if (fields [0].Equals ("TUTORIAL") || fields [0].Equals ("START")) {
                        if (LevelNames.ContainsKey (fields [1])) {
                            LevelNames.Add (fields [0], LevelNames [fields [1]]);
                        } else {
                            Console.Error.WriteLine ("Could not set " + fields [0] + ", " + fields [1] + " was not set.");
                        }
                    } else {
                        LevelNames.Add (fields [0], fields [1]);
                    }
                }
            }

            file.Close();

            //TODO: Verify "TUTORIAL" and "START" are set, fail appropriately if they are not.
        }
コード例 #2
0
 static void Main()
 {
     game = new Game1();
     game.Run();
 }