예제 #1
0
        /// <summary>
        /// A new player join the game session
        /// </summary>
        /// <param name="id"></param>
        public void Join(string id)
        {
            CheckCurrentState(EnumGameSessionState.WaitingForPlayers, "join is only possible during WaitingForPlayers state");

            const int BOARD_SIZE = 10;

            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentException("invalid player id");
            }

            if (P1 == null)
            {
                P1 = playerFactory.New(id, BOARD_SIZE);
            }
            else
            {
                if (id.ToLower() == P1.ID.ToLower())
                {
                    throw new ArgumentException("A player cannot play with him/her self");
                }

                P2    = playerFactory.New(id, BOARD_SIZE);
                State = EnumGameSessionState.WaitingPlayerConfirmation;
            }
        }