Exemplo n.º 1
0
        private void ProcessClientsListMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormFillingNewClient = delegate
            {
                clientsInfo.Clear();
                clientsInfo.Add(new ClientsInfo()
                {
                    clientID = ChatDialog, clientName = ChatName
                });
                foreach (ClientsInfo nameClient in message.clientsInfo)
                {
                    clientsInfo.Add(nameClient);
                    if (!chatDialogsInfo.ContainsKey(nameClient.clientID))
                    {
                        chatDialogsInfo.Add(nameClient.clientID, new AllDialogsMessages(nameClient.clientName));
                    }
                }
            };

            if (InvokeRequired)
            {
                Invoke(FormFillingNewClient);
            }
            else
            {
                FormFillingNewClient();
            }
        }
Exemplo n.º 2
0
 private void buttonSendMessage_Click_1(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(richTextBoxMessageContent.Text))
     {
         if (client.isClientConnected)
         {
             string messagecontent = richTextBoxMessageContent.Text;
             CommonInformation.Message message;
             if (currentDialog != ChatDialog)
             {
                 message = new CommonInformation.Message(currentDialog, messagecontent);
                 chatDialogsInfo[message.messageReceiverID].messages.Add("Я : " + DateTime.Now.ToString()
                                                                         + " - " + messagecontent);
             }
             else
             {
                 message = new CommonInformation.Message()
                 {
                     messageContent = messagecontent, messageType = CommonInformation.Message.MessageType.Common
                 };
             }
             client.SendMessage(message);
             richTextBoxMessageContent.Clear();
             labelPutMessage.Visible = false;
             UpdateView();
         }
     }
     else
     {
         labelPutMessage.Visible = true;
     }
 }
Exemplo n.º 3
0
        private void ProcessYourAnswerStatusMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormAnswerStatus = delegate
            {
                if (message.isCorrectAnswer)
                {
                    labelAnswerStatus.Text = "Верно!";
                    int points = int.Parse(labelYourPointsNumber.Text);
                    points++;
                    labelYourPointsNumber.Text = points.ToString();
                }
                else
                {
                    labelAnswerStatus.Text = "Неверно!";
                }
            };

            if (InvokeRequired)
            {
                Invoke(FormAnswerStatus);
            }
            else
            {
                FormAnswerStatus();
            }
        }
Exemplo n.º 4
0
        private void ProcessPromptResponseMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormPromptResponse = delegate
            {
                if (message.is5050Prompt)
                {
                    RemoveOneIncorrectAnswer(message.twoWrongAnswersFor5050Prompt[0]);
                    RemoveOneIncorrectAnswer(message.twoWrongAnswersFor5050Prompt[1]);
                }
                else
                {
                    buttonAnswerA.Text = "A   " + message.probabilityOfAnswersCorrectness[0].ToString() + Percent;
                    buttonAnswerB.Text = "B   " + message.probabilityOfAnswersCorrectness[1].ToString() + Percent;
                    buttonAnswerC.Text = "C   " + message.probabilityOfAnswersCorrectness[2].ToString() + Percent;
                    buttonAnswerD.Text = "D   " + message.probabilityOfAnswersCorrectness[3].ToString() + Percent;

                    ChangeButtonColorAccordingToProbabilityOfVarian(buttonAnswerA, message.probabilityOfAnswersCorrectness[0]);
                    ChangeButtonColorAccordingToProbabilityOfVarian(buttonAnswerB, message.probabilityOfAnswersCorrectness[1]);
                    ChangeButtonColorAccordingToProbabilityOfVarian(buttonAnswerC, message.probabilityOfAnswersCorrectness[2]);
                    ChangeButtonColorAccordingToProbabilityOfVarian(buttonAnswerD, message.probabilityOfAnswersCorrectness[3]);
                }
            };

            if (InvokeRequired)
            {
                Invoke(FormPromptResponse);
            }
            else
            {
                FormPromptResponse();
            }
        }
Exemplo n.º 5
0
        private void FormStartGameResponseMesssage(bool isGameContinue)
        {
            var message = new CommonInformation.Message();

            ProcessGameContinuationMessage(message);
            message.mayStartGame = isGameContinue;
            HideButtons();
            client.SendMessage(message);
        }
