コード例 #1
0
ファイル: Player.cs プロジェクト: Pezz0/ProgettoInfo3
        /// <summary>
        /// Invokes the method that chooses the bid.
        /// </summary>
        /// <returns>The bid chosen.</returns>
        internal BidBase InvokeChooseBid()
        {
            if (!Board.Instance.IsAuctionPhase)
            {
                throw new WrongPhaseException("A player can place a bid only during the auction phase", "Auction");
            }

            BidBase bid = _controller.ChooseBid();

            if (bid != null && bid < Board.Instance.currentAuctionWinningBid && bid is NotPassBidBase)
            {
                throw new BidNotEnoughException("The new bid is not enough to beat the winning one", bid);
            }

            if (bid == null)
            {
                return(null);
            }
            return(bid.ChangeBidder(this));
        }
コード例 #2
0
        /// <summary>
        /// Updates the game. must be continuously called in order to continue with the game. Stopping would mean a pause in the game.
        /// </summary>
        public void Update()
        {
            if (IsAuctionPhase)                 //auction
            {
                BidBase bid = _activeAuctionPlayer.InvokeChooseBid();

                if (bid != null)
                {
                    //place a bid
                    _listBid.Add(bid);

                    if (bid is NotPassBidBase)
                    {
                        _currentWinningBid = (NotPassBidBase)bid;
                    }

                    List <Player> pass = new List <Player> ();

                    foreach (BidBase b in _listBid)
                    {
                        if (b is PassBid)
                        {
                            pass.Add(b.bidder);
                        }
                    }

                    //find the next bidder
                    _activeAuctionPlayer = _activeAuctionPlayer + 1;

                    while (pass.Contains(_activeAuctionPlayer))
                    {
                        _activeAuctionPlayer++;
                    }

                    //event place a bid.
                    if (eventIPlaceABid != null && bid.bidder == Me)
                    {
                        eventIPlaceABid(bid);
                    }

                    if (eventSomeonePlaceABid != null && bid.bidder != Me)
                    {
                        eventSomeonePlaceABid(bid);
                    }



                    //check if the auction is still open
                    if (pass.Count >= PLAYER_NUMBER - 1 && _listBid.Count >= PLAYER_NUMBER)
                    {
                        _t = -1;
                        if (_currentWinningBid == null)
                        {
                            _gameType = EnGameType.MONTE;
                            _t        = 41;
                        }
                        else if (_currentWinningBid is CarichiBid)                              //carichi
                        {
                            _gameType = EnGameType.CARICHI;

                            _currentWinningBid.bidder.Role = EnRole.CHIAMANTE;
                            _winningPoint = ((CarichiBid)_currentWinningBid).point;

                            _t = 0;

                            if (eventPlaytimeStart != null)
                            {
                                eventPlaytimeStart();
                            }
                        }
                    }
                }
            }
            else if (IsFinalizePhase)                   //finalize
            {
                EnSemi?seme = _currentWinningBid.bidder.InvokeChooseSeme();

                if (seme.HasValue)
                {
                    _gameType = EnGameType.STANDARD;

                    _calledCard = GetCard(seme.Value, ((NormalBid)_currentWinningBid).number);

                    _winningPoint = ((NormalBid)_currentWinningBid).point;

                    //set the roles
                    _calledCard.initialPlayer.Role       = EnRole.SOCIO;
                    currentAuctionWinningBid.bidder.Role = EnRole.CHIAMANTE;

                    _t = 0;

                    if (eventPlaytimeStart != null)
                    {
                        eventPlaytimeStart();
                    }
                }
            }
            else if (IsPlayTime)                        //playtime

            {
                if (numberOfCardOnBoard == PLAYER_NUMBER)
                {
                    Card max = _cardOnBoard [0];
                    for (int i = 1; i < PLAYER_NUMBER; i++)
                    {
                        if (_cardOnBoard [i] > max)
                        {
                            max = _cardOnBoard [i];
                        }
                    }

                    _lastWinner = max.initialPlayer;

                    foreach (Card c in _cardOnBoard)
                    {
                        c.FinalPlayer = max.initialPlayer;
                    }

                    //event pick up
                    if (eventPickTheBoard != null)
                    {
                        eventPickTheBoard(_lastWinner, _cardOnBoard);
                    }

                    _cardOnBoard.Clear();

                    if (IsLastTurn)
                    {
                        if (eventPlaytimeEnd != null)
                        {
                            eventPlaytimeEnd();
                        }

                        //save last game in the archive
                        Archive.Instance.Add(new GameData(DateTime.Now, _cardGrid, _players, _listBid, _gameType, _calledCard, _winningPoint));
                        Archive.Instance.SaveLastGame();

                        _t = 41;
                    }
                }
                else
                {
                    Card card = ActivePlayer.InvokeChooseCard();
                    if (card != null)
                    {
                        card.PlayingTime = _t;
                        _cardOnBoard.Add(card);

                        //Events play a card
                        if (eventIPlayACard != null && ActivePlayer == Me)
                        {
                            eventIPlayACard(ActivePlayer, card);
                        }

                        if (eventSomeonePlayACard != null && ActivePlayer != Me)
                        {
                            eventSomeonePlayACard(ActivePlayer, card);
                        }

                        ++_t;
                    }
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChiamataLibrary.BidNotEnoughException"/> class.
 /// </summary>
 /// <param name="message">Exception description</param>
 /// <param name="bid">The bid.</param>
 public BidNotEnoughException(string message, BidBase bid) : base(message)
 {
     _bid = bid;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChiamataLibrary.BidNotEnoughException"/> class.
 /// </summary>
 /// <param name="bid">The bid.</param>
 public BidNotEnoughException(BidBase bid) : base()
 {
     _bid = bid;
 }