Esempio n. 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            TerrainSpriteSourceRectangle.LoadSprite();
            UISpriteSheetSourceRectangle.LoadSprite();
            UnitSpriteSheetRectangle.LoadSprite();
            BuildingSpriteSourceRectangle.LoadSprite();
            DirectionArrowSpriteSourceRectangle.LoadSprite();
            CommandSpriteSourceRectangle.LoadSprite();
            BackgroundTerrainSpriteSourceRectangle.LoadSprite();
            BackgroundUnitSpriteSourceRectangle.LoadSprite();
            SelectedMapCellBorderSpriteSourceRectangle.LoadSprite();
            SelectedMapCellCapturePointSpriteSourceRectangle.LoadSprite();
            SelectedMapCellDefenseStarSpriteSourceRectangle.LoadSprite();
            SelectedMapCellLoadedUnitSpriteSourceRectangle.LoadSprite();
            SelectedMapCellUnitInfoSpriteSourceRectangle.LoadSprite();
            BuyMenuFactorySpriteSourceRectangle.LoadSprite();
            BuyMenuAirportHarborSpriteSourceRectangle.LoadSprite();

            graphics.PreferredBackBufferWidth  = Constants.Width;   // set this value to the desired width of your window
            graphics.PreferredBackBufferHeight = Constants.Height;  // set this value to the desired height of your window
            graphics.ApplyChanges();

            DrawingHelper.Initialize(GraphicsDevice);

            Unit.Init();
            Unit.Load();

            CONTENT_MANAGER.gameinstance = this;

            base.Initialize();
        }
Esempio n. 2
0
        //Notify another phayer that you are ready
        //( This method only use to phayer is no host )

        private void InitUI()
        {
            Button button_ready = new Button("Ready", new Point(127, 200), new Vector2(100, 25), CONTENT_MANAGER.arcadefont);

            Button button_selectmap = new Button(UISpriteSheetSourceRectangle.GetSpriteRectangle(SpriteSheetUI.Open), new Point(650, 20), 0.5f);

            Label label_this_ready = new Label("", new Point(50, 50), null, CONTENT_MANAGER.arcadefont, 1);

            Label label_another_ready = new Label("", new Point(490, 227), null, CONTENT_MANAGER.arcadefont, 1);

            Button separate = new Button("", new Point(355, 20), new Vector2(10, 480), CONTENT_MANAGER.arcadefont);

            Label player_name = new Label(Player.Instance.Name, new Point(130, 0), null, CONTENT_MANAGER.arcadefont, 1);

            Label another_player_name = new Label("", new Point(490, 0), null, CONTENT_MANAGER.arcadefont, 1);

            Label room_ID = new  Label(Player.Instance.RoomNumber.ToString(), new Point(360, 0), null, CONTENT_MANAGER.arcadefont, 1);

            // Bind event


            Player.Instance.another_goto_room += (sender, e) =>
            {
                another_player_name.Text = e;
            };

            //Khi chủ phòng load map và gửi cho người chơi khác
            //When select map
            button_selectmap.MouseClick += (sender, e) =>
            {
                try
                {
                    //If you are host, you can load map
                    if (Player.Instance.isHost)
                    {
                        string path = CONTENT_MANAGER.ShowFileOpenDialog(CONTENT_MANAGER.LocalRootPath + @"\map");

                        LoadMap(path);


                        //Send map to another phayer
                        string send = Path.GetFileName(path);

                        Player.Instance.Update(send);
                    }
                }
                catch (Exception er)
                {
                    Utility.HelperFunction.Log(er);
                    CONTENT_MANAGER.ShowMessageBox(er.Message);
                }
            };


            //Người chơi khác nhận map
            //Load map which host had been chosen
            Player.Instance.update += (sender, e) =>
            {
                string path = string.Format("{0}{1}{2}", CONTENT_MANAGER.LocalRootPath, @"\map\", e);
                if (File.Exists(path))
                {
                    loadPath  = path;
                    isLoadMap = true;
                }
            };

            //Event raise when another phayer ready
            Player.Instance.received_chat += (sender, e) =>
            {
                if (e == "Ready")
                {
                    is_another_ready         = true;
                    label_another_ready.Text = "Ready";
                }
                else
                {
                    is_another_ready         = false;
                    label_another_ready.Text = "NotReady";
                }
            };


            //Player is ready
            button_ready.MouseClick += (sender, e) =>
            {
                if (Player.Instance.isHost)
                {
                    if (map != null && is_another_ready)
                    {
                        is_this_ready = true;
                        Player.Instance.ChatWithAnother("Ready");
                    }
                }
                else
                {
                    //Tell another phayer, you start
                    if (!is_this_ready)
                    {
                        is_this_ready         = true;
                        label_this_ready.Text = "Ready";
                        Player.Instance.ChatWithAnother("Ready");
                    }
                    else
                    {
                        is_this_ready         = false;
                        label_this_ready.Text = "";
                        Player.Instance.ChatWithAnother("NotReady");
                    }
                }
            };

            //Add to canvas to draw to screen
            canvas.AddElement("button_selectmap", button_selectmap);
            canvas.AddElement("button_ready", button_ready);
            canvas.AddElement("label_this_ready", label_this_ready);
            canvas.AddElement("separate", separate);
            canvas.AddElement("label_another_ready", label_another_ready);
            canvas.AddElement("another_player_name", another_player_name);
            canvas.AddElement("room_ID", room_ID);
        }