using System; using System.Collections.Generic; using System.Linq; using System.Text; using DominionBase.Cards; using DominionBase.Players; namespace DominionBase { public class Turn : IDisposable { private Player _Player = null; private Card _GrantedBy = null; private Player _NextPlayer = null; private Card _NextGrantedBy = null; private CardCollection _CardsPlayed = new CardCollection(); private CardCollection _ActionsPlayed = new CardCollection(); private CardCollection _CardsBought = new CardCollection(); private CardCollection _CardsGained = new CardCollection(); private CardCollection _CardsTrashed = new CardCollection(); private CardCollection _CardsPassed = new CardCollection(); private CardCollection _CardsReceived = new CardCollection(); private CardCollection _CardsGainedAfter = new CardCollection(); private CardCollection _CardsTrashedAfter = new CardCollection(); private CardCollection _CardsPassedAfter = new CardCollection(); private CardCollection _CardsReceivedAfter = new CardCollection(); private Boolean _IsTurnFinished = false; private Boolean _ModifiedTurn = false; public Player Player { get { return _Player; } } public Card GrantedBy { get { return _GrantedBy; } set { _GrantedBy = value; } } public Player NextPlayer { get { return _NextPlayer; } set { _NextPlayer = value; } } public Card NextGrantedBy { get { return _NextGrantedBy; } set { _NextGrantedBy = value; } } public CardCollection CardsPlayed { get { return _CardsPlayed; } } public CardCollection ActionsPlayed { get { return _ActionsPlayed; } } public CardCollection CardsBought { get { return _CardsBought; } } public CardCollection CardsGained { get { return _CardsGained; } } public CardCollection CardsTrashed { get { return _CardsTrashed; } } public CardCollection CardsPassed { get { return _CardsPassed; } } public CardCollection CardsReceived { get { return _CardsReceived; } } public CardCollection CardsGainedAfter { get { return _CardsGainedAfter; } } public CardCollection CardsTrashedAfter { get { return _CardsTrashedAfter; } } public CardCollection CardsPassedAfter { get { return _CardsPassedAfter; } } public CardCollection CardsReceivedAfter { get { return _CardsReceivedAfter; } } public Boolean IsTurnFinished { get { return _IsTurnFinished; } } public Boolean ModifiedTurn { get { return _ModifiedTurn; } set { _ModifiedTurn = value; } } public void Clear() { this.CardsPlayed.Clear(); this.ActionsPlayed.Clear(); this.CardsBought.Clear(); this.CardsGained.Clear(); this.CardsTrashed.Clear(); this.CardsPassed.Clear(); this.CardsReceived.Clear(); this.CardsGainedAfter.Clear(); this.CardsTrashedAfter.Clear(); this.CardsPassedAfter.Clear(); this.CardsReceivedAfter.Clear(); } #region IDisposable variables, properties, & methods // Track whether Dispose has been called. private bool disposed = false; public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. this._Player = null; this._GrantedBy = null; this._NextPlayer = null; this._NextGrantedBy = null; this._CardsPlayed.Clear(); this._ActionsPlayed.Clear(); this._CardsBought.Clear(); this._CardsGained.Clear(); this._CardsTrashed.Clear(); this._CardsPassed.Clear(); this._CardsReceived.Clear(); this._CardsGainedAfter.Clear(); this._CardsTrashedAfter.Clear(); this._CardsPassedAfter.Clear(); this._CardsReceivedAfter.Clear(); } // Call the appropriate methods to clean up // unmanaged resources here. // If disposing is false, // only the following code is executed. // Note disposing has been done. disposed = true; } } ~Turn() { Dispose(false); } #endregion public Turn(Player player) { _Player = player; } public void Played(Card card) { if (!_CardsPlayed.Contains(card)) _CardsPlayed.Add(card); _ActionsPlayed.Add(card); } public void Played(IEnumerable cards) { foreach (Card card in cards) this.Played(card); } public void Bought(Card card) { _CardsBought.Add(card); } public void Bought(IEnumerable cards) { _CardsBought.AddRange(cards); } public void Gained(Card card) { if (!this.IsTurnFinished) _CardsGained.Add(card); else _CardsGainedAfter.Add(card); } public void Gained(IEnumerable cards) { if (!this.IsTurnFinished) _CardsGained.AddRange(cards); else _CardsGainedAfter.AddRange(cards); } public void Trashed(Card card) { if (!this.IsTurnFinished) _CardsTrashed.Add(card); else _CardsTrashedAfter.Add(card); } public void Trashed(IEnumerable cards) { if (!this.IsTurnFinished) _CardsTrashed.AddRange(cards); else _CardsTrashedAfter.AddRange(cards); } public void Passed(Card card) { if (!this.IsTurnFinished) _CardsPassed.Add(card); else _CardsPassedAfter.Add(card); } public void Passed(IEnumerable cards) { if (!this.IsTurnFinished) _CardsPassed.AddRange(cards); else _CardsPassedAfter.AddRange(cards); } public void Received(Card card) { if (!this.IsTurnFinished) _CardsReceived.Add(card); else _CardsReceivedAfter.Add(card); } public void Received(IEnumerable cards) { if (!this.IsTurnFinished) _CardsReceived.AddRange(cards); else _CardsReceivedAfter.AddRange(cards); } public void Finished() { _IsTurnFinished = true; } } public class TurnList : List { public int TurnNumber(Player player) { return this.Count(t => t.Player == player && t.GrantedBy == null); } } }