示例#1
0
        private void InitUI()
        {
            Button btn_create_room = new Button("Create Room", new Point(275, 150), new Vector2(170, 25), CONTENT_MANAGER.arcadefont);

            Button btn_goto_room = new Button("Go To Room", new Point(285, 200), new Vector2(150, 25), CONTENT_MANAGER.arcadefont);

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

            //bind event

            //Click to button go to room
            btn_goto_room.MouseClick += (sender, e) =>
            {
                enterRoom.ShowDialog();
            };

            //Click to button create room
            btn_create_room.MouseClick += (sender, e) =>
            {
                Player.Instance.CreateRoom();
            };

            //Click to ok button after enter room number
            enterRoom.button_OK.Click += (sender, e) =>
            {
                if (enterRoom.textBox_Input.Text != "")
                {
                    Player.Instance.GotoRoom(Convert.ToInt32(enterRoom.textBox_Input.Text));
                }
                else
                {
                    CONTENT_MANAGER.ShowMessageBox("You have't enter room number");
                }
            };

            //Cancel go to room
            enterRoom.button_Cancel.Click += (sender, e) =>
            {
                enterRoom.Hide();
            };

            //Event enter success
            Player.Instance.entered_succeed += (sender, e) =>
            {
                SCREEN_MANAGER.goto_screen("Room_Screen");
            };

            //Event create room success
            Player.Instance.created_room += (_sender, _e) =>
            {
                SCREEN_MANAGER.goto_screen("Room_Screen");
            };

            canvas.AddElement("btn_create_room", btn_create_room);
            canvas.AddElement("btn_goto_room", btn_goto_room);
            canvas.AddElement("label_player_name", label_player_name);
        }
示例#2
0
        /* a map file data structure
         * basically it's a json file serialize from the class Map
         */

        public static Map LoadMap(string data)
        {
            data = CompressHelper.UnZip(data);

            var    mapdata  = data.Split('|');
            string majorver = string.Empty
            , minorver      = string.Empty;

            try
            {
                majorver = JsonConvert.DeserializeObject <string>(mapdata[0]);
                minorver = JsonConvert.DeserializeObject <string>(mapdata[1]);
            }
            catch (Exception e)
            {
                Utility.HelperFunction.Log(e);
            }

            if (string.Compare(majorver, VersionNumber.MajorVersion) != 0 ||
                string.Compare(minorver, VersionNumber.MinorVersion) != 0)
            {
                CONTENT_MANAGER.ShowMessageBox("Cant't load map" + Environment.NewLine + "Version not compatible" + Environment.NewLine + "Game version: " + VersionNumber.GetVersionNumber + Environment.NewLine + "Map version: " + majorver + "." + minorver);
                return(null);
            }

            Map output = new Map();

            try
            {
                output = JsonConvert.DeserializeObject <Map>(mapdata[2]);
            }
            catch (Exception er)
            {
                Utility.HelperFunction.Log(er);
                Environment.Exit(0);
            }

            if (output != null)
            {
                return(output);
            }
            else
            {
                HelperFunction.Log(new Exception(output?.ToString()));
                Environment.Exit(0);
                throw new NullReferenceException();
            }
        }
示例#3
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);
        }