Пример #1
0
        public void Test_Menu_Item_Selected(object sender, int index)
        {
            Menu m = (Menu)sender;

            Game1.MessageBox(new IntPtr(0), m.ItemsList[index], "Menu Item Selected", 0);
            test_menu.Hide();
        }
Пример #2
0
 public void Ok_button_clicked(object sender, FormEventData e)
 {
     if (Host_name_textbox.Text.Length > 12)
     {
         Game1.MessageBox(new IntPtr(0), "Player Name cannot more than 12 characters", "Player Name Invalid", 0);
         return;
     }
     if (Room_name_textbox.Text.Length > 12)
     {
         Game1.MessageBox(new IntPtr(0), "Room Name cannot more than 12 characters", "Room Name Invalid", 0);
         return;
     }
     try
     {
         main_game.mRoomScreen.IPAddress = ipTextBox.Text;
         Player player = new Player(Host_name_textbox.Text, Game1.getLocalIP());
         player.Status = true;
         Room r = new Room(player, Room_name_textbox.Text,
                           int.Parse(Number_of_player_textbox.Text));
         ScreenEvent.Invoke(this, new SivEventArgs(4, r));
     }
     catch (Exception ex)
     {
         main_game.mRoomScreen.End(new Command());
         Game1.MessageBox(new IntPtr(0), ex.Message, "Exception", 0);
     }
 }
Пример #3
0
        private void OkClick(object sender, FormEventData e)
        {
            int count = CountSelectChar();

            if (count < 2)
            {
                Game1.MessageBox(new IntPtr(0), "Please select 2 Characters", "Warning!", 0);
            }
            else if (count == 2)
            {
                string           s        = "";
                List <Character> listTemp = new List <Character>();
                for (int i = 0; i < 7; i++)
                {
                    if (charSelectBorder[i].Width == 4)
                    {
                        listTemp.Add(characterPlayerList[i]);
                        s += characterPlayerList[i].CharName + "\n";
                    }
                }
                if (listTemp[0].CharType == listTemp[1].CharType)
                {
                    Game1.MessageBox(new IntPtr(0), "Please select 2 Characters with different type", "Warning!", 0);
                }
                else
                {
                    //Game1.MessageBox(new IntPtr(0), s, "Your Character", 0);
                    if (listTemp[0].CharType == Character.Type.Servant)
                    {
                        room.Player_List[Player_Index].Character1 = listTemp[1];
                        room.Player_List[Player_Index].Character2 = listTemp[0];
                    }
                    else
                    {
                        room.Player_List[Player_Index].Character1 = listTemp[0];
                        room.Player_List[Player_Index].Character2 = listTemp[1];
                    }
                    //Console.WriteLine(room.Player_List[Player_Index].Character1.CharName
                    //    + " " + room.Player_List[Player_Index].Character1.MaxHealth);
                    //Console.WriteLine(room.Player_List[Player_Index].Character2.CharName
                    //    + " " + room.Player_List[Player_Index].Character2.MaxHealth);
                    SelectCharacter();
                    for (int i = 0; i < 7; i++)
                    {
                        if (charSelectBorder[i].Width == 2)
                        {
                            charSelectBorder[i].Visible = false;
                            characterImage[i].Visible   = false;
                        }
                        if (charSelectBorder[i].Width == 4)
                        {
                            characterImage[i].OnClick = null;
                        }
                    }
                    okButton.Visible = false;
                }
            }
        }
