Esempio n. 1
0
        /// <summary>
        /// Event handler for hitting the enter key.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KeyHandler(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape && WordTextbox.IsFocused)
            {
                ResetBoardGreen();
            }

            if (e.Key == Key.Enter && NameTextbox.IsFocused)
            {
                IPTextbox.Focus();
            }
            else if (e.Key == Key.Enter && IPTextbox.IsFocused)
            {
                PlayButton_Click(sender, e);
            }
            else if (e.Key == Key.Enter && WordTextbox.IsFocused)
            {
                if (WordTextbox.Text != "")
                {
                    System.Diagnostics.Debug.WriteLine("Sending " + WordTextbox.Text);
                    clientWork.SendWord(WordTextbox.Text);
                }
                ResetBoardGreen();
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var userId = 0;
            TextBox IDtextbox = (TextBox)IDTextbox;
            if (!Int32.TryParse(IDtextbox.Text, out userId))
            {
                NotifLabel.Text = "Please insert valid ID.";
                IDTextbox.Clear();
            }
            else
            {
                Regex ipParser = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
                TextBox IPtextbox = (TextBox)IPTextbox;
                MatchCollection result = ipParser.Matches(IPtextbox.Text);
                if (!(result.Count == 1))
                {
                    IPTextbox.Clear();
                    NotifLabel.Text = "Please insert valid IP.";
                    IPTextbox.Clear();

                }
                else {
                    var match = result[0];
                    NotifLabel.Text = "Connecting from user " + userId + " to " + match.Value;
                    if (NotifLabel.CanFocus)
                    {
                        NotifLabel.Focus();
                    }
                    //TODO: LoginService
                    SQLiteConnection cnnect = new SQLiteConnection("Data Source=" + dbname + ";Version=3;");
                    cnnect.Open();
                    SQLiteCommand command = new SQLiteCommand();
                    command.Connection = cnnect;
                    command.CommandText = @"INSERT INTO [players]([id], [xcoordinate], [ycoordinate], [size]) "
                                + "VALUES (" + userId + ", 335, 300, 40);";
                    command.CommandType = CommandType.Text;
                    command.ExecuteNonQuery();
                    cnnect.Close();
                    gclient = new GameClient(IPTextbox.Text, this){ Id = userId, IP = IPTextbox.Text };
                }
            }
        }