public void TestGetPartnerNotInitializedUser() { User partner = ParticipationService.GetPartner(null, null); Assert.AreEqual(null, partner); }
private void NotifyActualPlayer(User user, List <HandCard> handCards, int tableId) { GameTable actualGameTable = GameTableService.GetTable(Games, tableId); List <HandCard> validCards = actualGameTable.CardServiceData.ProveCards(handCards, actualGameTable, user); IHubContext context = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); if (validCards.Find(card => card.IsValid) != null) { Task firstTask = context.Clients.Group(tableId.ToString(), user.ConnectionIds.ToArray()).broadcastSystemMessage(ServerMessages.InformOtherPlayer.Replace("{0}", user.Nickname), tableId, DateTime.Now.Ticks + GetMessageCounter()); firstTask.Wait(); actualGameTable.ActualParticipation = ParticipationService.GetParticipation(actualGameTable, user.Nickname); user.ConnectionIds.ForEach(cId => { Task task = context.Clients.Client(cId).broadcastSystemMessage(ServerMessages.NofityActualPlayer, actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter()); task.Wait(); ColorCode colorCode = GameTableService.GetColorCodeForUser(Games, GameTableService.AreAllEndFieldsUsedForColorCode(actualGameTable, GameTableService.GetColorCodeForUser(Games, user.Nickname, tableId)) ? ParticipationService.GetPartner(user, actualGameTable.Participations).Nickname : user.Nickname, tableId); Clients.Client(cId).notifyActualPlayer(validCards, colorCode, tableId); }); } else { NotifyNextPlayer("", actualGameTable); } }
public void TestGetPartnerNotInitializedParticipation() { User user = new User("test_user", "4"); User partner = ParticipationService.GetPartner(user, null); Assert.AreEqual(null, partner); }
// this method is not used yet, as initial card excchange has not been implemented public void ChooseCardExchange(HandCard selectedCard, int tableId) { GameTable actualGameTable = GameTableService.GetTable(Games, tableId); User actualUser = actualGameTable.Participations.Find(participation => participation.Participant.Identifier == Context.User.Identity.Name).Participant; actualGameTable.CardServiceData.CardExchange(actualUser, ref actualGameTable, selectedCard); User partnerUser = ParticipationService.GetPartner(actualUser, actualGameTable.Participations); partnerUser.ConnectionIds.ForEach(id => { Clients.Client(id).exchangeCard(selectedCard); }); }
public void TestGetPartnerCorrectlyInitialized() { GameTable table = MakeInitialGameTable; User user1 = table.Participations.Find(participation => participation.Participant.Nickname == "user1").Participant; User user3 = table.Participations.Find(participation => participation.Participant.Nickname == "user3").Participant; User partner1 = ParticipationService.GetPartner( table.Participations.Find(participation => participation.Participant.Nickname == "user1").Participant, table.Participations); User partner3 = ParticipationService.GetPartner( table.Participations.Find(participation => participation.Participant.Nickname == "user3").Participant, table.Participations); if (user1.Identifier == partner3.Identifier && user3.Identifier == partner1.Identifier) { Assert.AreEqual(true, true); } else { Assert.AreEqual(true, false); } }
private void NotifyNextPlayer(string nextUserName, GameTable actualGameTable) { string nextPlayerNickname; if (string.IsNullOrWhiteSpace(nextUserName)) { nextPlayerNickname = ParticipationService.GetNextPlayer(actualGameTable, Context.User.Identity.Name); } else { nextPlayerNickname = nextUserName; } User nextUser = UserRepository.Instance.Get().FirstOrDefault(user => user.Value.Nickname == nextPlayerNickname).Value; List <HandCard> cards = actualGameTable.CardServiceData.GetActualHandCards(nextUser, actualGameTable); List <HandCard> validHandCards = actualGameTable.CardServiceData.ProveCards(cards, actualGameTable, nextUser); IHubContext context = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); actualGameTable.ActualParticipation = ParticipationService.GetParticipation(actualGameTable, nextUser.Nickname); Task task = context.Clients.Group(actualGameTable.Identifier.ToString(), nextUser.ConnectionIds.ToArray()).broadcastSystemMessage(ServerMessages.InformOtherPlayer.Replace("{0}", nextUser.Nickname), actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter()); task.Wait(); if (validHandCards.Count > 0 && validHandCards.Find(card => card.IsValid) == null) { if (!nextUser.CardDropped) { context.Clients.Group(actualGameTable.Identifier.ToString(), nextUser.ConnectionIds.ToArray()).broadcastStateMessage(ServerMessages.NoValidCardAvailable.Replace("{0}", nextUser.Nickname), actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter()); nextUser.ConnectionIds.ForEach(id => context.Clients.Client(id).broadcastStateMessage(ServerMessages.YourCardsHaveBeenDropped, actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter())); } } nextUser.ConnectionIds.ForEach(id => { if (validHandCards.Find(card => card.IsValid) != null) { Task chatTask = context.Clients.Client(id).broadcastSystemMessage(ServerMessages.NofityActualPlayer, actualGameTable.Identifier, DateTime.Now.Ticks + GetMessageCounter()); chatTask.Wait(); ColorCode colorCode = GameTableService.GetColorCodeForUser(Games, GameTableService.AreAllEndFieldsUsedForColorCode(actualGameTable, GameTableService.GetColorCodeForUser(Games, nextUser.Nickname, actualGameTable.Identifier)) ? ParticipationService.GetPartner(nextUser, actualGameTable.Participations).Nickname : nextUser.Nickname, actualGameTable.Identifier); Clients.Client(id).notifyActualPlayer(validHandCards, colorCode, actualGameTable.Identifier); } else { actualGameTable.CardServiceData.RemoveAllCardsFromUser(actualGameTable, nextUser); nextUser.CardDropped = true; Clients.Client(id).dropCards(actualGameTable.Identifier); if (actualGameTable.CardServiceData.ProveCardsCount % GlobalDefinitions.NofParticipantsPerTable != 0) { NotifyNextPlayer(ParticipationService.GetNextPlayer(actualGameTable, nextUser.Nickname), actualGameTable); return; } if (!actualGameTable.CardServiceData.AreCardsOnHand(actualGameTable)) { SendCardsForRound(actualGameTable); } else { NotifyNextPlayer(ParticipationService.GetNextPlayer(actualGameTable, nextUser.Nickname), actualGameTable); } } }); }