Ejemplo n.º 1
0
        public bool AddPlayer(Player player)
        {
            if (_players.Count == 2)
                return false;

            _players.Add(player);
            return true;
        }
Ejemplo n.º 2
0
 private void AssignBidByPlayer(Player player, Bid bid)
 {
     _bidPlayerTeam = new Trio<Bid, Player, Team>
                          {
                              First = bid,
                              Second = player,
                              Third = _teams.First(t => t.Players.Contains(player))
                          };
 }
Ejemplo n.º 3
0
        public void Join(string playerId, string playerName, string teamName)
        {
            var teamCount = _teams.Count;

            if (_teams.All(t => t.Name != teamName))
            {
                if (_teams.Count < 2)
                {
                    _teams.Add(new Team { Name = teamName });
                }
                else
                {
                    throw new Exception("Maximum number of teams has been reached!");
                }
            }

            var team = _teams.First(t => t.Name == teamName);
            var player = new Player(playerId, playerName);
            _players.Add(player);

            if (!team.AddPlayer(player))
            {
                throw new Exception("Maximum number of players per team has been reached!");
            }

            _eventHandlerList[PlayerJoinedConstant].SafelyInvoke(this, new PlayersInformationEventArgs { Teams = _teams });

            if (teamCount == 1 && _teams.Count == 2)
            {
                _eventHandlerList[TeamsCompletedConstant].SafelyInvoke(this,
                                                                       new PlayersInformationEventArgs { Teams = _teams });
            }

            if (_players.Count != 4) return;

            _eventHandlerList[PlayersCompletedConstant].SafelyInvoke(this,
                                                                     new PlayersInformationEventArgs { Teams = _teams });
            ReArrangePlayersSeatting();
            SetupGame();
        }
Ejemplo n.º 4
0
        public void Bid(Player player, Bid bid)
        {
            if (_bidPlayerTeam == null)
                AssignBidByPlayer(player, bid);
            else if (bid.CallType == CallType.Call && _bidPlayerTeam.First.CompareTo(bid) > 0)
                throw new Exception("Invalid bid is called!");
            else if (bid.CallType == CallType.Call)
                AssignBidByPlayer(player, bid);

            _biddingPlayerIndex = (_biddingPlayerIndex + 1) % 4;
            _eventHandlerList[BidCalledConstant].SafelyInvoke(this,
                                                              new BidEventArgs
                                                                  {
                                                                      Bid = bid,
                                                                      Caller = player,
                                                                      NextCaller = _players[_biddingPlayerIndex]
                                                                  });

            if (bid.CallType != CallType.Double &&
                (bid.CallType != CallType.Pass || _players[_biddingPlayerIndex] != _bidPlayerTeam.Second))
                return;
            if (bid.CallType == CallType.Double)
                _isDouble = true;

            _cardsPlayers.Keys.ForEach(c => c.Trump = _bidPlayerTeam.First.Suit);
            var bidArgs = new BidEventArgs
                              {
                                  Bid = _bidPlayerTeam.First,
                                  Caller = _bidPlayerTeam.Second
                              };
            _eventHandlerList[BidEndedConstant].SafelyInvoke(this, bidArgs);
        }
Ejemplo n.º 5
0
 public void RemovePlayer(Player player)
 {
     _players.Remove(player);
 }