Esempio n. 1
0
        public ActionResponse PressCell(ActionRequest action)
        {
            var game = gameDal.FindById(action.GameId);

            if (action.PositionX < 1 && action.PositionX > game.Arena.Height)
            {
                return(new ActionResponse {
                    ErrorMessage = "Position X is out of boundaries!"
                });
            }

            if (action.PositionY < 1 && action.PositionY > game.Arena.Weight)
            {
                return(new ActionResponse {
                    ErrorMessage = "Position Y is out of boundaries!"
                });
            }

            var cell = arenaDal.GetCell(game.Arena.Id, action.PositionX, action.PositionY);

            if (cell.Player != null)
            {
                return(new ActionResponse {
                    ErrorMessage = "Cell is already revealed!"
                });
            }

            arenaDal.UpdateCellPlayer(game.Arena.Id, action.PositionX, action.PositionY, game.NextMove.Id);

            if (!cell.IsMine)
            {
                game.NextMove = GetNextPlayer(game.NextMove, game.Players);
            }

            gameDal.Update(game);

            var nextPlayer = playerDal.FindById(game.NextMove.Id);

            return(new ActionResponse {
                HasMine = cell.IsMine, NextMove = nextPlayer.Id, NextMoveName = nextPlayer.NickName, NearMines = cell.NearMines
            });
        }
Esempio n. 2
0
 public Player FindById(int id)
 {
     return(playerDal.FindById(id));
 }