Exemplo n.º 1
0
        void networkcontrol_NewCommand()
        {
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate()
            {
                String str;
                lock (networkcontrol.CommandList_receive)
                {
                    str = networkcontrol.CommandList_receive.Dequeue();
                }
                String[] chips  = str.Split(';');
                MyPerson person = null;
                if (chips[0] == "person")
                {
                    if (chips[1] == "1")
                    {
                        person = person1;
                    }
                    else if (chips[1] == "2")
                    {
                        person = person2;
                    }
                    person.position = new System.Drawing.Point(Int32.Parse(chips[2]), Int32.Parse(chips[3]));
                    if (chips[4] == "left")
                    {
                        person.direction = MyPerson.Direction.Left;
                    }
                    if (chips[4] == "right")
                    {
                        person.direction = MyPerson.Direction.Right;
                    }
                    if (chips[4] == "up")
                    {
                        person.direction = MyPerson.Direction.Up;
                    }
                    if (chips[4] == "down")
                    {
                        person.direction = MyPerson.Direction.Down;
                    }
                    MoveOfPerson(person);
                }
                else if (chips[0] == "bomb")
                {
                    if (chips[1] == "1")
                    {
                        person1.mp -= 20;
                    }
                    else if (chips[1] == "2")
                    {
                        person2.mp -= 20;
                    }
                    int i           = Int32.Parse(chips[4]);
                    TypeOfBomb type = TypeOfBomb.normal;
                    switch (i)
                    {
                    case 0:
                        type = TypeOfBomb.normal;
                        break;

                    case 1:
                        type = TypeOfBomb.around_small;
                        break;

                    case 2:
                        type = TypeOfBomb.around_big;
                        break;

                    case 3:
                        type = TypeOfBomb.row;
                        break;

                    case 4:
                        type = TypeOfBomb.column;
                        break;

                    case 5:
                        type = TypeOfBomb.row_column;
                        break;

                    case 6:
                        type = TypeOfBomb.diagonal;
                        break;
                    }
                    SetBomb(new System.Drawing.Point(Int32.Parse(chips[2]), Int32.Parse(chips[3])), 3000, type);
                    Paragraph p = new Paragraph(new Run("->请注意炸弹!"));
                    Tip.Document.Blocks.Add(p);
                    Tip.ScrollToEnd();
                }
                else if (chips[0] == "brick")
                {
                    List <System.Drawing.Point> temp = new List <System.Drawing.Point>();
                    for (int i = 3; i < chips.Length; i++)
                    {
                        String[] s = chips[i].Split(',');
                        temp.Add(new System.Drawing.Point(Int32.Parse(s[0]), Int32.Parse(s[1])));
                    }
                    if (chips[1] == "creat")
                    {
                        RefreshBlock(temp, true);
                    }
                    else if (chips[1] == "delete")
                    {
                        RefreshBlock(temp, false);
                    }
                }
                else if (chips[0] == "drug")
                {
                    int pid = Int32.Parse(chips[2]);
                    if (chips[1] == "h")
                    {
                        setHpDrug(pid);
                    }
                    else if (chips[1] == "m")
                    {
                        setMpDrug(pid);
                    }
                    Paragraph p = new Paragraph(new Run("->新的药品出现"));
                    Tip.Document.Blocks.Add(p);
                    Tip.ScrollToEnd();
                }
                else if (chips[0] == "reset")
                {
                    if (chips[1] == "1")
                    {
                        person1.hp = Int32.Parse(chips[2]);
                        person1.mp = Int32.Parse(chips[3]);
                    }
                    else if (chips[1] == "2")
                    {
                        person2.hp = Int32.Parse(chips[2]);
                        person2.mp = Int32.Parse(chips[3]);
                    }
                }
                else if (chips[0] == "start!")
                {
                    Paragraph p = new Paragraph(new Run("->游戏开始!"));
                    Tip.Document.Blocks.Add(p);
                    Tip.ScrollToEnd();
                    GameInit();
                }
                else
                {
                    Paragraph p;
                    if (str.StartsWith("Client"))
                    {
                        p = new Paragraph(new Run(str)
                        {
                            Foreground = new SolidColorBrush(Colors.Green)
                        });
                    }
                    else
                    {
                        p = new Paragraph(new Run(str)
                        {
                            Foreground = new SolidColorBrush(Colors.Red)
                        });
                    }
                    Message.Document.Blocks.Add(p);
                    Message.ScrollToEnd();
                }
            });
        }