Exemplo n.º 6
0
        private void buttonInterruptWaitingForOpponent_Click(object sender, EventArgs e)
        {
            ShowDetailsOfTheBeginningOfTheGameWithRandomPlayer(false);
            var message = new CommonInformation.Message()
            {
                messageType = CommonInformation.Message.MessageType.InterruptSearchingForOpponent
            };

            client.SendMessage(message);
        }
Exemplo n.º 7
0
 private void ProcessGameContinuationMessage(CommonInformation.Message message)
 {
     message.messageTime               = DateTime.Now;
     message.messageType               = CommonInformation.Message.MessageType.StartGameResponse;
     message.messageName               = messageSenderName;
     message.messageSenderID           = messageSenderID;
     message.messageReceiverID         = messageReceiverID;
     message.gameTopic                 = gametopic;
     message.isSelectedOpponentForGame = true;
 }
Exemplo n.º 8
0
        private void buttonShowStatistics_Click(object sender, EventArgs e)
        {
            var message = new CommonInformation.Message()
            {
                messageType       = CommonInformation.Message.MessageType.GetStatistics,
                messageReceiverID = currentDialog
            };

            client.SendMessage(message);
        }
Exemplo n.º 9
0
        private void buttonPlayWithRandomPlayer_Click(object sender, EventArgs e)
        {
            ShowDetailsOfTheBeginningOfTheGameWithRandomPlayer(true);
            var message = new CommonInformation.Message()
            {
                messageType = CommonInformation.Message.MessageType.StartGameRequest,
                isSelectedOpponentForGame = false
            };

            client.SendMessage(message);
        }
Exemplo n.º 10
0
        private void buttonLeftGame_Click(object sender, EventArgs e)
        {
            ClearGameField();
            panelGame.Visible = false;
            var message = new CommonInformation.Message()
            {
                messageType = CommonInformation.Message.MessageType.LeftGame
            };

            client.SendMessage(message);
        }
Exemplo n.º 11
0
        private void FormAnswerTheQuestionMessage(int numberOfAnswer)
        {
            var message = new CommonInformation.Message()
            {
                messageType            = CommonInformation.Message.MessageType.PlayerAnswer,
                answeredQuestionNumber = currentQuestionNumber, answerNumber = numberOfAnswer
            };

            currentQuestionNumber++;
            ShowQuestion();
            client.SendMessage(message);
        }
Exemplo n.º 12
0
 private void ProcessCommonMessage(CommonInformation.Message message)
 {
     if (String.IsNullOrEmpty(message.IPAdress))
     {
         chatDialogsInfo[ChatDialog].AddMessage(DateTime.Now.ToShortTimeString()
                                                + " - " + message.messageName + " : " + message.messageContent);
     }
     else
     {
         chatDialogsInfo[ChatDialog].AddMessage(message.messageTime.ToString() + " - " + message.IPAdress
                                                + " - " + message.messageName + " : " + message.messageContent);
     }
 }
Exemplo n.º 13
0
        private void SendPromptRequestMessage(Button buttonToDisable, Button buttonToHide, bool is5050prompt)
        {
            var message = new CommonInformation.Message()
            {
                messageType  = CommonInformation.Message.MessageType.PromptRequest,
                is5050Prompt = is5050prompt, answeredQuestionNumber = currentQuestionNumber
            };

            buttonToDisable.Enabled = false;
            buttonToHide.Visible    = false;
            isPromptUsed            = true;
            client.SendMessage(message);
        }
Exemplo n.º 14
0
        private void buttonShowHistory_Click_1(object sender, EventArgs e)
        {
            comboBoxParticipants.SelectedIndex = StartNumber;
            currentDialog                 = ChatDialog;
            selectedReceiverIndex         = comboBoxParticipants.SelectedIndex;
            labelCurrentClientDialog.Text = chatDialogsInfo[ChatDialog].dialogName;
            var message = new CommonInformation.Message()
            {
                messageType = CommonInformation.Message.MessageType.History
            };

            client.SendMessage(message);
            UpdateView();
        }
Exemplo n.º 15
0
 private void buttonPlay_Click(object sender, EventArgs e)
 {
     if (currentGameTopic != InvalidValue)
     {
         labelTopicIsNotSelected.Visible = false;
         var message = new CommonInformation.Message()
         {
             messageType       = CommonInformation.Message.MessageType.StartGameRequest,
             messageReceiverID = currentDialog, gameTopic = currentGameTopic, isSelectedOpponentForGame = true
         };
         client.SendMessage(message);
     }
     else
     {
         labelTopicIsNotSelected.Visible = true;
     }
 }
