/// <summary> /// Creates new belot game /// </summary> public BelotGame( Player south, Player east, Player north, Player west ) { _southPlayer = south; _eastPlayer = east; _northPlayer = north; _westPlayer = west; _southPlayer.SetPosition( PlayerPosition.South ); _eastPlayer.SetPosition( PlayerPosition.East ); _northPlayer.SetPosition( PlayerPosition.North ); _westPlayer.SetPosition( PlayerPosition.West ); _firstPlayer = _southPlayer; _deals = new List< Deal >(); }
/// <summary> /// Constructor for the class. Creates a new deal during the current game. /// </summary> /// <param name="game"></param> /// <param name="firstPlayer"></param> internal Deal( BelotGame game, Player firstPlayer ) { this._game = game; this._firstPlayer = firstPlayer; _mapEqualCombinationToPlayer = new ListDictionary(); _mapSequentialCombinationToPlayer = new ListDictionary(); _mapBelotCombinationToPlayer = new ListDictionary(); _allCards = InitCards(); _cards = new CardsCollection(); foreach( Card card in _allCards ) { _cards.Add( card ); } _currentAnnouncement = new Announcement( AnnouncementTypeEnum.Pass, false, false ); _game.RaiseDealStarted(); }
internal Player EnterBiddingState() { AnnouncementManager announcementManager = new AnnouncementManager( ); Player current = this._firstPlayer; Announcement announce; while( !announcementManager.IsBiddingFinished ) { announce = current.MakeAnnouncement( announcementManager ); announcementManager.Add( current, announce ); _currentAnnouncement = announcementManager.GetLastValidAnnouncement(); current = _game.GetNextPlayer( current ); } _bidWinner = announcementManager.GetLastBidder(); return announcementManager.GetLastBidder(); }
private void NextDeal() { _southPlayer.Cards.Clear(); _eastPlayer.Cards.Clear(); _northPlayer.Cards.Clear(); _westPlayer.Cards.Clear(); _currentDeal = new Deal( this, _firstPlayer ); _firstPlayer = GetNextPlayer( _firstPlayer ); _deals.Add( _currentDeal ); _currentDeal.DealFirstCards(); Player winner = _currentDeal.EnterBiddingState(); if( _currentDeal.CurrentAnnouncement.Type == AnnouncementTypeEnum.Pass ) { _southPlayer.Cards.Clear(); _eastPlayer.Cards.Clear(); _northPlayer.Cards.Clear(); _westPlayer.Cards.Clear(); FinalizeDeal(); return; } RaiseBiddingCompleted( winner, _currentDeal.CurrentAnnouncement ); _currentDeal.DealRestCards(); _southPlayer.CardPlayed += new Player.CardPlayedHandler( _currentDeal.PlayerPlayedCard ); _northPlayer.CardPlayed += new Player.CardPlayedHandler( _currentDeal.PlayerPlayedCard ); _eastPlayer.CardPlayed += new Player.CardPlayedHandler( _currentDeal.PlayerPlayedCard ); _westPlayer.CardPlayed += new Player.CardPlayedHandler( _currentDeal.PlayerPlayedCard ); _currentDeal.EnterPlayingState(); }
/// <summary> /// Raises the BiddingCompleted event /// </summary> protected void RaiseBiddingCompleted( Player winner, Announcement announce ) { if( BiddingCompleted != null ) { BiddingCompleted( winner, announce ); } }
internal void SetWinner( Player winner ) { _winner = winner; }
private void HumanPlayerIsPlaying( Player player, PlayingManager manager ) { SetPlayerActive( player ); _currentHuman = ( HumanPlayer )player; }
private bool HumanCardCombinationAnnouncing( Player player, CardCombination combination ) { bool isAnnounced = false; _combinationForm.Combination = combination; isAnnounced = ( _combinationForm.ShowDialog() == DialogResult.OK ); if ( isAnnounced ) { CombinationAnnounced( player, combination ); } return isAnnounced; }
private void DrawCards( Player player, CardsCollection cards ) { switch ( player.Position ) { case PlayerPosition.South: _panelSouth.Cards = cards; break; case PlayerPosition.East: _panelEast.Cards = cards; break; case PlayerPosition.North: _panelNorth.Cards = cards; break; case PlayerPosition.West: _panelWest.Cards = cards; break; default: _panelSouth.Cards = cards; break; } }
/// <summary> /// If announcement made by this player is valid according to game rules /// </summary> public bool IsValid( Player player, AnnouncementTypeEnum type, bool isDoubled, bool isRedoubled ) { //no player if( player == null) throw new ArgumentNullException( "Player", "Bidding player cannot be null"); //legal pass if( type == AnnouncementTypeEnum.Pass ) { if( !isDoubled && !isRedoubled ) return true; else return false; } if( _lastValidAnnouncement.CompareTo( type ) < 0 && !isDoubled && !isRedoubled ) return true; if( _lastValidAnnouncement.CompareTo( type ) == 0 && !IsLastValidBidByTeam( player ) && !_lastValidAnnouncement.IsReDoubled) { if( !_lastValidAnnouncement.IsDoubled && isDoubled && !isRedoubled ) return true; if( _lastValidAnnouncement.IsDoubled && !isDoubled && isRedoubled ) return true; } return false; }
private void PlayerHasTurn( Player player ) { #region Announce combinations on first hand if( _playingManager.IsFirstHand && _currentAnnouncement.Type != AnnouncementTypeEnum.NoTrumps ) { CombinationFinder finder = new CombinationFinder( player.Cards ); foreach( CardCombination combination in finder.Combinations ) { bool isValidCombination = false; if( combination is SequentialCombination ) { Player biggest = FindBiggestSequentialCombinationHolder(); CardCombination biggestCombination = null; foreach( DictionaryEntry de in _mapSequentialCombinationToPlayer ) { if( biggest == de.Value as Player ) { biggestCombination = de.Key as CardCombination; break; } } if( (biggest == null) || (combination.Points >= biggestCombination.Points) || (player.Position == biggest.Position || player.Position == _game.GetTeamPlayer( biggest ).Position) ) { isValidCombination = true; } } else { isValidCombination = true; } if( isValidCombination && player.AnnounceCombination( combination ) ) { if( combination is SequentialCombination ) { _mapSequentialCombinationToPlayer.Add( combination, player ); } if( combination is FourEqualsCombination ) { _mapEqualCombinationToPlayer.Add( combination, player ); } } } } #endregion foreach( Card card in player.Cards ) { card.IsSelectable = _playingManager.IsValid( player, card ); } player.PlayCard( _playingManager ); }
private int GetCombinationPoints( Player winner, ListDictionary map ) { int points = 0; foreach( DictionaryEntry de in map ) { if( winner == de.Value || _game.GetTeamPlayer( winner ) == de.Value ) { points += (de.Key as CardCombination).Points; (de.Key as CardCombination).IsCounted = true; } else { (de.Key as CardCombination).IsCounted = false; } } return points; }
private void AddLastTenPoints( Player winner ) { PlayerPosition pos = winner.Position; if( pos == PlayerPosition.East || pos == PlayerPosition.West ) { _eastWestPoints += 10; } else { _northSouthPoints += 10; } }
private void AddBelotCombination( Player player, BelotCombination combination ) { if( player.AnnounceCombination( combination ) ) { _mapBelotCombinationToPlayer.Add( combination, player ); } }
internal void PlayerPlayedCard( Player player, Card playedCard ) { _playingManager.Add( player, playedCard ); player.Cards.Remove( playedCard ); foreach( Card card in player.Cards ) { card.IsSelectable = false; } if( _playingManager.IsHandClosed ) { Hand lastHand = _playingManager.GetLastHand(); CalculatePoints( lastHand ); _game.HandIsClosed( lastHand ); NextHand(); } else { PlayerHasTurn( _game.GetNextPlayer( player ) ); } }
private void CompPlayerBidded( Player player, Announcement currentAnnounce ) { SetPlayerActive( null ); bool isActive = currentAnnounce.CompareTo( _game.CurrentDeal.CurrentAnnouncement ) > 0; _passedAnnouncesForm.AddMessage( player.Name, GetAnnouncementString( currentAnnounce ), isActive ); Thread.Sleep( 1000 - Properties.Settings.Default.Speed*50 ); this.Text = StringResources.lastBid; this.Text += GetAnnouncementString( currentAnnounce ); this.Text += StringResources.saidBy; this.Text += player.Name; }
private void ComputerPlayerPlayed( Player player, Card playedCard ) { SetPlayerActive( null ); MoveCardToTable( player.Position, playedCard ); }
/// <summary> /// Stores and announcement made by a player /// </summary> /// <param name="player"></param> /// <param name="announce"></param> internal void Add( Player player, Announcement announce ) { if( !IsValid( player, announce )) throw new InvalidOperationException( "You cannot bid lower than current" ); if( (_players.Count != 0)&&( player == (Player)_players[_players.Count - 1] ) ) throw new InvalidOperationException( "You cannot bid twice" ); _announces.Add( announce ); _players.Add( player ); if( announce.Type != AnnouncementTypeEnum.Pass ) { _lastValidAnnouncement = announce; _lastBidder = player; } else { //4 successive passes end bidding or 3 passes after a legal bid if( _announces.Count > 3 ) { if( ( ( _announces[_announces.Count-1]).Type == AnnouncementTypeEnum.Pass ) && ( ( _announces[_announces.Count-2]).Type == AnnouncementTypeEnum.Pass ) && ( ( _announces[_announces.Count-3]).Type == AnnouncementTypeEnum.Pass ) && ( _lastBidder != null || (_announces[_announces.Count-4]).Type == AnnouncementTypeEnum.Pass ) ) { this._isBiddingFinished = true; } } } }
private void GameOver( Player winner1, Player winner2 ) { MessageBox.Show( winner1.Name + StringResources.and + winner2.Name + StringResources.win, StringResources.congratulations, MessageBoxButtons.OK ); _resultsTable.Rows.Clear(); }
private bool IsLastValidBidByTeam( Player player ) { if( _lastBidder == player ) return true; if( _players.Count >= 2 ) { if( _players[_players.Count-2] == _lastBidder ) return true; } return false; }
private Announcement HumanPlayerIsBidding( Player player, AnnouncementManager manager ) { SetPlayerActive( player ); _announceForm.Bid( player, manager ); _announceForm.ShowDialog(); this.Update(); Announcement currentAnnounce = _announceForm.Announce; this.Text = StringResources.lastBid; this.Text += GetAnnouncementString( currentAnnounce ); this.Text += StringResources.saidBy; this.Text += player.Name; bool isActive = currentAnnounce.CompareTo( _game.CurrentDeal.CurrentAnnouncement ) > 0; _passedAnnouncesForm.AddMessage( player.Name, GetAnnouncementString( currentAnnounce ), isActive ); return currentAnnounce; }
/// <summary> /// If announcement made by this player is valid according to game rules /// </summary> public bool IsValid( Player player, Announcement announce ) { if( player == null) throw new ArgumentNullException( "Player", "Bidding player cannot be null"); if( announce == null) throw new ArgumentNullException( "Announcement", "Announcement cannot be null"); return IsValid( player, announce.Type, announce.IsDoubled, announce.IsReDoubled ); }
private void SetPlayerActive( Player player ) { if ( player == null ) { _picPos.Image = Properties.Resources.AllPos; } else { switch ( player.Position ) { case PlayerPosition.South: _picPos.Image = Properties.Resources.SouthPos; break; case PlayerPosition.East: _picPos.Image = Properties.Resources.EastPos; break; case PlayerPosition.North: _picPos.Image = Properties.Resources.NorthPos; break; case PlayerPosition.West: _picPos.Image = Properties.Resources.WestPos; break; } } }
public void AddCombination( Player player, CardCombination combination ) { _mapCombinationToPlayer.Add( combination, player ); }
internal Player GetTeamPlayer( Player currentPlayer ) { if( currentPlayer == _southPlayer ) return _northPlayer; if( currentPlayer == _eastPlayer ) return _westPlayer; if( currentPlayer == _northPlayer ) return _southPlayer; if( currentPlayer == _westPlayer ) return _eastPlayer; return _southPlayer; }
public void Bid( Player player, AnnouncementManager manager ) { this._manager = manager; this._player = player; }
/// <summary> /// Raises the DealStarted event /// </summary> protected void RaiseGameCompleted( Player winner1, Player winner2 ) { if( GameCompleted != null ) { GameCompleted( winner1, winner2 ); } }
private void BiddingCompleted( Player winner, Announcement finalAnnounce ) { this.Text = StringResources.gameOf; this.Text = GetAnnouncementString( finalAnnounce ); this.Text = StringResources.saidBy; this.Text = winner.Name; _passedAnnouncesForm.AddSpaces(); }
private void CombinationAnnounced( Player player, CardCombination combination ) { _passedAnnouncesForm.AddMessage( player.Name, GetCombinationString( combination ), false ); _dealResultForm.AddCombination( player, combination ); }
private void CheckForBelotCombination( Player player, Card playedCard ) { CardsCollection foundCards = new CardsCollection(); CardColor trumpColor = GetTrumpColor( ); if( _currentAnnouncement.Type == AnnouncementTypeEnum.AllTrumps ) { if( _currentHand.IsEmpty ) { CheckBelotForValidColor( player, playedCard, foundCards ); } else { if( playedCard.CardColor == GetPlayingColor( _currentHand ) ) { CheckBelotForValidColor( player, playedCard, foundCards ); } } } else if( _currentAnnouncement.Type != AnnouncementTypeEnum.NoTrumps && playedCard.CardColor == trumpColor ) { CheckBelotForValidColor( player, playedCard, foundCards ); } if( foundCards.Count != 0 ) { BelotFound( player, new BelotCombination( foundCards, 20) ); } }