/// <summary> /// Znajdź obiekt planszy na podstawie typu. /// </summary> /// <param name="boardElementType">typ szukanego elementu</param> /// <param name="message">wiadomośc, przekazywana w razie porażki</param> /// <returns></returns> public static BoardElementDao FindBoardElementByType(BoardElementType boardElementType, out String message) { try { var query = from b in DataManager.DataBaseContext.BoardElements where b.ElementType == boardElementType select b; if (query.Any()) { message = null; return(Mapper.Map <BoardElementDao>(query.First())); } message = "Nie znaleziono szukanego elementu planszy"; return(null); } catch (Exception e) { var declaringType = MethodBase.GetCurrentMethod().DeclaringType; if (declaringType != null) { Logger.LogMessage(declaringType.Name, MethodBase.GetCurrentMethod().Name, e.StackTrace); } message = e.Message; } return(null); }
private List <Position> CheckForPosition(BoardElementType type) { List <Position> targetList = new List <Position>(); for (int i = 1; i < 11; i++) { for (int j = 1; j < 11; j++) { if (OpponentsBoard.BoardElements[i, j] == type) { targetList.Add(new Position(i, j)); } } } return(targetList); }
public static bool AreValid(BoardArray boardArray, IEnumerable <QuoridorPlayer> players, QuoridorPlayer player, params Position[] wallPositions) { if (player.NumberOfWallsAvalaible <= 0) { return(false); } //var boardCopy = new Board(board); foreach (var wallPosition in wallPositions) { if (!BasicValidator.IsWithinBoard(wallPosition)) //just in case, it doesnt cost much { return(false); } if (boardArray[wallPosition] != BoardElementType.EmptyForWall) { return(false); } } var elements = new BoardElementType[wallPositions.Length]; for (var index = 0; index < wallPositions.Length; index++) { elements[index] = boardArray[wallPositions[index]]; boardArray[wallPositions[index]] = BoardElementType.Wall; } var isPassable = IsPassable(boardArray, players); for (var index = 0; index < wallPositions.Length; index++) { boardArray[wallPositions[index]] = elements[index]; } return(isPassable); }
/// <summary> /// Set on ship's position choosen BoardElemType /// </summary> /// <param name="selectedShip">Ship</param> /// <param name="elem">Type</param> public void SetStatusAtShipPos(Ship selectedShip, BoardElementType elem) { switch (selectedShip.Orientation) { case ShipOrientation.OneSizeShip: BoardElements[selectedShip.StartPosition.X, selectedShip.StartPosition.Y] = elem; break; case ShipOrientation.Horisontal: for (int j = selectedShip.StartPosition.Y; j < selectedShip.StartPosition.Y + selectedShip.Size; j++) { BoardElements[selectedShip.StartPosition.X, j] = elem; } break; case ShipOrientation.Vertical: for (int i = selectedShip.StartPosition.X; i < selectedShip.StartPosition.X + selectedShip.Size; i++) { BoardElements[i, selectedShip.StartPosition.Y] = elem; } break; } if (elem == BoardElementType.KilledShip) { //Set an empty Positions around killed ship foreach (Position positions in Ship.GetPositionsAroundShip(selectedShip)) { if (this[positions] != BoardElementType.Border) { this[positions] = BoardElementType.Empty; } } } }