private void SendToUserOrGroup(string message) { if (broker == null) { return; } string senderId = UserName.Length != 0 ? UserName : UserNumber.ToString(); var senderMsg = $"{senderId}: {message}\n"; if (userRadioBtn.Checked) { try { var destUserNumber = Int32.Parse(receiverTextBox.Text); if (destUserNumber == UserNumber) { MessageBox.Show("Cannot send message to yourself."); return; } outputTextBox.AppendText(senderMsg); inputTextBox.Clear(); sendMessageToUser.BeginInvoke(destUserNumber, message, UserNumber, ar => { try { sendMessageToUser.EndInvoke(ar); } catch (Exception ex) { MessageBox.Show(ex.Message); } }, null); } catch (FormatException) { MessageBox.Show("The user number is invalid."); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { var groupName = receiverTextBox.Text; if (groupName.Length == 0) { MessageBox.Show("Please, enter the group name."); return; } outputTextBox.AppendText(senderMsg); inputTextBox.Clear(); sendMessageToGroup.BeginInvoke(groupName, message, UserNumber, ar => { try { sendMessageToGroup.EndInvoke(ar); } catch (Exception ex) { MessageBox.Show(ex.Message); } }, null); } }
/// <summary> /// A parameterless constructor /// </summary> public SudokuConsoleGame() { UserName = "******"; GameDifficulty = Difficulty.MEDIUM; DateCreated = DateTime.Now; UserNumber = SudokuUtilities._random.Next(100000); GameName = (UserName + UserNumber.ToString()).GetHashCode().ToString(); SudokuSolution = SudokuUtilities.SudokuGenerator(); ElementList = new List <Element>(); ElementSB = new StringBuilder(); // Load the solution string which will be used to test the users solution foreach (int _number in SudokuSolution) { SolutionString = SolutionString + _number + " "; } // Load the element list with elements based on the solution string foreach (int _element in SudokuSolution) { Element element = new Element(_element); ElementList.Add(element); } // Determine the amount of elements which will be displayed if (GameDifficulty == Difficulty.EASY || GameDifficulty == Difficulty.MEDIUM) { Display = 36; } else if (GameDifficulty == Difficulty.HARD) { Display = 27; } // Set the amount of hints the user will receive for (int i = 0; i < Display;) { int j = SudokuUtilities._random.Next(0, ElementList.Count - 1); if (ElementList[j].DisplayHint == false) { ElementList[j].DisplayHint = true; i++; } } // Convert the element list into a StringBuilder // This StringBuilder is passed to the diplay to build the game board // This also records the users entries foreach (Element element in ElementList) { if (element.DisplayHint == true) { ElementSB.Append(element.ToString() + " "); } else { ElementSB.Append("_ "); } } // Initialize score to 0 Score = 0; // Initialize the ticks to 0 Ticks = 0; // Initialize demerits to 0 Demerits = 0; }