コード例 #1
0
        private void SetUpGame()
        {
            WinValue = 0;
            if (world != null)
            {
                world.ResetWorld(Game);
            }
            //Create a new world
            else
            {
                world = new WorldHandler(Game, "TempWorld");
            }
            //318,98 - Temp spawn point until I randomize it
            Vector2 startPoint = new Vector2(318, 98);

            collision = new CollisionHandler(Game, world);
            world.AddCollision(collision);
            //Probably could be moved to a save file to setup templates for start
            #region Resource Setup
            //Initialize the new wallet to start with....this can probably be moved to a file
            Wallet startingResources = new Wallet(new Dictionary <IResource, float>()
            {
                { new Wood(), 500 }, { new Steel(), 500 }, { new Money(), 500 }, { new Likes(), 500 }, { new Iron(), 500 }, { new Energy(), 500 }
            });
            #endregion
            #region util setup
            if (newGame)
            {
                //creates a new input handler instance
                input = InputDefinitions.CreateInput(Game);
                cam   = new Camera(Game, input, world, startPoint);
            }
            #endregion
            projectileManager = new ProjectileManager(Game, cam, collision);
            #region componenets
            //Game components
            cc = new CommandComponent(Game, startingResources, world);

            process = new CommandProccesor(Game, new List <IUnit>(), world, input, cc, cam);
            overlay = new Overlay(Game, input, world, process);

            #endregion
            //Wave handler
            wave = new WaveManager(Game, world, projectileManager);
            //Adds a unit to start
            #region startUnits
            List <IUnit> units = new List <IUnit>();
            units.Add(new Civilian("Base unit", new Vector2(1, 1), 100, 100, startPoint + new Vector2(4, 5), BaseUnitState.Idle, TextureValue.Civilian, TextureValue.Civilian, 1, projectileManager, cc.TeamStats).AddQueueables());
            world.AddMob(units[0]);
            ((BasicUnit)units[0]).SetTeam(1);
            #endregion

            #region buildingPlacement
            #region Allies
            //Center
            Center center = new Center(TextureValue.Center, startPoint, TextureValue.CenterIcon, projectileManager, cc.TeamStats);
            center.AddQueueables();
            center.SetTeam(cc.Team);
            center.SetSpawn(startPoint + center.Size + new Vector2(0, 1));
            center.PlacedTile(GraphicsDevice);
            world.Place(center, startPoint);
            center.Subscribe((IBuildingObserver)cc);
            center.Damage(-5000);
            #endregion
            #region Enemies
            //Portal
            startPoint = new Vector2(82, 190);
            for (int i = 0; i < 3; i++)
            {
                Portal portal = new Portal(TextureValue.Portal, startPoint, TextureValue.Portal, projectileManager, wave.TeamStats, wave);
                startPoint += new Vector2(i * 8, 0);
                portal.SetTeam(cc.Team + 1);
                portal.SetSpawn(startPoint + portal.Size + new Vector2(0, 1));
                portal.PlacedTile(GraphicsDevice);
                world.Place(portal, startPoint);
                portal.Subscribe((IBuildingObserver)cc);
            }
            #endregion
            #endregion
            CommandButton exit = new CommandButton(GraphicsDevice, new ExitGameCommand(), new Vector2(GraphicsDevice.Viewport.Width - 50, 0), TextureValue.None, new Point(50, 30));
            exit.Scale = 1;
            exit.color = Color.SlateGray;
            exit.Text  = "Exit";
            exit.Draw(GraphicsDevice);
            overlay.AddComponent(exit);


            //Initializer
            overlay.Initialize();
            newGame = false;
        }