コード例 #1
0
 public static TRex GetInstance()
 {
     if (_instance == null)
     {
         _instance = new TRex();
     }
     return(_instance);
 }
コード例 #2
0
        private void InitComponents()
        {
            var director = new Director();
            var builder  = new GraphicsBuilder();

            director.Builder = builder;
            PhysicsFactory physicsFactory = new PhysicsFactory();

            director.BuildTRex();
            Graphics g = new Graphics();

            g.control     = builder.GetProduct();
            trex          = TRex.GetInstance();
            trex.graphics = g;
            trex.physics  = physicsFactory.CreatePhysics("trex", trex.graphics, this);
            view.AddControl(trex);

            director.BuildGround();
            g               = new Graphics();
            g.control       = builder.GetProduct();
            ground          = new Entity();
            ground.graphics = g;
            view.AddControl(ground);

            director.BuildLittleCactus();
            g                     = new Graphics();
            g.control             = builder.GetProduct();
            littleCactus          = new Entity();
            littleCactus.graphics = g;
            littleCactus.physics  = physicsFactory.CreatePhysics("obstacle", littleCactus.graphics, this);
            view.AddControl(littleCactus);

            director.BuildLargeCactus();
            g                    = new Graphics();
            g.control            = builder.GetProduct();
            largeCactus          = new Entity();
            largeCactus.graphics = g;
            largeCactus.physics  = physicsFactory.CreatePhysics("obstacle", largeCactus.graphics, this);
            view.AddControl(largeCactus);

            //score
            scoreGraphics = new ScoreGraphics();
            view.AddControl(scoreGraphics.GetControl());

            //timer
            gameTimer          = new Timer();
            gameTimer.Interval = 20;
            gameTimer.Tick    += new EventHandler(this.GameTimerEvent);

            view.AddKeyDown(new KeyEventHandler(this.keyIsDown));
            view.AddKeyUp(new KeyEventHandler(this.keyIsUp));
            view.SetText("TRex Game");
            viewWidthSize = 800;
            view.SetClientSize(new Size(800, 450));
        }
コード例 #3
0
 public void SetContext(TRex trex)
 {
     this.trex = trex;
 }