Example #1
0
        /// <summary>
        /// Делает ход "Первый ход"
        /// </summary>
        /// <param name="move"></param>
        public void MakeFirstMove(FirstMove move)
        {
            if (move == null)
            {
                throw new ArgumentNullException(nameof(move));
            }

            try
            {
                _moveMutex.WaitOne();

                if (IsInvalid)
                {
                    throw new TrueFalseGameException("Игровой стол находится в инвалидном состоянии");
                }

                if (CurrentGame == null)
                {
                    throw new TrueFalseGameException("Игра еще не началась");
                }

                CurrentGame.MakeFirstMove(move);
            }
            finally
            {
                _moveMutex.ReleaseMutex();
            }
        }
        public MakeFirstMoveResult MakeFirstMove(Guid playerId, IReadOnlyCollection <int> cardIds, int rank)
        {
            if (cardIds == null)
            {
                throw new ArgumentNullException(nameof(cardIds));
            }

            var player = _playerRepository.GetById(playerId);

            if (player == null)
            {
                throw new NullReferenceException($"Отсутствует пользователь с id = {playerId}");
            }

            var gameTable = _gameTableRepository.GetByPlayer(player);

            if (gameTable == null)
            {
                throw new Exception($"Игрок с Id = {playerId} не находится за игровым столом");
            }

            var cards = gameTable.GetPlayerCards(playerId, cardIds);

            var move = new FirstMove(cards.Select(c => new PlayingCard(c.Id, c.Suit, c.Rank)).ToList(), (PlayingCardRank)rank, playerId);

            gameTable.MakeFirstMove(move);

            return(new MakeFirstMoveResult()
            {
                NextMoverId = gameTable.CurrentMover.Id,
                GameTableId = gameTable.Id,
                NextPossibleMoves = gameTable.GetNextPossibleMoves().Select(mt => MoveTypesUtils.GetMoveType(mt)).ToList()
            });
        }
        private void OnFirstMoveMade(OnFirstMoveMadeParams @params)
        {
            if (@params == null)
            {
                return;
            }

            var mover = GameTable.Players.FirstOrDefault(gp => gp.Player.Id == @params.MoverId);

            if (mover == null || mover.Player.Id == _stateService.GetSavedPlayer().Id)
            {
                return;
            }

            var nextMover = GameTable.Players.FirstOrDefault(gp => gp.Player.Id == @params.NextMoverId);

            if (nextMover == null)
            {
                return;
            }

            var move = new FirstMove(mover.Player, @params.CardIds.Select(c => new PlayingCard()
            {
                Id = c
            }).ToList())
            {
                Rank = (PlayingCardRank)@params.Rank
            };

            GameTable.MakeFirstMove(move, nextMover.Player.Id);
            GameTable.SetNextPossibleMoves(@params.NextPossibleMoves);
        }
Example #4
0
        public void MakeFirstMove(FirstMove move, Guid nextMoverId)
        {
            if (!IsStarted || CurrentGame.CurrentMover.Id != move.Initiator.Id)
            {
                return;
            }

            CurrentGame.MakeFirstMove(move, Players.First(p => p.Player.Id == nextMoverId).Player);
        }
Example #5
0
        public override int GetHashCode()
        {
            var hashCode = 459464988;

            hashCode = hashCode * -1521134295 + Row.GetHashCode();
            hashCode = hashCode * -1521134295 + Column.GetHashCode();
            hashCode = hashCode * -1521134295 + Color.GetHashCode();
            hashCode = hashCode * -1521134295 + Type.GetHashCode();
            hashCode = hashCode * -1521134295 + FirstMove.GetHashCode();
            hashCode = hashCode * -1521134295 + CanJump.GetHashCode();
            return(hashCode);
        }
Example #6
0
        private bool ValidateFirstMove(FirstMove move)
        {
            if (!ValidateCardsCount(move.Cards))
            {
                return(false);
            }

            if (!CardsPack.IsRankContains(move.Rank))
            {
                return(false);
            }

            return(true);
        }
Example #7
0

        
Example #8
0
        /// <summary>
        /// Делает ход "Первый ход"
        /// </summary>
        /// <param name="move"></param>
        public void MakeFirstMove(FirstMove move)
        {
            if (!CanMakeMove())
            {
                throw new TrueFalseGameException("В данный момент нельзя совершать ходы");
            }

            if (CurrentRound.MovesCount > 0)
            {
                throw new TrueFalseGameException("Первый ход уже был сделан");
            }

            if (move == null)
            {
                throw new ArgumentNullException(nameof(move));
            }

            var gamePlayer = GamePlayers.FirstOrDefault(p => p.Player.Id == move.InitiatorId);

            if (gamePlayer == null)
            {
                throw new TrueFalseGameException($"Игрока с Id = {move.InitiatorId} нет за игровым столом");
            }

            if (CurrentMover.Id != gamePlayer.Player.Id)
            {
                throw new TrueFalseGameException($"Ход вне очереди со стороны пользователя с Id = {move.InitiatorId}");
            }

            if (!ValidateFirstMove(move))
            {
                throw new TrueFalseGameException("Не валидный ход");
            }

            gamePlayer.TakeCards(move.Cards.Select(c => c.Id).ToList());
            CurrentRound.AddMove(move);
            SetNextMover();
        }
Example #9
0
 public void MakeFirstMove(FirstMove move, Player nextMover)
 {
     CurrentRound.AddMove(move);
     CurrentMover = nextMover;
 }
Example #10
0
 public void OnFirstMove()
 {
     FirstMove?.Invoke();
 }