Example #1
0
        private void BtnOpenClient_Click(object sender, RoutedEventArgs e)
        {
            Window window = new Window()
            {
                MinHeight = 450,
                MinWidth  = 600,
            };
            ClientPage page = new ClientPage();

            page.PageExitEvent += (s, args) =>
            {
                window.Close();
            };
            page.BtnBack.Visibility = Visibility.Collapsed;
            window.Content          = page;
            window.Closing         += (s, args) =>
            {
                if (window.Content is ClientPage p)
                {
                    if (MaterialDesignMessageBox.Show("是否要退出游戏?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                    {
                        args.Cancel = true;
                    }
                    else
                    {
                        p.client.Stop();
                    }
                }
            };
            window.Show();
        }
        public static MessageBoxResult Show(string content, string title = "提示", MessageBoxButton button = MessageBoxButton.OK, PackIconKind icon = PackIconKind.Information, Window owner = null)
        {
            MaterialDesignMessageBox messageBox = new MaterialDesignMessageBox();

            messageBox.TBContent.Text = content;
            messageBox.TBTitle.Text   = title;
            messageBox.Owner          = owner;
            if (messageBox.Owner == null)
            {
                messageBox.Owner = Application.Current.MainWindow;
            }
            switch (button)
            {
            case MessageBoxButton.OK:
                messageBox.BtnCancel.Visibility = Visibility.Collapsed;
                messageBox.BtnNo.Visibility     = Visibility.Collapsed;
                messageBox.BtnOK.Visibility     = Visibility.Visible;
                messageBox.BtnYes.Visibility    = Visibility.Collapsed;
                break;

            case MessageBoxButton.OKCancel:
                messageBox.BtnCancel.Visibility = Visibility.Visible;
                messageBox.BtnNo.Visibility     = Visibility.Collapsed;
                messageBox.BtnOK.Visibility     = Visibility.Visible;
                messageBox.BtnYes.Visibility    = Visibility.Collapsed;
                break;

            case MessageBoxButton.YesNo:
                messageBox.BtnCancel.Visibility = Visibility.Collapsed;
                messageBox.BtnNo.Visibility     = Visibility.Visible;
                messageBox.BtnOK.Visibility     = Visibility.Collapsed;
                messageBox.BtnYes.Visibility    = Visibility.Visible;
                break;

            case MessageBoxButton.YesNoCancel:
                messageBox.BtnCancel.Visibility = Visibility.Visible;
                messageBox.BtnNo.Visibility     = Visibility.Visible;
                messageBox.BtnOK.Visibility     = Visibility.Collapsed;
                messageBox.BtnYes.Visibility    = Visibility.Visible;
                break;
            }
            messageBox.PIIcon.Kind = icon;
            messageBox.ShowDialog();
            return(messageBox.result);
        }
Example #3
0
        private void Client_MessageRecieved(string msg)
        {
            //throw new NotImplementedException();
            Dispatcher.Invoke(() =>
            {
#if DEBUG
                HandleChat("(Original Message)", msg);
#endif
                string[] vs = msg.Split('|');
                try
                {
                    switch (vs[0])
                    {
                    case "CHAT":
                        HandleChat(vs[1], vs[2]);
                        break;

                    case "SLOG":
                        HandleChat("", vs[1]);
                        break;

                    case "SBAR":
                        SnbMain.MessageQueue.Enqueue(vs[1]);
                        break;

                    case "ULGI":
                        if (!NameCards.Keys.Contains(vs[1]))
                        {
                            NameCards.Add(vs[1], new Chip()
                            {
                                Content = vs[1]
                            });
                            WrPUsers.Children.Add(NameCards[vs[1]]);
                        }
                        break;

                    case "ULGO":
                        WrPUsers.Children.Remove(NameCards[vs[1]]);
                        NameCards.Remove(vs[1]);
                        break;

                    case "TMIF":
                        if (NameCards.TryGetValue(vs[1], out Chip chip))
                        {
                            if (vs.Length == 3)
                            {
                                chip.Icon = vs[2];
                            }
                            else
                            {
                                chip.Icon = null;
                            }
                        }
                        else
                        {
                            NameCards.Add(vs[1], new Chip()
                            {
                                Content = vs[1],
                                Icon    = vs[2]?.Trim()
                            });
                            WrPUsers.Children.Add(NameCards[vs[1]]);
                        }
                        break;

                    case "TCLR":
                        WrPUsers.Children.Clear();
                        NameCards.Clear();
                        break;

                    case "MBOX":
                        MessageBox.Show(vs[1], "PlaneGame", MessageBoxButton.OK);
                        break;

                    case "GTEM":
                        TBHeader.Text       = "PlaneGame";
                        TeamSelectPage page = new TeamSelectPage(vs[1]);
                        page.Selected      += (ch) =>
                        {
                            client.SendMessage("STEM|" + ch);
                            MyTeam = ch - '0';
                        };
                        NowPage = page;
                        break;

                    case "SGTM":
                        if (NowPage is TeamSelectPage)
                        {
                            NowPage = new GameDefaultPage();
                        }
                        break;

                    case "SCOR":
                        if (NameCards.TryGetValue(vs[1], out chip))
                        {
                            if (vs.Length == 3)
                            {
                                chip.ToolTip = vs[2];
                            }
                            else
                            {
                                chip.ToolTip = null;
                            }
                        }
                        else
                        {
                            NameCards.Add(vs[1], new Chip()
                            {
                                Content = vs[1],
                                ToolTip = vs[2]?.Trim()
                            });
                            WrPUsers.Children.Add(NameCards[vs[1]]);
                        }
                        break;

                    case "SPUS":
                        PutUnitPage p     = new PutUnitPage();
                        p.BtnClear.Click += (s, args) =>
                        {
                            if (MaterialDesignMessageBox.Show("是否清空棋盘?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                            {
                                client.SendMessage("PUCR|");
                            }
                        };
                        p.BtnOK.Click += (s, args) =>
                        {
                            if (MaterialDesignMessageBox.Show("是否确定方案?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                            {
                                client.SendMessage("FPUS|");
                            }
                        };
                        p.Click += (x, y, name, f, r) =>
                        {
                            client.SendMessage("PUTU|" + name + '|' + x + '|' + y + '|' + f + '|' + r);
                        };
                        if (bool.Parse(vs[1]))
                        {
                            p.BtnXFlip.Visibility = p.BtnYFlip.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            p.BtnXFlip.Visibility = p.BtnYFlip.Visibility = Visibility.Collapsed;
                        }
                        if (bool.Parse(vs[2]))
                        {
                            p.BtnRotate.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            p.BtnRotate.Visibility = Visibility.Hidden;
                        }
                        NowPage = p;
                        break;

                    case "UNIT":
                        if (NowPage is PutUnitPage pg)
                        {
                            pg.UpdateUnit(vs[1], int.Parse(vs[2]), vs[3]);
                        }
                        break;

                    case "UCNT":
                        if (NowPage is PutUnitPage pag)
                        {
                            pag.UpdateUnit(vs[1], int.Parse(vs[2]));
                        }
                        break;

                    case "GBRD":
                        if (NowPage is PutUnitPage pge)
                        {
                            pge.board = new GameBoard.FullPlayerGameBoard(vs[1].Split('\n'));
                        }
                        break;

                    case "ASRT":
                        if (NowPage is PutUnitPage pe)
                        {
                            AttackPage attackPage  = new AttackPage(pe.board, MyTeam);
                            attackPage.UnitPreview = pe.UnitPreview;
                            attackPage.Attack     += (t, pnt) =>
                            {
                                client.SendMessage("ATCK|" + t.ToString() + '|' + pnt.Item1 + '|' + pnt.Item2);
                            };
                            NowPage = attackPage;
                        }
                        break;

                    case "AGBR":
                        if (NowPage is AttackPage a)
                        {
                            a.UpdateBoard(int.Parse(vs[1]), new GameBoard.PlayerViewGameBoard(vs[2].Split('\n')));
                        }
                        break;

                    case "SNOW":
                        if (vs[1] == "")
                        {
                            TBHeader.Text = "现在轮到" + vs[2] + "队";
                        }
                        else
                        {
                            TBHeader.Text = "现在轮到玩家" + vs[1] + '(' + vs[2] + ')';
                        }
                        break;

                    case "GPNT":
                        a = NowPage as AttackPage;
                        a.StartGetPoint(int.Parse(vs[1]), int.Parse(vs[2]));
                        break;

                    case "SGPT":
                        a = NowPage as AttackPage;
                        a.StopGetPoint();
                        break;

                    case "AUGB":
                        a = NowPage as AttackPage;
                        a.UpdetePoint(int.Parse(vs[1]), int.Parse(vs[2]), int.Parse(vs[3]), (GameBoardBlock)int.Parse(vs[5]), vs[4]);
                        break;

                    case "LGAM":
                        a = NowPage as AttackPage;
                        a.UpdateBoard(int.Parse(vs[1]), new GameBoard.PlayerViewGameBoard(vs[2].Split('\n')));
                        break;

                    case "LGED":
                        Page detail = NowPage;
                        NowPage     = new GameDefaultPage();
                        SnbMain.MessageQueue.Enqueue("即将开始下一局", "查看上局详情", () =>
                        {
                            new Window()
                            {
                                Content   = detail,
                                MinHeight = 400,
                                MinWidth  = 600
                            }.Show();
                        });
                        break;
                    }
                }
                catch (IndexOutOfRangeException e)
                {
                    SnbMain.MessageQueue.Enqueue("收到无效信息,可能网络不稳定", "查看详情", () =>
                    {
                        LongTextDisplayWindow window = new LongTextDisplayWindow(msg + Environment.NewLine + e.Message);
                        window.Show();
                    }, true);
                }
            });
        }