using System; using System.Collections.Generic; using System.Text; namespace PokerTournamentManager.Framework { public class Table { public const int DEFAULT_NUMBER_OF_SEATS = 10; private int _TotalNumberOfSeats = DEFAULT_NUMBER_OF_SEATS; protected int TotalNumberOfSeats { get { return _TotalNumberOfSeats; } } private Dictionary _Seats; internal List Seats { get { if (_Seats == null) CreateSeats(); return new List(_Seats.Values); } } public int AvailableSeats { get { return Seats.FindAll( delegate (Seat s) { return s.IsAvailable; } ).Count; } } private void CreateSeats() { _Seats = new Dictionary(TotalNumberOfSeats); for (int i = 0; i < TotalNumberOfSeats; i++) { _Seats[i] = new Seat(); } } protected internal Seat GetNextAvailableSeat() { return Seats.Find(delegate(Seat s) { return s.IsAvailable; }); } public void SeatPlayers(List players) { // If we don't have enough available seats, throw em out of here if (AvailableSeats < players.Count) throw new NoAvailableSeatsException(); foreach (Player player in players) { SeatPlayer(player); } } public void SeatPlayer(Player player) { // If we don't have enough available seats, throw em out of here if (AvailableSeats == 0) throw new NoAvailableSeatsException(); else GetNextAvailableSeat().CurrentPlayer = player; } } public class Seat { /// /// Gets a value indicating whether this seat is available. /// /// /// true if this seat is available; otherwise, false. /// public bool IsAvailable { get { return _CurrentPlayer == null; } } private Player _CurrentPlayer; /// /// Gets or sets the player currently occupying this seat. /// /// The player currently occupying this seat. internal Player CurrentPlayer { get { return _CurrentPlayer; } set { _CurrentPlayer = value; } } } }