public Cell GetCell(int arenaId, int positionX, int positionY) { IDatabase database = Database.Instance(); var parameters = new List <SqlParameter> { new SqlParameter("@ARENA_ID", arenaId), new SqlParameter("@POSITION_X", positionX), new SqlParameter("@POSITION_Y", positionY), }; var commonData = database.ExecuteQuery( "SELECT PLAYER_ID, IS_MINE FROM ARENA_CELL WHERE ARENA_ID=@ARENA_ID AND POSITION_X=@POSITION_X AND POSITION_Y=@POSITION_Y", parameters.ToArray()); var parameters2 = new List <SqlParameter> { new SqlParameter("@ARENA_ID", arenaId), new SqlParameter("@POSITION_X", positionX), new SqlParameter("@POSITION_Y", positionY), }; var nearMinesCounterStatement = "select count(*) as near_mines from ARENA_CELL where ARENA_ID=@ARENA_ID and " + "( (POSITION_X=(@POSITION_X -1) AND POSITION_Y=@POSITION_Y AND IS_MINE=1) OR " + "(POSITION_X=(@POSITION_X +1) AND POSITION_Y=@POSITION_Y AND IS_MINE=1) OR " + "(POSITION_X=@POSITION_X AND POSITION_Y=(@POSITION_Y +1) AND IS_MINE=1) OR " + "(POSITION_X=@POSITION_X AND POSITION_Y=(@POSITION_Y -1) AND IS_MINE=1) OR " + "(POSITION_X=(@POSITION_X +1) AND POSITION_Y=(@POSITION_Y +1) AND IS_MINE=1) OR " + "(POSITION_X=(@POSITION_X -1) AND POSITION_Y=(@POSITION_Y -1) AND IS_MINE=1) OR " + "(POSITION_X=(@POSITION_X +1) AND POSITION_Y=(@POSITION_Y -1) AND IS_MINE=1) OR " + "(POSITION_X=(@POSITION_X -1) AND POSITION_Y=(@POSITION_Y +1) AND IS_MINE=1) )"; var nearMinesDS = database.ExecuteQuery(nearMinesCounterStatement, parameters2.ToArray()); var cell = ArenaMapper.ToCelEntity(commonData, nearMinesDS); return(cell); }
public Arena FindById(int id) { IDatabase database = Database.Instance(); var parameters = new List <SqlParameter> { new SqlParameter("@ID", id) }; var arenaDs = database.ExecuteQuery(@"SELECT * from ARENA WHERE ID = @ID", parameters.ToArray()); var cellParameters = new List <SqlParameter> { new SqlParameter("@ID", id) }; var cellsDs = database.ExecuteQuery(@"SELECT * from ARENA_CELL WHERE ARENA_ID = @ID", cellParameters.ToArray()); return(ArenaMapper.ToArenaEntity(arenaDs, cellsDs)); }