public void Excecute(ClientObject client, ServerObject server, RoomObject room, string packet = "") { Console.WriteLine("Get room info"); var response = new GetRoomInfoResponse(); response.TableQuestions = new System.Collections.ObjectModel.ReadOnlyDictionary <string, IEnumerable <Core.Objects.Question> >(room.Game.TableQuestions); foreach (var item in response.TableQuestions) { foreach (var q in item.Value) { Debug.Write((q.Id > 0 ? 1 : 0)); } Debug.WriteLine(""); } response.Players = room.GetAllPlayers(); response.Selector = room.Selector.Player; string packetResponse = JsonConvert.SerializeObject(response); room.SendMessageToDefiniteClient(packetResponse, client); Console.WriteLine("Get room successfully"); }
public void Excecute(ClientObject client, ServerObject server, RoomObject room, string packet = "") { lock (locker) { var response = new SetRespondentResponse(); if (room.Respondent == null) { room.Respondent = client; response.Status = ResponseStatus.Ok; response.Player = client.Player; string packetResponse = JsonConvert.SerializeObject(response); room.SendMessageToDefiniteClient(packetResponse, client); BlockAnswerButtonForAllPlayers(room, client); //останавливаем таймер для нажатия кнопки "ответить" room.Game.StopAnswerButtonClickTimer(); room.Game.StartAnswerTimer(); } else { response.Status = ResponseStatus.Bad; response.Player = room.Respondent.Player; string packetResponse = JsonConvert.SerializeObject(response); room.SendMessageToAllClientsExceptSendingClient(packetResponse, client); } } }
public void Excecute(ClientObject client, ServerObject server, RoomObject room, string packet = "") { room.Game.StopAnswerTimer(); Console.WriteLine("Check answer"); var request = JsonConvert.DeserializeObject <CheckAnswerRequest>(packet); var response = new CheckAnswerResponse(); response.Status = DB.CheckAnswer(request.Question); Console.WriteLine($"Answer status: {response.Status }"); int points = 0; if (response.Status == ResponseStatus.Ok) { points = request.Question.Points; room.Selector = client; //очищаем клиентов ответивших не верно room.Game.RemoveQuestionFromTable(request.Question.Id); room.Respondents.Clear(); NotifyPlayersAboutUpdateRoom(client, room, UpdateRoomType.UpdateTable); room.Game.StopAnswerButtonClickTimer(); } else { points = request.Question.Points * -1; room.Game.listClickButton.Add(client); room.Respondents.Add(client); //если все ответили не верно, назначаем селектором первого игрока if (room.Clients.Count == room.Respondents.Count) { room.Game.RemoveQuestionFromTable(request.Question.Id); if (room.Clients.Count != 0) { room.Selector = room.Clients.First(); } room.Respondents.Clear(); NotifyPlayersAboutUpdateRoom(client, room, UpdateRoomType.UpdateTable); room.Game.StopAnswerButtonClickTimer(); } else { room.Game.StartAnswerButtonClickTimer(); } if (room.Respondents.Count != 0) { //обновляем статус кнопки ответа для всех игроков ChangeAnswerButtonPropertyForPlayers(room); } } client.UpdatePoints(points); string packetResponse = JsonConvert.SerializeObject(response); room.SendMessageToDefiniteClient(packetResponse, client); //отправляем уведомление об обновлении счета игрока NotifyPlayersAboutUpdateRoom(client, room, UpdateRoomType.UpdatePlayers); }
private void ChangeAnswerButtonPropertyForPlayers(RoomObject room) { foreach (var client in room.Clients) { if (!room.Respondents.Contains(client)) { var response = new BlockAnswerButtonResponse(); response.IsEnabled = true; string packetResponse = JsonConvert.SerializeObject(response); room.SendMessageToDefiniteClient(packetResponse, client); } } }