Exemplo n.º 16
0
        private void ProcessGameStatusMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormGameStatus = delegate
            {
                ClearGameField();
                richTextBoxGameStatus.Text = message.gameStatus;
            };

            if (InvokeRequired)
            {
                Invoke(FormGameStatus);
            }
            else
            {
                FormGameStatus();
            }
        }
Exemplo n.º 17
0
        private void ProcessGetStatisticsMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormGetStatisticsResult = delegate
            {
                if (message.messageReceiverID != 0)
                {
                    richTextBoxStatistics.Visible = true;
                    richTextBoxStatistics.Clear();
                    if (message.isfailedToGetStatistics)
                    {
                        richTextBoxStatistics.Text = "Данный участник чата ещё ни разу не играл!";
                    }
                    else
                    {
                        richTextBoxStatistics.Text = message.playerInfo.playerName + "(" + message.playerInfo.playerStatus
                                                     + ")" + "\r\n";
                        richTextBoxStatistics.Text += "Игры                     " + message.playerInfo.numberOfPlayedGames + "\r\n";
                        richTextBoxStatistics.Text += "Победы/ничьи/поражения   " + message.playerInfo.winsNumber
                                                      + "/" + message.playerInfo.drawsNumber + "/" + message.playerInfo.losesNumber + "\r\n";
                        richTextBoxStatistics.Text += "Верные/неверные ответы   " + message.playerInfo.rightAnswersNumber
                                                      + "/" + message.playerInfo.wrongAnswersNumber + "\r\n";
                        richTextBoxStatistics.Text += "Количество очков         " + message.playerInfo.pointsNumber + "\r\n";
                    }
                }
                else
                {
                    dataGridViewStatistics.Rows.Clear();
                    dataGridViewStatistics.Visible = true;
                    foreach (PlayerInfo playerInfo in message.playerInfoList)
                    {
                        dataGridViewStatistics.Rows.Add(playerInfo.playerName, playerInfo.numberOfPlayedGames,
                                                        playerInfo.winsNumber, playerInfo.drawsNumber, playerInfo.losesNumber, playerInfo.rightAnswersNumber,
                                                        playerInfo.wrongAnswersNumber, playerInfo.pointsNumber);
                    }
                }
            };

            if (InvokeRequired)
            {
                Invoke(FormGetStatisticsResult);
            }
            else
            {
                FormGetStatisticsResult();
            }
        }
Exemplo n.º 18
0
        private void ProcessOpponentRightAnswerMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormOpponentAnswerStatus = delegate
            {
                int opponentPoints = int.Parse(labelOpponentPointsNumber.Text);
                opponentPoints++;
                labelOpponentPointsNumber.Text = opponentPoints.ToString();
            };

            if (InvokeRequired)
            {
                Invoke(FormOpponentAnswerStatus);
            }
            else
            {
                FormOpponentAnswerStatus();
            }
        }
Exemplo n.º 19
0
        private void ProcessSendGameTopicsMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormFillingGameTopics = delegate
            {
                foreach (string topic in message.gameTopics)
                {
                    comboBoxGameTopics.Items.Add(topic);
                }
            };

            if (InvokeRequired)
            {
                Invoke(FormFillingGameTopics);
            }
            else
            {
                FormFillingGameTopics();
            }
        }
Exemplo n.º 20
0
        private void ProcessServerResponseMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormFillingServerResponse = delegate
            {
                textBoxServerIPAddress.Text    = message.IPAdress;
                textBoxServerPort.Text         = message.serverPort.ToString();
                textBoxServerIPAddress.Enabled = false;
                textBoxServerPort.Enabled      = false;
            };

            if (InvokeRequired)
            {
                Invoke(FormFillingServerResponse);
            }
            else
            {
                FormFillingServerResponse();
            }
        }
Exemplo n.º 21
0
        private void ProcessGameResultsMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormGameResult = delegate
            {
                ClearGameField();
                labelOpponent.Text         = Nothing;
                panelGame.Visible          = false;
                richTextBoxGameStatus.Text = message.gameStatus;
                GiveAccessToPlayButtons(true);
            };

            if (InvokeRequired)
            {
                Invoke(FormGameResult);
            }
            else
            {
                FormGameResult();
            }
        }
