//Check if the move is not out of bounds... // if moving left were subtracting spaces, if moving right were adding spaces. // if moving up were subtracting spaces, if were moving down were adding spaces. private bool ValidateTranslation(Directions.Direction dir, int spaces) { if (dir == Directions.Direction.Up && (PosX - spaces) < 0) { Validation.InvalidMovement(dir, PosX); return(false); } else if (dir == Directions.Direction.Right && (PosY + spaces) > Board.BoardSizeY) { Validation.InvalidMovement(dir, Board.BoardSizeY - PosY - 1); return(false); } else if (dir == Directions.Direction.Down && (PosX + spaces) > Board.BoardSizeX) { Validation.InvalidMovement(dir, Board.BoardSizeX - PosX - 1); return(false); } else if (dir == Directions.Direction.Left && (PosY - spaces) < 0) { Validation.InvalidMovement(dir, PosY); return(false); } return(true); }
public RoboticRover(int xPosition, int yPosition, Directions.Direction direction, Plateau plateau) { this.XPosition = xPosition; this.YPosition = yPosition; this.RoboticRoverDirection = direction; this.Plateau = plateau; }
/// <summary> /// Collect the border values for the direction within the given octant node /// (so if north, it will collect all values on(within) the north face of the current node) /// </summary> /// <param name="currentNode"></param> /// <param name="direction"></param> /// <param name="values">Used for recursion</param> /// <returns></returns> TType[] collectBorderValues(OctreeNode <TType> currentNode, Directions.Direction direction, List <TType> values = null) { values ??= new List <TType>(); // if the current node is solid, so is the border in the direction we're searching, just send back the current value if (currentNode.isSolid) { values.Add(currentNode.value); } else { // if the current node isn't solid, we'll need to check all blocks within it in the bordering direction. foreach (Octants.Octant octant in direction.getOctants()) { OctreeNode <TType> childNode = currentNode.getChild(octant); // if there's no child we just use the current node value for that part of the face, // if there is a child we need to grab it's values to that facial direction. if (childNode != null) { collectBorderValues(childNode, direction, values); } else { values.Add(currentNode.parent.value); } } } return(values.ToArray()); }
public static void SetDirection(string strDirection) { try { if (strDirection.Trim() != null) { switch (strDirection) { case "N": direction = Directions.Direction.N; break; case "S": direction = Directions.Direction.S; break; case "E": direction = Directions.Direction.E; break; case "W": direction = Directions.Direction.W; break; default: break; } } } catch (Exception ex) { throw ex; } }
private Trail AddNextRoom(HashSet <IRoom> searchedRooms, Directions.Direction direction, IExit exit, IMobileObject performer, Queue <Trail> newTrails, Trail trail) { if (trail.Distance > 3) //don't follow someone that has gotten to far away to follow { return(null); } if (exit != null) { IRoom nextRoom = Zones[exit.Zone].Rooms[exit.Room]; if (searchedRooms.Contains(nextRoom)) { return(null); } trail.Distance++; IMobileObject foundMob = FindMobInRoom(nextRoom, performer); if (foundMob != null) { return(trail); } if (!searchedRooms.Contains(nextRoom)) { trail.Room = nextRoom; newTrails.Enqueue(trail); searchedRooms.Add(nextRoom); } } return(null); }
private Trail AddNextRoom(HashSet <IRoom> searchedRooms, Directions.Direction direction, IExit exit, string targetKeyword, Queue <Trail> newTrails, Trail trail) { if (exit != null) { IRoom nextRoom = GlobalReference.GlobalValues.World.Zones[exit.Zone].Rooms[exit.Room]; if (searchedRooms.Contains(nextRoom)) { return(null); } //check to make sure the next room does not contain the attribute NoTrack //if so return null if (nextRoom.Attributes.Contains(RoomAttribute.NoTrack)) { return(null); } trail.Distance++; IMobileObject foundMob = FindMobInRoom(nextRoom, targetKeyword); if (foundMob != null) { return(trail); } if (!searchedRooms.Contains(nextRoom)) { trail.Room = nextRoom; newTrails.Enqueue(trail); searchedRooms.Add(nextRoom); } } return(null); }
public void AttemptToFollow(Directions.Direction direction, IMobileObject performer, IMobileObject followedTarget) { RunEnchantments(performer, EventType.AttemptToFollow, new EventParamerters() { Direction = direction, Performer = performer, FollowedTarget = followedTarget }); GlobalReference.GlobalValues.Logger.Log(performer, LogLevel.DEBUG, $"{performer.SentenceDescription} attempted to follow {followedTarget.SentenceDescription} {direction.ToString()}."); }
public void LeaveRoom(IMobileObject performer, Directions.Direction direction) { RunEnchantments(performer, EventType.LeaveRoom, new EventParamerters() { Performer = performer, Direction = direction }); GlobalReference.GlobalValues.Logger.Log(performer, LogLevel.DEBUG, $"{performer.SentenceDescription} left room {performer.Room.ToString()}."); }
public void CloseDoor(int x, int y, Directions.Direction direction) { string dir = direction.ToString().Substring(0, 1); string key = rooms[x, y].ToString(); key = key.Replace(dir, ""); rooms[x, y] = RoomDictionary.GetRoom(key); }
/// <summary> /// Get if this block's face in the given direction is exposed to air/transparent blocks /// </summary> /// <param name="value"></param> /// <param name="direction"></param> /// <returns>If the neighbor to the given direction is solid</returns> public static bool BlockFaceIsExposed(this int value, Directions.Direction direction) { // Get the mask of neighboring block data from the int return(( // trim the neighbor's mask off of the full block data int value ((byte)(value >> 8)) // create a mask (ex: 000100) with the 1 in the spot = to the value of the // direction we want to test for, and & compare them. & (1 << (direction.Value)) // if it is not = 000000 after the and, the bit is set. ) != 0); }
/// <summary> /// Move the focus/central loaded point of the level /// </summary> /// <param name="direction">the direction the focus has moved</param> /// <param name="magnitude">the number of chunks in the direction that the foucs moved</param> public override void adjustFocus(Directions.Direction direction) { List <Coordinate> chunksToLoad = new List <Coordinate>(); List <Coordinate> chunksToUnload = new List <Coordinate>(); // add new chunks to the load queue in the given direction if (Array.IndexOf(Directions.Cardinal, direction) > -1) { // NS if (direction.Value == Directions.North.Value || direction.Value == Directions.South.Value) { // grab the chunks one to the direction of the current loaded ones for (int i = 0; i < LoadedChunkDiameter; i++) { // the z comes from the extreem bound, either the northern or southern one, y is 0 Coordinate chunkToLoad = loadedChunkBounds[direction.Value == Directions.North.Value ? 1 : 0] + direction.Offset; // the x is calculated from the SW corner's W, plust the current i chunkToLoad.x = i + loadedChunkBounds[1].x - LoadedChunkDiameter; // calculate the chunk to unload on the opposite side Coordinate chunkToUnload = loadedChunkBounds[direction.Value == Directions.North.Value ? 0 : 1] + direction.Offset; chunkToUnload.x = i + loadedChunkBounds[1].x - LoadedChunkDiameter; // add the values chunksToLoad.Add(chunkToLoad); chunksToUnload.Add(chunkToUnload); } // EW } else { for (int i = 0; i < LoadedChunkDiameter; i++) { Coordinate chunkToLoad = loadedChunkBounds[direction.Value == Directions.East.Value ? 1 : 0] + direction.Offset; chunkToLoad.z = i + loadedChunkBounds[0].z; Coordinate chunkToUnload = loadedChunkBounds[direction.Value == Directions.East.Value ? 0 : 1] + direction.Offset; chunkToUnload.z = i + loadedChunkBounds[0].z; chunksToLoad.Add(chunkToLoad); chunksToUnload.Add(chunkToUnload); } } } // queue the collected values addChunkColumnsToLoadingQueue(chunksToLoad.ToArray()); addChunkColumnsToUnloadingQueue(chunksToUnload.ToArray()); }
public bool tryMove(Directions.Direction dir) { int nx = man.x + Directions.Instance.dx[dir]; int ny = man.y + Directions.Instance.dy[dir]; if (!correct(nx, ny, Constants.cntWidth, Constants.cntHeight) || field[nx, ny]) { return(false); } if (haveBox(nx, ny) != -1) { int nnx = nx + Directions.Instance.dx[dir]; int nny = ny + Directions.Instance.dy[dir]; if (!correct(nnx, nny, Constants.cntWidth, Constants.cntHeight) || field[nnx, nny] || haveBox(nnx, nny) != -1) { return(false); } int idx = haveBox(nx, ny); boxes[idx].x += Directions.Instance.dx[dir]; boxes[idx].y += Directions.Instance.dy[dir]; if (haveLoader(nnx, nny)) { boxesScore++; } if (haveLoader(nx, ny)) { boxesScore--; } } man.x += Directions.Instance.dx[dir]; man.y += Directions.Instance.dy[dir]; if (haveBonus(man.x, man.y) != -1) { bonusesScore++; bonuses.RemoveAt(haveBonus(man.x, man.y)); } return(true); }
//Handles movement of the turtle based on direction, spaces, and pens state public void Translate(Directions.Direction direction, int spaces, Pen.PenStates pen) { if (ValidateTranslation(direction, spaces)) { var draw = (pen == Pen.PenStates.Down); //draw holds the state of our pen. switch (direction) { //if moving up were moving in -X case Directions.Direction.Up: if (draw) { Board.UpdateBoardX(PosX, spaces, LEFTUP, PosY); } PosX -= spaces; break; //if moving down were moving in +X case Directions.Direction.Down: if (draw) { Board.UpdateBoardX(PosX, spaces, RIGHTDOWN, PosY); } PosX += spaces; break; //if moving Left were moving in -Y case Directions.Direction.Left: if (draw) { Board.UpdateBoardY(PosY, spaces, LEFTUP, PosX); } PosY -= spaces; break; //if moving Right were moving in +Y case Directions.Direction.Right: if (draw) { Board.UpdateBoardY(PosY, spaces, RIGHTDOWN, PosX); } PosY += spaces; break; } } }
public void setMoveDirection(Directions.Direction dir) { moveDirection = dir; setFacingDirection(dir); //So the cultist can't annoyingly be pushed around in an axis other than the one it's moving on. if(Directions.isHorizontalDirection(dir)) { freezeYMovement(); } else if(Directions.isVerticalDirection(dir)) { freezeXMovement(); } moving = true; }
/// <summary> /// Get the 'cousin' of the current node in the given dirrection /// (cousin being a node of the same size with different parents) /// </summary> /// <param name="direction"></param> /// <param name="uncleValue">Get the value of the cousin, can be used in case no node is returned.</param> /// <returns></returns> OctreeNode <TType> getCousinToThe(Directions.Direction direction, out TType cousinValue) { OctreeNode <TType> uncleNode = getUncleToThe(direction, out cousinValue); // if there's an uncle, we need to find the child element at the location // 1 to the direction of this one inside of that uncle with a min resolution // of this one's size. if (uncleNode != null) { OctreeNode <TType> cousinNode = uncleNode.getNodeAt( position.go(direction, size), size ); cousinValue = cousinNode.value; return(cousinNode); } // if we don't find an uncle, it's outside the level return(null); }
private void OpenClose(Directions.Direction direction, bool openClose) { switch (direction) { case Directions.Direction.North: North = openClose; break; case Directions.Direction.South: South = openClose; break; case Directions.Direction.East: East = openClose; break; case Directions.Direction.West: West = openClose; break; } }
private bool AddToPath(Room[,] rooms, List <Position> path, int minRooms) { Position currentPos = path[path.Count - 1]; bool mazeEnds = false; //get the directions it can go bool CanEndMaze = path.Count >= minRooms; List <Directions.Direction> dir = GetRoomDirectionsAvailableToGo(rooms, currentPos, CanEndMaze); if (dir.Count > 0) { //pick one Directions.Direction direction = dir[random.Next(dir.Count)]; mazeEnds = OpenDoor(currentPos.X, currentPos.Y, direction); switch (direction) { case Directions.Direction.North: currentPos = new Position(currentPos.X, currentPos.Y - 1); break; case Directions.Direction.South: currentPos = new Position(currentPos.X, currentPos.Y + 1); break; case Directions.Direction.East: currentPos = new Position(currentPos.X + 1, currentPos.Y); break; case Directions.Direction.West: currentPos = new Position(currentPos.X - 1, currentPos.Y); break; } path.Add(currentPos); } else { path.RemoveAt(path.Count - 1); } return(mazeEnds); }
/// <summary> /// Get the uncle octant to the given direction of the current octant /// (uncle being an octant bordeing the parent sharing a parent.) /// </summary> /// <param name="direction"></param> /// <param name="uncleValue">Get the value of the uncle, can be used in case no node is returned.</param> /// <returns></returns> OctreeNode <TType> getUncleToThe(Directions.Direction direction, out TType uncleValue) { // we want to make sure we aren't too far up for uncles if (!isRoot && !parent.isRoot) { Octants.Octant currentParentOctant = parent.parent.getChildOctantFor(parent.position); Octants.Octant uncleOctant = currentParentOctant.toThe(direction); // if we have an uncle at this level, return the node and or value from the grandparent if (uncleOctant != null) { OctreeNode <TType> uncleNode = parent.parent.getChild((Octants.Octant)uncleOctant); uncleValue = uncleNode == null ? parent.parent.value : uncleNode.value; return(uncleNode); // if we don't, we want to see if this node's parent has the uncle we need. } else { return(parent.getUncleToThe(direction, out uncleValue)); } } // there's no uncles, only brothers and parents. uncleValue = default; return(null); }
/// <summary> /// Check if the neigboring node(s) in the given direction is(are) solid against this node. /// </summary> /// <param name="direction"></param> /// <returns></returns> TType[] getValuesToThe(Directions.Direction direction) { if (isRoot) { return(new TType[1]); } TType defaultValue; Octants.Octant currentOctant = parent.getChildOctantFor(position); Octants.Octant brotherOctant = currentOctant.toThe(direction); // if the octant shares a parent, move downwards into the found brother OctreeNode <TType> neighborNode; if (brotherOctant != null) { neighborNode = parent.getChild(brotherOctant); defaultValue = parent.value; // else we have to get the cousin } else { neighborNode = getCousinToThe(direction, out defaultValue); } // if we found a node at all, collect the values of that node. if (neighborNode != null) { return(collectBorderValues(neighborNode, direction.Reverse)); // if there is no neighboring node, return the value we generated for the position instead } else { return(new TType[1] { defaultValue }); } }
private Trail LookForMobInNextRoom(IMobileObject performer, string target, HashSet <IRoom> searchedRooms, Queue <Trail> newTrails, IRoom currentRoom, Directions.Direction direction, Trail existingTrail) { Trail trail = null; switch (direction) { case Directions.Direction.North: trail = AddNextRoom(performer, searchedRooms, direction, currentRoom.North, target, newTrails, existingTrail); break; case Directions.Direction.East: trail = AddNextRoom(performer, searchedRooms, direction, currentRoom.East, target, newTrails, existingTrail); break; case Directions.Direction.South: trail = AddNextRoom(performer, searchedRooms, direction, currentRoom.South, target, newTrails, existingTrail); break; case Directions.Direction.West: trail = AddNextRoom(performer, searchedRooms, direction, currentRoom.West, target, newTrails, existingTrail); break; case Directions.Direction.Up: trail = AddNextRoom(performer, searchedRooms, direction, currentRoom.Up, target, newTrails, existingTrail); break; case Directions.Direction.Down: trail = AddNextRoom(performer, searchedRooms, direction, currentRoom.Down, target, newTrails, existingTrail); break; } return(trail); }
protected void BuildRestOfRooms(Room[,] rooms, int fillPercent) { List <Position> listOfAvaibleRoomsToOpenDoors = new List <Position>(); for (int x = 0; x < rooms.GetLength(0); x++) { for (int y = 0; y < rooms.GetLength(1); y++) { if (rooms[x, y] != null) { listOfAvaibleRoomsToOpenDoors.Add(new Position(x, y)); } } } List <Position> listOfPopulatedRooms = new List <Position>(listOfAvaibleRoomsToOpenDoors); int doneRooms = 0; int totalRooms = rooms.GetLength(0) * rooms.GetLength(1); int roomsToFill = totalRooms; if (fillPercent < 100) { roomsToFill = totalRooms * fillPercent / 100; } while (listOfAvaibleRoomsToOpenDoors.Count > 0) { if (listOfPopulatedRooms.Count >= roomsToFill) { break; } int randomRoom = random.Next(listOfAvaibleRoomsToOpenDoors.Count); Position randomPos = listOfAvaibleRoomsToOpenDoors[randomRoom]; List <Directions.Direction> dir = GetRoomDirectionsAvailableToGo(rooms, randomPos, false); if (dir.Count > 0) { Directions.Direction randomDir = dir[random.Next(dir.Count)]; OpenDoor(randomPos.X, randomPos.Y, randomDir); Position position = null; switch (randomDir) { case Directions.Direction.North: position = new Position(randomPos.X, randomPos.Y--); break; case Directions.Direction.South: position = new Position(randomPos.X, randomPos.Y++); break; case Directions.Direction.East: position = new Position(randomPos.X++, randomPos.Y); break; case Directions.Direction.West: position = new Position(randomPos.X--, randomPos.Y); break; } listOfAvaibleRoomsToOpenDoors.Add(position); listOfPopulatedRooms.Add(position); } else { listOfAvaibleRoomsToOpenDoors.RemoveAt(randomRoom); doneRooms++; } } }
public bool OpenDoor(int x, int y, Directions.Direction direction) { bool mazeEnds = false; string dir = ""; switch (direction) { case Directions.Direction.North: dir = "N"; break; case Directions.Direction.East: dir = "E"; break; case Directions.Direction.South: dir = "S"; break; case Directions.Direction.West: dir = "W"; break; } //string dir = direction.ToString().Substring(0, 1); rooms[x, y] = RoomDictionary.GetRoom(rooms[x, y].ToString() + dir); try { switch (direction) { case Directions.Direction.North: y = y - 1; if (y < 0) { mazeEnds = true; break; } if (rooms[x, y] == null) { rooms[x, y] = RoomDictionary.GetRoom(""); OpenDoor(x, y, Directions.Direction.South); } break; case Directions.Direction.South: y = y + 1; if (y >= rooms.GetLength(1)) { mazeEnds = true; break; } if (rooms[x, y] == null) { rooms[x, y] = RoomDictionary.GetRoom(""); OpenDoor(x, y, Directions.Direction.North); } break; case Directions.Direction.East: x = x + 1; if (x >= rooms.GetLength(0)) { mazeEnds = true; break; } if (rooms[x, y] == null) { rooms[x, y] = RoomDictionary.GetRoom(""); OpenDoor(x, y, Directions.Direction.West); } break; case Directions.Direction.West: x = x - 1; if (x < 0) { mazeEnds = true; break; } if (rooms[x, y] == null) { rooms[x, y] = RoomDictionary.GetRoom(""); OpenDoor(x, y, Directions.Direction.East); } break; } } //catch the exception that will occur when the maze ends (goes out of bounds) catch { mazeEnds = true; } return(mazeEnds); }
public Guard(Directions.Direction direction) { GuardDirections.Add(direction); }
public virtual void AttemptToFollow(Directions.Direction direction, IMobileObject performer, IMobileObject mob) { //do nothing unless overrode }
/// <summary> /// Get the octant to the direction of the current octant /// </summary> /// <param name="direction"></param> /// <returns>the octant to the direction, or null if it's out of the current bounds</returns> public Octant toThe(Directions.Direction direction) { if (direction.Equals(Directions.North)) { if (IsNorthern) { return(null); } else { return(Get(IsEastern, IsUpper, true)); } } if (direction.Equals(Directions.South)) { if (!IsNorthern) { return(null); } else { return(Get(IsEastern, IsUpper, false)); } } if (direction.Equals(Directions.East)) { if (IsEastern) { return(null); } else { return(Get(true, IsUpper, IsNorthern)); } } if (direction.Equals(Directions.West)) { if (!IsEastern) { return(null); } else { return(Get(false, IsUpper, IsNorthern)); } } if (direction.Equals(Directions.Above)) { if (IsUpper) { return(null); } else { return(Get(IsEastern, true, IsNorthern)); } } if (direction.Equals(Directions.Below)) { if (!IsUpper) { return(null); } else { return(Get(IsEastern, false, IsNorthern)); } } return(null); }
public void Open(Directions.Direction direction) { bool openClose = true; OpenClose(direction, openClose); }
public Walk(Directions.Direction direction) { this.direction = direction; }
internal void Close(Directions.Direction direction) { bool openClose = false; OpenClose(direction, openClose); }
/// <summary> /// Constructor for the MoveCommand class /// </summary> /// <param name="_actor">the actor to affect</param> /// <param name="_direction">the direction to move the actor</param> public MoveCommand(Actor _actor, Directions.Direction _direction) { actor = _actor; direction = _direction; }
public virtual void LeaveRoom(IMobileObject mob, Directions.Direction direction) { //do nothing unless overrode }
internal void Open(Directions.Direction direction) { bool openClose = true; OpenClose(direction, openClose); }