public void notifyHitMade(int gameId, ServiceCard movedCard) { Trace.WriteLine("SERVICE: notify hit made"); Game g = listOfGames.ElementAt(gameId - 1); g.Players[g.HitsIndex].CardsInHand -= 1; g.NrOfCardsOnTable += 1; Trace.WriteLine("SERVICE: cards on table " + g.NrOfCardsOnTable); if (g.Players[g.HitsIndex].CardsInHand == 0 && g.TopCardIndex <= 0) { g.Players[g.HitsIndex].Finished = true; if (isGameOver(gameId)) { for (int i = 0; i < g.Count; i++) { int looser = getNextActivePlayerIndex(g, g.HitsIndex); Subscriber s = getSubscriberById(g.Players[i].Id); IServiceCallback cb = s.callback; cb.OnGameOver(gameId, g.Players[looser].Id); } return; } else { for (int i = 0; i < g.Count; i++) { Subscriber s = getSubscriberById(g.Players[i].Id); IServiceCallback cb = s.callback; cb.OnPlayerFinished(gameId, g.Players[g.HitsIndex].Id); } } } if (g.NrOfCardsOnTable == 12) { setNextMoveAndHitId(gameId); for (int i = 0; i < g.Count; i++) { Subscriber s = getSubscriberById(g.Players[i].Id); IServiceCallback cb = s.callback; Trace.WriteLine("SERVICE: calling round over"); Trace.WriteLine("SERVICE: hit index" + g.HitsIndex + " moveIndex " + g.MovesIndex); cb.OnHitMade(movedCard, gameId, g.Players[g.HitsIndex].Id); cb.OnRoundOver(gameId, g.Players[g.MovesIndex].Id, g.Players[g.HitsIndex].Id); } } else { for (int i = 0; i < g.Count; i++) { Subscriber s = getSubscriberById(g.Players[i].Id); IServiceCallback cb = s.callback; cb.OnHitMade(movedCard, gameId, g.Players[g.HitsIndex].Id); } } }
/// <summary> /// Sends card to the game. Severely unreasonable approach /// </summary> /// <param name="cardMoved">card moved</param> /// <param name="playerId">playet that made the move</param> /// <param name="gameId">game in view</param> public void notifyMove(ServiceCard cardMoved, long playerId, int gameId) { Game g = listOfGames.ElementAt(gameId - 1); ServiceUser player = getUserById(gameId, playerId); player.CardsInHand -= 1; g.NrOfCardsOnTable += 1; if (player.CardsInHand == 0 && g.TopCardIndex <= 0) { player.Finished = true; if (isGameOver(gameId)) { for (int i = 0; i < g.Count; i++) { ServiceUser p = g.Players[i]; Subscriber s = getSubscriberById(p.Id); IServiceCallback cb = s.callback; cb.OnGameOver(gameId, g.Players[g.HitsIndex].Id); Trace.WriteLine("SERVICE: Calling back to notify Game Over!"); } return; } else { for (int i = 0; i < g.Count; i++) { ServiceUser p = g.Players[i]; Subscriber s = getSubscriberById(p.Id); IServiceCallback cb = s.callback; cb.OnPlayerFinished(gameId, playerId); Trace.WriteLine("SERVICE: Calling back to notify player finished!"); } } } for (int i = 0; i < g.Count; i++) { ServiceUser p = g.Players[i]; Subscriber s = getSubscriberById(p.Id); IServiceCallback cb = s.callback; cb.OnNotifyMove(cardMoved, gameId, playerId, g.Players[g.HitsIndex].Id);//seepärast peakski teenusele lisaks olema back endis veel üks klass Trace.WriteLine("SERVICE: Calling back to notify move done!"); } }