コード例 #1
0
        public void LoadContent(GraphicsDeviceManager g, Game ga)
        {
            graphics = g;
            graphics.IsFullScreen = false;
            game = ga;


            #region Decorator Pattern
            RedDecorator    rd;
            WhiteDecorator  wd;
            BlueDecorator   bd;
            YellowDecorator yd;
            #endregion

            Knight         k;
            Bishop         b;
            Clockworkbeast cb;
            Horseman       h;
            Mathbeast      mb;


            background = game.Content.Load <Texture2D>("grass.jpg");

            k = new Knight(graphics, new Vector2(40, 100), new Vector2(1, 1));
            #region Decorator Pattern
            rd = new RedDecorator(graphics);
            rd.SetGameEntity(k);
            game_elements.Add(rd);
            #endregion

            b = new Bishop(graphics, new Vector2(80, 200), new Vector2(-1, 1));
            #region Decorator Pattern
            wd = new WhiteDecorator(graphics);
            wd.SetGameEntity(b);
            game_elements.Add(wd);
            #endregion

            cb = new Clockworkbeast(graphics, new Vector2(160, 200), new Vector2(-1, 1));
            #region Decorator Pattern
            wd = new WhiteDecorator(graphics);
            wd.SetGameEntity(cb);
            game_elements.Add(wd);
            #endregion

            h = new Horseman(graphics, new Vector2(560, 310), new Vector2(1, 1));
            #region Decorator Pattern
            rd = new RedDecorator(graphics);
            rd.SetGameEntity(h);
            game_elements.Add(rd);
            #endregion

            mb = new Mathbeast(graphics, new Vector2(660, 200), new Vector2(1, 1));
            #region Decorator Pattern
            rd = new RedDecorator(graphics);
            rd.SetGameEntity(mb);
            wd = new WhiteDecorator(graphics);
            wd.SetGameEntity(rd);
            game_elements.Add(wd);
            #endregion

            mb = new Mathbeast(graphics, new Vector2(260, 300), new Vector2(1, 1));
            #region Decorator Pattern
            rd = new RedDecorator(graphics);
            rd.SetGameEntity(mb);
            wd = new WhiteDecorator(graphics);
            wd.SetGameEntity(rd);
            bd = new BlueDecorator(graphics);
            bd.SetGameEntity(wd);
            yd = new YellowDecorator(graphics);
            yd.SetGameEntity(bd);
            #endregion

            game_elements.Add(yd);
        }
コード例 #2
0
        public void LoadContent(GraphicsDeviceManager g, Game ga)
        {
            graphics = g;
            graphics.IsFullScreen = false;
            game = ga;
            Knight         k;
            Horseman       hm;
            Bishop         b;
            Clockworkbeast cwb;
            Mathbeast      mb;
            MadDog         md;

            background = game.Content.Load <Texture2D>("grass.jpg");
            tekst      = game.Content.Load <Texture2D>("tekst.png");

//			game_elements.Add (new Knight (graphics, new Vector2 (0,30), new Vector2(1,1)));
//			game_elements.Add (new Horseman (graphics, new Vector2(200,30), new Vector2(1,1)));

            tc = new TownCenter(graphics, new Vector2(400, 300), new Vector2(1, 1));

            Random rnd = new Random();

            int xpos, ypos, xdir, ydir, type;

            for (int i = 0; i < 1000; i++)
            {
                xpos = rnd.Next(Globals.left, Globals.right);
                ypos = rnd.Next(Globals.top, Globals.bottom);
                xdir = 1;
                ydir = 1;
                type = rnd.Next(1, 6 + 1);
                switch (type)
                {
                case 1:
                    k = new Knight(graphics, new Vector2(xpos, ypos), new Vector2(xdir, ydir), tc);
                    game_elements.Add(k);
                    #region Observer Pattern
                    tc.RegisterObserver(k);
                    #endregion
                    break;

                case 2:
                    hm = new Horseman(graphics, new Vector2(xpos, ypos), new Vector2(xdir, ydir), tc);
                    game_elements.Add(hm);
                    #region Observer Pattern
                    tc.RegisterObserver(hm);
                    #endregion
                    break;

                case 3:
                    b = new Bishop(graphics, new Vector2(xpos, ypos), new Vector2(xdir, ydir), tc);
                    game_elements.Add(b);
                    #region Observer Pattern
                    tc.RegisterObserver(b);
                    #endregion
                    break;

                case 4:
                    cwb = new Clockworkbeast(graphics, new Vector2(xpos, ypos), new Vector2(xdir, ydir), tc);
                    game_elements.Add(cwb);
                    #region Observer Pattern
                    tc.RegisterObserver(cwb);
                    #endregion
                    break;

                case 5:
                    mb = new Mathbeast(graphics, new Vector2(xpos, ypos), new Vector2(xdir, ydir), tc);
                    game_elements.Add(mb);
                    #region Observer Pattern
                    tc.RegisterObserver(mb);
                    #endregion
                    break;

                case 6:
                    md = new MadDog(graphics, new Vector2(xpos, ypos), new Vector2(xdir, ydir), tc);
                    game_elements.Add(md);
                    #region Observer Pattern
                    tc.RegisterObserver(md);
                    #endregion
                    break;
                }
                System.Threading.Thread.Sleep(1);
            }
        }