コード例 #1
0
        public ClientManager(string gatewayServerAddress)
        {
            var elem = Document.GetElementById("loading");
            elem.ParentNode.RemoveChild(elem);

            var stats = new XStats();
            Document.Body.AppendChild(stats.Element);

            gameCanvas = CanvasInformation.Create((CanvasElement) Document.GetElementById(gameCanvasName), 0, 0);
            uiCanvas = CanvasInformation.Create((CanvasElement) Document.GetElementById(uiCanvasName), 0, 0);
            UIManager = new UIManager();
            gateway = new Gateway(gatewayServerAddress);

            gameManager = new GameManager(gateway.On, gateway.Emit);
            gateway.On("Area.Main.Login.Response", (user,data) => {
                Window.Alert(Json.Stringify(data));
                                                   });
            gateway.Login(randomName());

            bindInput();
            Window.AddEventListener("resize", e => resizeCanvas());
            jQuery.Document.Resize(e => resizeCanvas());
            int a = 0;
            //Window.SetInterval(() => {},1000 / 60);
            Window.SetInterval(GameTick, 1000 / 10);
            Window.SetInterval(Tick, 1000 / 60);
            Window.SetInterval(GameDraw, 1000 / 60);
            Window.SetInterval(UIDraw, 1000 / 10);

            gameManager.Start(gameCanvas.Context);
            resizeCanvas();
            gameManager.BuildUI(UIManager);
        }
コード例 #2
0
ファイル: IsoGame.cs プロジェクト: dested/Triangles-
        public IsoGame()
        {
            Instance = this;
            var stats = new XStats();
            Document.Body.InsertBefore(stats.Element,Document.Body.ChildNodes[0]);
            jQuery.Select(".xstats").CSS("position", "absolute");

            myCanvas = CanvasInformation.Create(Document.GetElementById("cnvGameBoard"), Size.X, Size.Y);
             //   myCanvas.Canvas.AddEvent("contextmenu", (evt) => { evt.PreventDefault(); });

            init();
            myCanvas.Canvas.Style.BackgroundColor = "#C6F3FF";
            KeyboardJS.Instance().Bind.Key("ctrl",
                                           () =>
                                           {
                                               for (int l = 0; l < myIsoList.Count; l++)
                                               {
                                                   var iso = myIsoList[l];
                                                   foreach (var block in iso.Blocks)
                                                   {
                                                       block.HorizontalLength = 1;
                                                       block.Color = iso.Color;
                                                       block.VerticalLength = 1;
                                                       block.build(myCanvas.Context, iso.X, iso.Y);
                                                   }
                                               }
                                           },
                                           () =>
                                           {

                                           });
            KeyboardJS.Instance().Bind.Key("up",
                                           () => {
                                               int tot = 0;
                                               Window.SetInterval(() => {
                                                                      tot++;

                                                                      for (int x = 0; x < myIsoGrid.Length; x++) {
                                                                          int x1 = x;
                                                                          float curf = tot % 10 < 5 ? .1f : -.1f;
                                                                          Window.SetTimeout(() => {

                                                                                                for (int y = 0; y < myIsoGrid[x1].Length; y++) {
                                                                                                    var iso = myIsoGrid[x1][y];
                                                                                                    foreach (var block in iso.Blocks) {
                                                                                                        block.VerticalLength += curf;
                                                                                                        block.Color = iso.Color;
                                                                                                        block.build(myCanvas.Context, iso.X, iso.Y);
                                                                                                    }

                                                                                                }

                                                                                            },
                                                                                            x * 100);
                                                                      }

                                               }, (int) ( myIsoGrid.Length*100*.7 ));
                                           },
                                           () =>
                                           {

                                           });
            KeyboardJS.Instance().Bind.Key("shift",
                                           () =>
                                           {
                                               for (int l = 0; l < myIsoList.Count; l++)
                                               {
                                                   var iso = myIsoList[l];
                                                   foreach (var block in iso.Blocks) {
                                                       block.Color = iso.Color;
                                                       block.HorizontalLength = (float) Math.Random();
                                                       block.VerticalLength = (float)Math.Random();
                                                       block.build(myCanvas.Context, iso.X, iso.Y);
                                                   }
                                               }
                                           },
                                           () =>
                                           {

                                           });
        }