/// <summary> /// UC014 Start (Deal) a New Hand /// </summary> /// <see cref="https://docs.google.com/document/d/1OTee6BGDWK2usL53jdoeBOI-1Jh8wyNejbQ0ZroUhcA/edit#heading=h.3z6a7b6nlnjj"/> public void StartNewHand() { while (true) { Monitor.Enter(_lock); while (ActivePlayers.Count < Preferences.MinNumberOfPlayers) { Monitor.Wait(_lock); //throw new NotEnoughPlayersException("Its should be at least 2 active players to start new hand!"); } Monitor.Exit(_lock); if (this.CurrentHand != null && this.CurrentHand.Active) { throw new NotEnoughPlayersException("The previous hand hasnt ended"); } Player dealer = ActivePlayers.ElementAt(dealerIndex); CurrentHand = new Hand(dealer, ActivePlayers, Preferences); CurrentHand.PlayHand(_lock); EndCurrentHand(); /* Note: only the first player joining the room start * the new thread of the hand */ } }