Пример #1
0
        // 4. SetCurrentPlayer
        private void SetPiecePosition(Player player, GamePlayerPiecePosition gamePlayerPiecePosition)
        {
            Quadrant quadrant = GameBoardForm.Quadrants[gamePlayerPiecePosition.Quadrant];
            Ghor     ghor;

            if (gamePlayerPiecePosition.GhorType == "Home")
            {
                ghor = quadrant.QuadrantHome.GhorPositions[gamePlayerPiecePosition.GhorPosition];
            }
            else
            {
                ghor = quadrant.GetGhorByPosition(gamePlayerPiecePosition.GhorPosition);
            }

            try
            {
                Piece piece = player.Pieces[gamePlayerPiecePosition.PieceNumber];
                piece.Movable = false;
                //player.Pieces[gamePlayerPiecePosition.PieceNumber].TransitionPositions = new List<GameBoardPosition>
                //{
                //    new GameBoardPosition(quadrant, ghor)
                //};
                //ShowTransitions(player.Pieces[gamePlayerPiecePosition.PieceNumber]);
                piece.GameBoardPosition = new GameBoardPosition(quadrant, ghor);

                ghor.UIControl.Controls.Add(piece.UIControl);
                piece.UIControl.BringToFront();
            }
            catch (Exception) { }
        }
Пример #2
0
        public ServiceResponse TakeOpponentPiece(int gameId, int opponentPlayerId, int pieceNumber)
        {
            GamePlayerPiecePosition gamePlayerPiecePosition =
                LudoContext.GamePlayerPiecePositions.Single(c => c.GameId == gameId && c.PlayerId
                                                            == opponentPlayerId && c.PieceNumber == pieceNumber);

            GamePlayer gamePlayer = LudoContext.GamePlayers.Single(c => c.GameId == gameId && c.PlayerId == opponentPlayerId);

            gamePlayerPiecePosition.GhorPosition = pieceNumber;
            gamePlayerPiecePosition.GhorType     = Util.GetGhorTypeFromEnum(GhorType.Home);
            gamePlayerPiecePosition.Quadrant     = gamePlayer.Quadrant;

            LudoContext.SaveChanges();

            return(new ServiceResponse
            {
                Data = gamePlayerPiecePosition,
                Messages = new List <Message>()
            });
        }
Пример #3
0
        public ServiceResponse MovePiece(int gameId, int currentPlayerId, int pieceNumber,
                                         Ludo.UI.Class.GameBoardPosition position, int nextPlayerId)
        {
            GamePlayerPiecePosition gamePlayerPiecePosition =
                LudoContext.GamePlayerPiecePositions.Single(c => c.GameId == gameId && c.PlayerId
                                                            == currentPlayerId && c.PieceNumber == pieceNumber);

            gamePlayerPiecePosition.GhorPosition = position.Ghor.Position;
            gamePlayerPiecePosition.GhorType     = Util.GetGhorTypeFromEnum(position.Ghor.GhorType);
            gamePlayerPiecePosition.Quadrant     = position.Quadrant.QuadrantPosition;

            GameProgress gameProgress = LudoContext.GameProgresses.Single(c => c.GameId == gameId);

            // Here check the Dice Stack
            DiceStack diceStack = LudoContext.DiceStacks
                                  .Single(c => c.GameId == gameId);

            if (gameProgress.LastDiceValue == 6)
            {
                if (diceStack.DiceValue3 == 6)
                {
                    gameProgress.CurrentPlayerId         = nextPlayerId;
                    diceStack.DiceValue1                 = -1;
                    diceStack.DiceValue2                 = -1;
                    diceStack.DiceValue3                 = -1;
                    gameProgress.CurrentPlayerDiceRolled = false;
                }
                else
                {
                    gameProgress.CurrentPlayerDiceRolled = false;
                }
            }
            else
            {
                gameProgress.CurrentPlayerId         = nextPlayerId;
                diceStack.DiceValue1                 = -1;
                diceStack.DiceValue2                 = -1;
                diceStack.DiceValue3                 = -1;
                gameProgress.CurrentPlayerDiceRolled = false;
            }
            gameProgress.LastActionDateTime = DateTime.Now;

            //Take opponent pice
            List <GamePlayerPiecePosition> otherPlayerPiecePositions =
                LudoContext.GamePlayerPiecePositions.Where(c => c.GameId == gameId && c.PlayerId
                                                           != currentPlayerId).ToList();

            foreach (GamePlayerPiecePosition piecePosition in otherPlayerPiecePositions)
            {
                if (piecePosition.GhorPosition == gamePlayerPiecePosition.GhorPosition &&
                    piecePosition.Quadrant == gamePlayerPiecePosition.Quadrant)
                {
                    GamePlayer gamePlayer = LudoContext.GamePlayers
                                            .Single(c => c.GameId == gameId && c.PlayerId == piecePosition.PlayerId);

                    piecePosition.Quadrant     = gamePlayer.Quadrant;
                    piecePosition.GhorPosition = piecePosition.PieceNumber;
                    piecePosition.GhorType     = Util.GetGhorTypeFromEnum(GhorType.Home);

                    // Continue Current Player turn
                    gameProgress.CurrentPlayerId         = currentPlayerId;
                    gameProgress.CurrentPlayerDiceRolled = false;
                }
            }

            LudoContext.SaveChanges();

            return(new ServiceResponse
            {
                Data = gamePlayerPiecePosition,
                Messages = new List <Message>()
            });
        }