Пример #4
0
        private void RequestJoin(Room room)
        {
            Command c = new Command(CommandCode.Can_I_Join);

            byte[] data = c.Serialize();

            try
            {
                tcpClient     = new TcpClient(room.Player_List[room.owner_index].Address, 51002);
                networkStream = tcpClient.GetStream();
                networkStream.Write(data, 0, data.Length);

                Byte[]   bytes = new Byte[1024 * 16];
                DateTime dt    = DateTime.Now;
                while (true)
                {
                    int i;
                    while ((i = networkStream.Read(bytes, 0, bytes.Length)) != 0)
                    {
                        Command c2 = new Command(bytes);
                        if (c2.Command_Code == CommandCode.OK_to_Join)
                        {
                            tcpClient.Close();
                            Player player = new Player(playerName.Text, Game1.getLocalIP());
                            room.Player_List.Add(player);
                            ScreenEvent.Invoke(this, new SivEventArgs(4, room));
                            return;
                        }
                        else if (c2.Command_Code == CommandCode.Cant_Join_Room_Full)
                        {
                            tcpClient.Close();
                            Game1.MessageBox(new IntPtr(0), "Can't join, the room is full.", "Can not Join", 0);
                            return;
                        }
                    }
                    if ((DateTime.Now - dt) > new TimeSpan(0, 0, 3))
                    {
                        tcpClient.Close();
                        Game1.MessageBox(new IntPtr(0), "Host is not responding", "Can not Join", 0);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Game1.MessageBox(new IntPtr(0), ex.Message, "Can not Join", 0);
            }
        }
Пример #5
0
        private void Start_button_clicked(object sender, FormEventData e)
        {
            bool isAllReady = true;

            foreach (Player p in room.Player_List)
            {
                if (!p.Status)
                {
                    isAllReady = false;
                    break;
                }
            }
            if (isAllReady)
            {
                try
                {
                    int     Player_Index = room.findByID(Player_ID);
                    Command c            = new Command(CommandCode.Start_Game, room);
                    byte[]  data2        = c.Serialize();
                    for (int i = 0; i < tcpServerClient.Count; i++)
                    {
                        try
                        {
                            if (i == Player_Index)
                            {
                                continue;
                            }
                            tcpServerClient[i].GetStream().Write(data2, 0, data2.Length);
                        }
                        catch { }
                    }
                }
                catch { }
                ScreenEvent.Invoke(this, new SivEventArgs(1));
            }
            else
            {
                Game1.MessageBox(new IntPtr(0), "All Players in this room are not ready!", "Warning!", 0);
            }
        }
Пример #6
0
        private void ClientReceiver()
        {
            Byte[] bytes = new Byte[1024 * 16];
            while (receiverRun)
            {
                if (StoppedTcp)
                {
                    break;
                }
                else if (receiveTcp.Pending())
                {
                    try
                    {
                        LastReceiveTimeFromHost = DateTime.Now;
                        TcpClient     client = receiveTcp.AcceptTcpClient();
                        NetworkStream stream = client.GetStream();
                        int           i;
                        while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                        {
                            if (!connect_to_host)
                            {
                                client.Close();
                                break;
                            }

                            /*BinaryFormatter bin = new BinaryFormatter();
                             * MemoryStream mem = new MemoryStream(bytes);*/
                            Command c = new Command(bytes);
                            if (c.Command_Code == CommandCode.Standby)
                            {
                                //do nothing
                            }
                            //else if (c.Command_Code == CommandCode.Chat_Message)
                            //{
                            //    chatDisplayTextbox.Text += c.Message;
                            //}
                            else if (c.Command_Code == CommandCode.Update_Room)
                            {
                                this.room = (Room)c.Data1;
                                UpdateRoom();
                            }
                            else if (c.Command_Code == CommandCode.Start_Game)
                            {
                                room = (Room)c.Data1;
                                ScreenEvent.Invoke(this, new SivEventArgs(1));
                            }
                            else if (c.Command_Code == CommandCode.Character_Distribute)
                            {
                                characterPlayerList = (List <Character>)c.Data1;
                                UpdateSelectImageList();
                            }
                        }
                    }
                    catch
                    {
                        ScreenEvent.Invoke(this, new SivEventArgs(0));
                        Game1.MessageBox(new IntPtr(0), "Connection Error!", "Connection Error!", 0);
                    }
                }
                else if ((DateTime.Now - LastReceiveTimeFromHost) > new TimeSpan(0, 0, 5))
                {
                    try
                    {
                        Command c = new Command(CommandCode.Check_Connect);
                        c.SendData(room.Player_List[room.owner_index].Address, 51002);
                    }
                    catch
                    {
                        Game1.MessageBox(new IntPtr(0), "Disconected from host", "Disconnected", 0);
                        ScreenEvent.Invoke(this, new SivEventArgs(0));
                    }
                }
            }
        }