Esempio n. 1
0
        private void PlayButt_Click(object sender, RoutedEventArgs e)
        {
            foreach (var item in PlayerList.Items)
            {
                ListBoxItem lbi = (ListBoxItem)PlayerList.ItemContainerGenerator.ContainerFromItem(item);

                if (lbi.IsSelected && (string)lbi.Content != NickBox.Text)
                {
                    clientIO.SendData("play," + NickBox.Text + "," + (string)lbi.Content);
                    Game game = new Game(client, true, NickBox.Text, (string)lbi.Content);
                    Dispatcher.BeginInvoke((Action)(() => game.Show()));
                    lisen.Abort();
                    Close();
                }
            }
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (mGameEnded)
            {
                NewGame();
                return;
            }

            if (!YouTurn)
            {
                return;
            }

            var button = (Button)sender;

            var column = Grid.GetColumn(button);
            var row    = Grid.GetRow(button);
            var index  = column + (row * 3);

            if (mResults[index] != MarkType.Free)
            {
                return;
            }

            mResults[index] = YouPlayer1 ? MarkType.Cross : MarkType.Nought;

            button.Content = YouPlayer1 ? "X" : "O";

            if (!YouPlayer1)
            {
                button.Foreground = Brushes.Red;
            }
            string CheckWinRet = CheckForWinner();

            if (CheckWinRet == "")
            {
                clientIO.SendData("mv," + index);
                State.Content    = "Ход противника";
                State.Foreground = Brushes.Red;
            }
            else
            {
                clientIO.SendData("mv," + index + "," + CheckWinRet);
            }
            YouTurn = false;
        }
Esempio n. 3
0
        private void ConnButt_Click(object sender, EventArgs e)
        {
            string nick = NickBox.Text;

            Regex regex = new Regex(@"\w");
            Match match = regex.Match(nick);



            if (match.Success && nick.Length < 11)
            {
                try
                {
                    client.Connect("127.0.0.1", 5555);
                }
                catch
                {
                    NickLable.Content    = "Не удалось подключиться к серверу";
                    NickLable.Foreground = Brushes.Red;
                    return;
                }

                NickLable.Content    = "Вы подключены";
                NickLable.Foreground = Brushes.Green;
                NickBox.IsEnabled    = false;
                ConnButt.IsEnabled   = false;

                PlayerList.Items.Add(nick);

                clientIO = new ClientIO(client);

                lisen = new Thread(() => ListendForCommand());
                lisen.Start();
                clientIO.SendData("conn," + nick);
            }
            else if (nick.Length > 10)
            {
                NickLable.Content    = "Максимальная длина имени 10 символов";
                NickLable.Foreground = Brushes.Red;
            }
            else
            {
                NickLable.Content    = "Некорректное имя";
                NickLable.Foreground = Brushes.Red;
            }
        }