Exemplo n.º 22
0
        private void ProcessStartGameResponseMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormAddGameResponse = delegate
            {
                if (message.mayStartGame == false)
                {
                    richTextBoxGameStatus.Text = message.gameStartDetails;
                }
                else
                {
                    questions             = message.questionsToSend;
                    answers               = message.answersToSend;
                    currentQuestionNumber = StartNumber;
                    currentAnswerNumber   = StartNumber;
                    HideStatisticsTables();
                    ShowDetailsOfTheBeginningOfTheGameWithRandomPlayer(false);
                    GiveAccessToPlayButtons(false);
                    panelGame.Visible          = true;
                    labelOpponent.Text         = message.opponentForGameName;
                    richTextBoxGameStatus.Text = NullString;
                    labelAnswerStatus.Text     = Nothing;
                    buttonAnswerA.Enabled      = true;
                    buttonAnswerB.Enabled      = true;
                    buttonAnswerC.Enabled      = true;
                    buttonAnswerD.Enabled      = true;
                    SetPromptsButtonsEnable(true);
                    ShowQuestion();
                    labelYourPointsNumber.Text     = StringWithNull;
                    labelOpponentPointsNumber.Text = StringWithNull;
                }
            };

            if (InvokeRequired)
            {
                Invoke(FormAddGameResponse);
            }
            else
            {
                FormAddGameResponse();
            }
        }
Exemplo n.º 23
0
        private void ProcessStartGameRequestMessage(CommonInformation.Message message)
        {
            ProcessFormFilling FormAddGameRequest = delegate
            {
                richTextBoxGameStatus.Text = message.gameStartDetails;
                buttonAcceptGame.Visible   = true;
                buttonRejectGame.Visible   = true;
                messageSenderID            = message.messageSenderID;
                messageReceiverID          = message.messageReceiverID;
                messageSenderName          = message.messageName;
                gametopic = message.gameTopic;
            };

            if (InvokeRequired)
            {
                Invoke(FormAddGameRequest);
            }
            else
            {
                FormAddGameRequest();
            }
        }
Exemplo n.º 24
0
 private void buttonDisconnect_Click_1(object sender, EventArgs e)
 {
     if (client.isClientConnected)
     {
         if (panelGame.Visible)
         {
             ClearGameField();
             panelGame.Visible = false;
             var message = new CommonInformation.Message()
             {
                 messageType = CommonInformation.Message.MessageType.LeftGame
             };
             client.SendMessage(message);
         }
         client.Disconnect();
         buttonFindServer.Enabled       = true;
         buttonDisconnect.Enabled       = false;
         buttonSendMessage.Enabled      = false;
         buttonShowHistory.Enabled      = false;
         labelDisplayConnection.Text    = NotConnected;
         textBoxServerIPAddress.Enabled = true;
         textBoxServerIPAddress.Text    = NullString;
         textBoxServerPort.Enabled      = true;
         textBoxServerPort.Text         = NullString;
         textBoxName.Enabled            = true;
         textBoxName.Text = NullString;
         comboBoxParticipants.Items.Clear();
         richTextBoxChatContent.Clear();
         labelCurrentClientDialog.Text = Nothing;
         richTextBoxMessageContent.Clear();
         labelNewMessage.Text = Nothing;
     }
     else
     {
         labelDisplayConnection.Text = Nothing;
     }
 }
Exemplo n.º 25
0
 private void ProcessPrivateMessage(CommonInformation.Message message)
 {
     chatDialogsInfo[message.messageSenderID].AddMessage(message.messageTime.ToString() + " : " + message.messageContent);
     labelNewMessage.Text = "Новое сообщение от " + message.messageName;
 }
Exemplo n.º 26
0
 private void ProcessHistoryRequestMessage(CommonInformation.Message message)
 {
     chatDialogsInfo[currentDialog].messages = message.messageHistory;
 }
