Beispiel #1
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        public void Start()
        {
            _listBid.Clear();
            _activeAuctionPlayer = _lastWinner;                 //dealer+1
            _currentWinningBid   = null;

            _t = -2;
            if (eventAuctionStart != null)
            {
                eventAuctionStart();
            }
        }
Beispiel #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;
                    }
                }
            }
        }