Пример #1
0
        /// <inheritdoc cref="ISessionManager"/>
        public void HumanPlayer_Round(object sender, EventArgs e)
        {
            var  handshapeIdString = string.Empty;
            var  isNumeric         = false;
            var  isValidHandshape  = false;
            uint handshapeId       = 0;
            var  player            = _session.Players.First(p => p.Id == ((RoundEventArgs)e).PlayerId);

            while (string.IsNullOrWhiteSpace(handshapeIdString) || !isNumeric || !isValidHandshape)
            {
                _messageProcessor.Write($"\r\nPlease enter the numeric id of the hand shape player #{player.Id} wishes to play. \r\nThese can be 1.) Rock, 2.) Paper, or 3.) Scissors.\r\n");
                handshapeIdString = _messageProcessor.Read();
                isNumeric         = uint.TryParse((handshapeIdString ?? "").Trim(), out handshapeId);
                isValidHandshape  = Enum.IsDefined(typeof(HandShape), (int)handshapeId) && (HandShape)handshapeId != HandShape.Invalid;
            }

            var result = (HandShape)handshapeId;

            _messageProcessor.Write($"Human player #{player.Id} plays {result}.\r\n");
            _currentGame.RecordRound(player, result);
        }