Exemplo n.º 27
0
        private void ProcessStartGameRequestMessage(Message message)
        {
            if (message.isSelectedOpponentForGame)
            {
                if (message.messageReceiverID == listeningClientMessagesSocket.RemoteEndPoint.GetHashCode())
                {
                    var responseMessage = new Message()
                    {
                        messageType      = Message.MessageType.StartGameResponse,
                        gameStartDetails = "Самому с собой играть нельзя!", mayStartGame = false
                    };
                    Server.SendMessage(responseMessage, listeningClientMessagesSocket);
                }
                else
                {
                    if (isOpponentPlaying(message.messageReceiverID))
                    {
                        var responseMessage = new Message()
                        {
                            messageType      = Message.MessageType.StartGameResponse,
                            gameStartDetails = "Оппонент в текущий момент уже играет!", mayStartGame = false
                        };
                        Server.SendMessage(responseMessage, listeningClientMessagesSocket);
                    }
                    else
                    {
                        message.messageName      = Server.clientNames[listeningClientMessagesSocket.RemoteEndPoint.GetHashCode()];
                        message.gameStartDetails = message.messageName + " хочет играть с Вами. Принять?";
                        if (Server.clientSockets.ContainsKey(message.messageReceiverID))
                        {
                            message.messageSenderID = listeningClientMessagesSocket.RemoteEndPoint.GetHashCode();
                            Server.SendMessage(message, Server.clientSockets[message.messageReceiverID]);
                        }
                        else
                        {
                            Console.WriteLine("Failed to send start game message");
                        }
                    }
                }
            }
            else
            {
                if (Server.waitingForRandomGamePlayers.Count == StartNumber)
                {
                    Server.waitingForRandomGamePlayers.Add(listeningClientMessagesSocket.RemoteEndPoint.GetHashCode());
                }
                else
                {
                    var random      = new Random();
                    int randomValue = random.Next(StartNumber, TopicsNumber);

                    var responseGameMessage = new CommonInformation.Message()
                    {
                        messageType       = Message.MessageType.StartGameResponse,
                        messageSenderID   = Server.waitingForRandomGamePlayers[StartNumber],
                        messageReceiverID = listeningClientMessagesSocket.RemoteEndPoint.GetHashCode(),
                        gameTopic         = randomValue,
                        messageName       = Server.clientNames[Server.waitingForRandomGamePlayers[StartNumber]],
                        mayStartGame      = true
                    };
                    Server.waitingForRandomGamePlayers.RemoveAt(StartNumber);
                    OrganizeGame(responseGameMessage);
                }
            }
        }
Exemplo n.º 28
0
        public void ProcessReceivedMessages(CommonInformation.Message message)
        {
            switch (message.messageType)
            {
            case CommonInformation.Message.MessageType.Common:
                ProcessCommonMessage(message);
                break;

            case CommonInformation.Message.MessageType.Private:
                ProcessPrivateMessage(message);
                break;

            case CommonInformation.Message.MessageType.History:
                ProcessHistoryRequestMessage(message);
                break;

            case CommonInformation.Message.MessageType.SendGameTopics:
                ProcessSendGameTopicsMessage(message);
                break;

            case CommonInformation.Message.MessageType.ClientsList:
                ProcessClientsListMessage(message);
                break;

            case CommonInformation.Message.MessageType.SearchResponce:
                ProcessServerResponseMessage(message);
                break;

            case CommonInformation.Message.MessageType.StartGameRequest:
                ProcessStartGameRequestMessage(message);
                break;

            case CommonInformation.Message.MessageType.StartGameResponse:
                ProcessStartGameResponseMessage(message);
                break;

            case CommonInformation.Message.MessageType.YourAnswerStatus:
                ProcessYourAnswerStatusMessage(message);
                break;

            case CommonInformation.Message.MessageType.OpponentRightAnswer:
                ProcessOpponentRightAnswerMessage(message);
                break;

            case CommonInformation.Message.MessageType.GameStatus:
                ProcessGameStatusMessage(message);
                break;

            case CommonInformation.Message.MessageType.GameResults:
                ProcessGameResultsMessage(message);
                break;

            case CommonInformation.Message.MessageType.GetStatistics:
                ProcessGetStatisticsMessage(message);
                break;

            case CommonInformation.Message.MessageType.PromptResponse:
                ProcessPromptResponseMessage(message);
                break;

            default:
                return;
            }
            if ((message.messageType != CommonInformation.Message.MessageType.SearchResponce) &&
                (message.messageType != CommonInformation.Message.MessageType.StartGameRequest) &&
                (message.messageType != CommonInformation.Message.MessageType.StartGameResponse) &&
                (message.messageType != CommonInformation.Message.MessageType.YourAnswerStatus) &&
                (message.messageType != CommonInformation.Message.MessageType.OpponentRightAnswer) &&
                (message.messageType != CommonInformation.Message.MessageType.GameStatus) &&
                (message.messageType != CommonInformation.Message.MessageType.GameResults) &&
                (message.messageType != CommonInformation.Message.MessageType.GetStatistics) &&
                (message.messageType != CommonInformation.Message.MessageType.PromptResponse))
            {
                UpdateView();
            }
        }