Exemple #1
0
 public void AddD20()
 {
     DiceStack.Add(new DiceStackDto()
     {
         NumSides = 20
     });
 }
Exemple #2
0
        public ServiceResponse DiceRolled(int gameId)
        {
            int diceValue = GetDiceRandomValue();

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

            gameProgress.CurrentPlayerDiceRolled = true;
            gameProgress.LastDiceValue           = diceValue;
            gameProgress.LastActionDateTime      = DateTime.Now;

            DiceStack diceStack = LudoContext.DiceStacks
                                  .Single(c => c.GameId == gameId);

            if (diceStack.DiceValue1 == -1)
            {
                diceStack.DiceValue1 = diceValue;
                diceStack.DiceValue2 = -1;
                diceStack.DiceValue3 = -1;
            }
            else if (diceStack.DiceValue2 == -1)
            {
                diceStack.DiceValue2 = diceValue;
                diceStack.DiceValue3 = -1;
            }
            else if (diceStack.DiceValue3 == -1)
            {
                diceStack.DiceValue3 = diceValue;
            }
            else
            {
                diceStack.DiceValue1 = diceValue;
                diceStack.DiceValue2 = -1;
                diceStack.DiceValue3 = -1;
            }

            // Check if Current Player has any move, else assign the next player as Current Player

            LudoContext.SaveChanges();

            return(new ServiceResponse
            {
                Data = diceValue,
                Messages = new List <Message>()
            });
        }
Exemple #3
0
        public ServiceResponse UpdateCurrentPlayer(int gameId, int playerId)
        {
            GameProgress gameProgress = LudoContext.GameProgresses.Single(c => c.GameId == gameId);

            gameProgress.CurrentPlayerId         = playerId;
            gameProgress.CurrentPlayerDiceRolled = false;

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

            diceStack.DiceValue1 = -1;
            diceStack.DiceValue2 = -1;
            diceStack.DiceValue3 = -1;

            LudoContext.SaveChanges();

            return(new ServiceResponse
            {
                Data = gameProgress,
                Messages = new List <Message>()
            });
        }
Exemple #4
0
 public void ClearDiceStack()
 {
     DiceStack.Clear();
 }
Exemple #5
0
 public void AddRoll(Roll roll)
 {
     DiceStack.Add(new DiceStackDto(roll));
 }
Exemple #6
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>()
            });
        }