public void Use(string itemName) { var found = _game.CurrentPlayer.Inventory.Find(i => i.Name.ToLower() == itemName); if (found != null) { Messages.Add(_game.CurrentRoom.Use(found)); if (found.Name == "Row Boat") { _game.CurrentRoom = _game.CurrentRoom.Exits["west"]; var key = "wooden paddle"; var paddle = _game.CurrentPlayer.Inventory.Find(i => i.Name.ToLower() == key); if (paddle == null) { _game.CurrentRoom = _game.CurrentRoom.Exits["west"]; Messages.Add(_game.CurrentRoom.Description); EndRoom end = _game.CurrentRoom as EndRoom; if (end != null) { Messages.Add(end.Narrative); } } else { Messages.Add(_game.CurrentRoom.Description); } } } // check if item is in room else { Messages.Add("You don't have that Item"); } }
//bool CheckRoomOverlap(Room room) //{ // Bounds bounds = room.RoomBounds; // bounds.Expand(-0.1f); // Collider[] colliders = Physics.OverlapBox(bounds.center, bounds.size / 2, room.transform.rotation, roomLayerMask); // if(colliders.Length > 0) // { // Ignore collisions with current room // foreach(Collider c in colliders) // { // if(c.transform.parent.gameObject.Equals(room.gameObject)) // { // continue; // } // else // { // Debug.LogError("Overlap detected"); // return true; // } // } // } //} void PlaceEndRoom() { PlaceEndRoomNew(); return; //Instantiate room endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.transform.parent = this.transform; for (int i = 0; i < endRoom.gameObject.transform.childCount; i++) { Track track = endRoom.gameObject.transform.GetChild(i).GetComponent <Track>(); if (prevTrack != null) { prevTrack.NextTrack = track; track.PrevTrack = prevTrack; } prevTrack = track; startRoom.gameObject.transform.GetChild(0).GetComponent <Track>().PrevTrack = track; } NewTestController.instance.Show_Button(); //Create doorway lists to loop over List <Doorway> allAvailableDoorways = new List <Doorway>(availableDoorways); Doorway doorway = endRoom.doorways[0]; bool roomPlaced = false; //Try all available doorways foreach (Doorway availableDoorway in allAvailableDoorways) { //Position room Room room = (Room)endRoom; PositionRoomAtDoorway(ref room, doorway, availableDoorway); //Check room overlaps // if (CheckRoomOverlap(endRoom)) //{ // continue; //} roomPlaced = true; //Remove occupied doorways doorway.gameObject.SetActive(false); availableDoorways.Remove(doorway); availableDoorway.gameObject.SetActive(false); availableDoorways.Remove(availableDoorway); //Exit loop if room has been placed break; } //Room couldn't be placed. Restart generator and try again if (!roomPlaced) { ResetLevelGenerator(); } }
public bool Go(string direction) { minutes++; if (minutes >= 10) { Utils.LossNoise(); Messages.Add("You took too long to get to work! Sorry, you're fired!"); return(false); } //if the current room has that direction on the exits dictionary if (_game.CurrentRoom.Exits.ContainsKey(direction)) { // set current room to the exit room _game.CurrentRoom = _game.CurrentRoom.Exits[direction]; // populate messages with room description Messages.Add($"You Travel {direction}, and discover: "); Messages.Add($"Minutes Passed: {minutes}"); Look(); EndRoom end = _game.CurrentRoom as EndRoom; if (end != null) { Utils.WinNoise(); Messages.Add(end.Narrative); return(false); } return(true); } //no exit in that direction Messages.Add("No Room in that direction"); Messages.Add($"Minutes Passed: {minutes}"); Look(); return(true); }
public bool Go(string direction) { //if the current room has that direction on the exits dictionary if (_game.CurrentRoom.Exits.ContainsKey(direction)) { // set current room to the exit room _game.CurrentRoom = _game.CurrentRoom.Exits[direction]; // populate messages with room description Messages.Add($"You Travel {direction}, and discover: "); Look(); EndRoom end = _game.CurrentRoom as EndRoom; if (end != null) { Messages.Add(end.Narrative); return(false); } return(true); } else if (_game.CurrentRoom.LockedExits.Count > 0) { foreach (var lockedRoom in _game.CurrentRoom.LockedExits.Values) { if (direction == lockedRoom.Key) { Messages.Add($"{lockedRoom.Value.LockedMessage}"); } } return(true); } //no exit in that direction Messages.Add("No Room in that direction"); Look(); return(true); }
public bool Go(string direction) { //if the current room has that direction on the exits dictionary if (_game.CurrentRoom.Exits.ContainsKey(direction)) { // set current room to the exit room _game.CurrentRoom = _game.CurrentRoom.Exits[direction]; // populate messages with room description Messages.Add(new Message($"You Travel {direction}, and discover: ", ConsoleColor.White)); Look(); EndRoom end = _game.CurrentRoom as EndRoom; if (end != null) { Messages.Add(new Message(end.Narrative, ConsoleColor.Red)); return(false); } return(true); } //no exit in that direction Messages.Add(new Message("No Room in that direction", ConsoleColor.Red)); Console.Clear(); Look(); return(true); }
void PlaceEndRoom() { // Instantiate Room endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.transform.parent = this.transform; // Create doorway lists to loop over List <Doorway> currentAvailableDoorways = new List <Doorway>(allAvailableDoorways); Doorway doorway = endRoom.doorways[0]; bool roomPlaced = false; // Try all available doorways foreach (Doorway availableDoorway in currentAvailableDoorways) { //if (availableDoorway.transform.GetComponentInParent<StartRoom>() == null) //{ // print("test"); //} Room room = (Room)endRoom; PositionRoomAtDoorway(ref room, doorway, availableDoorway); // Check room overlaps if (CheckRoomOverlap(endRoom)) { // If overlap detected - skip to next iteration of the loop continue; } // No overlap, set this to true and... roomPlaced = true; // Remove occupied doorways doorway.gameObject.SetActive(false); allAvailableDoorways.Remove(doorway); availableDoorway.gameObject.SetActive(false); allAvailableDoorways.Remove(availableDoorway); // Exit loop if room has been placed. if (roomPlaced) { break; } } // Room couldn't be placed. Restart. if (!roomPlaced) { ResetLevelGenerator(); } //DeleteOverlappingDoorways(); }
private void PlaceEndRoom() { endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.transform.SetParent(transform); List <Doorway> allAvailableDoorways = new List <Doorway>(availableDoorways); Doorway doorway = endRoom.doorways[0]; bool roomPlaced = false; foreach (var availableDoorway in allAvailableDoorways) { if (availableDoorway.gameObject.tag == "Room") { continue; } Room room = (Room)endRoom; PositionRoomAtDoorway(ref room, doorway, availableDoorway); float distance = Vector3.Distance(startRoom.gameObject.transform.position, endRoom.gameObject.transform.position); if (CheckRoomOverlap(endRoom)) { continue; } if (distance <= 30) { continue; } roomPlaced = true; doorway.gameObject.SetActive(false); availableDoorways.Remove(doorway); availableDoorway.gameObject.SetActive(false); availableDoorways.Remove(availableDoorway); break; } if (!roomPlaced) { ResetLevelGenerator(); } }
void PlaceEndRoom() { // Instantiate room endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.transform.parent = this.transform; // Create doorway lists to loop over List <Doorway> allAvailableDoorways = new List <Doorway>(availableDoorways); Doorway doorway = endRoom.doorways[0]; bool roomPlaced = false; // Try all available doorways foreach (Doorway availableDoorway in allAvailableDoorways) { // Position room Room room = (Room)endRoom; PositionRoomAtDoorway(ref room, doorway, availableDoorway); Debug.Log("[" + name + "] Checking overlap"); // Check room overlaps if (CheckRoomOverlap(endRoom)) { continue; } Debug.Log("[" + name + "] Room placed"); roomPlaced = true; // Remove occupied doorways doorway.gameObject.SetActive(false); availableDoorways.Remove(doorway); availableDoorway.gameObject.SetActive(false); availableDoorways.Remove(availableDoorway); // Exit loop if room has been placed break; } // Room couldn't be placed. Restart generator and try again if (!roomPlaced) { ResetLevelGenerator(); } }
/// <summary> /// This function instantiate end room /// </summary> private void PlaceEndRoom() { Debug.Log("Place end room"); // Instantiate end room _endRoom = Instantiate(endRoomPrefab, transform) as EndRoom; // Create doorway lists to loop over List <Doorway> allAvailableDoorways = new List <Doorway>(_availableDoorways); Doorway doorway = _endRoom.doorways[Random.Range(0, _endRoom.doorways.Length)]; bool roomPlaced = false; // Try all available doorways foreach (Doorway availableDoorway in allAvailableDoorways) { // Position room Room room = (Room)_endRoom; PositionRoomAtDoorway(ref room, doorway, availableDoorway); // Check room overlaps if (CheckRoomOverlap(_endRoom)) { continue; } roomPlaced = true; // Remove occupied doorways doorway.gameObject.SetActive(false); _availableDoorways.Remove(doorway); availableDoorway.gameObject.SetActive(false); _availableDoorways.Remove(availableDoorway); // Exit loop break; } // Room couldn't be placed, restart generator if (!roomPlaced) { ResetLevelGenerator(); } }
void PlaceEndRoom() { // Instantiate room endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.transform.parent = this.transform; // Create doorway lists to loop over List <Doorway> allAvailableDoorways = new List <Doorway> (availableDoorways); Doorway doorway = endRoom.doorways [0]; bool roomPlaced = false; // Try all available doorways foreach (Doorway availableDoorway in allAvailableDoorways) { // Position room Room room = (Room)endRoom; PositionRoomAtDoorway(ref room, doorway, availableDoorway); // Check if endRoom overlaps with any other room. If false returned it means no overlaps found if (!CheckRoomOverlap(endRoom)) { roomPlaced = true; } // Remove occupied doorways doorway.gameObject.SetActive(false); availableDoorways.Remove(doorway); availableDoorway.gameObject.SetActive(false); availableDoorways.Remove(availableDoorway); // Exit loop if room has been placed if (roomPlaced) { break; } } // Room couldn't be placed. Restart Generator if (!roomPlaced) { ResetLevelGenerator(); } }
void PlaceEndRoom() { //instatiate room endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.transform.parent = this.transform; //create dorway list to loop over List <Doorway> allAvailableDoorways = new List <Doorway>(availableDoorways); Doorway doorway = endRoom.doorways[0]; bool roomPlaced = false; //try all available doorways foreach (Doorway availableDoorway in allAvailableDoorways) { //position room Room room = (Room)endRoom; PositionRoomAtDoorway(ref room, doorway, availableDoorway); //check for overlap if (CheckRoomOverlap(endRoom)) { continue; } roomPlaced = true; //remove occupied doorways doorway.gameObject.SetActive(false); availableDoorways.Remove(doorway); availableDoorway.gameObject.SetActive(false); availableDoorways.Remove(availableDoorway); //exit the loop break; } //room couldnt be palced restart and try again if (!roomPlaced) { ResetLevelGenerator(); } }
public bool Go(string direction) { //if the current room has that direction on the exits dictionary if (_game.CurrentRoom.Exits.ContainsKey(direction)) { // set current room to the exit room _game.CurrentRoom = _game.CurrentRoom.Exits[direction]; // populate messages with room description Messages.Add($"You travel {direction}, and discover: "); Look(); EndRoom end = _game.CurrentRoom as EndRoom; if (end != null) { Messages.Add(end.Narrative); return(false); } return(true); } //no exit in that direction Messages.Add("No path in that direction"); Look(); return(true); }
private void PlaceEndRoomNew() { endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.transform.parent = this.transform; for (int i = 0; i < endRoom.gameObject.transform.childCount; i++) { Track track = endRoom.gameObject.transform.GetChild(i).GetComponent <Track>(); if (prevTrack != null) { prevTrack.NextTrack = track; track.PrevTrack = prevTrack; } prevTrack = track; startRoom.gameObject.transform.GetChild(0).GetComponent <Track>().PrevTrack = track; } Room prevRoom = null; if (placeRooms.Count == 0) { prevRoom = startRoom; } else { prevRoom = placeRooms[placeRooms.Count - 1]; } Doorway enddoorway_prevroom = prevRoom.doorways[prevRoom.doorways.Length - 1]; Quaternion rotation_end = enddoorway_prevroom.gameObject.transform.rotation; endRoom.transform.rotation = rotation_end; endRoom.transform.position = enddoorway_prevroom.transform.position - new Vector3(0, 0.45f, 0); endRoom.doorways[0].gameObject.SetActive(false); }
void Awake() { endRoom = this; }
public void Generate() { grid = new bool[width + 1, width + 1]; maze = new Tile[width + 1, width + 1]; List <pair> frontiers = new List <pair>(); //cells to visit //starting tile int pos = width / 2 + 1; grid[pos, pos] = true; //frontiers.Add(new pair(1, width - 3)); //frontiers.Add(new pair(3, width - 1)); frontiers.Add(new pair(pos - 2, pos)); frontiers.Add(new pair(pos + 2, pos)); frontiers.Add(new pair(pos, pos - 2)); frontiers.Add(new pair(pos, pos + 2)); while (frontiers.Count > 0) { int index = UnityEngine.Random.Range(0, frontiers.Count); //get random cell from list pair coords = frontiers[index]; List <pair> neighbors = getNeighbors(coords.a, coords.b); //get random neighbor int index2 = UnityEngine.Random.Range(0, neighbors.Count); //Debug.Log(index2); pair neighbor = neighbors[index2]; int dx = (neighbor.a - coords.a) / 2; int dy = (neighbor.b - coords.b) / 2; //Debug.Log("dx: " + dx); //Debug.Log("dy: " + dy); grid[coords.a, coords.b] = true; grid[coords.a + dx, coords.b + dy] = true; //passage between selected frontier cell and selected neighbor if (valid(coords.a + 2, coords.b)) //add chosen cell's frontier cells { if (!grid[coords.a + 2, coords.b]) { //Debug.Log(grid[coords.a + 2, coords.b]); pair p1 = new pair(coords.a + 2, coords.b); if (!frontiers.Contains(p1)) { frontiers.Add(new pair(coords.a + 2, coords.b)); } } } if (valid(coords.a, coords.b + 2)) { if (!grid[coords.a, coords.b + 2]) { // Debug.Log(grid[coords.a, coords.b + 2]); pair p2 = new pair(coords.a, coords.b + 2); if (!frontiers.Contains(p2)) { frontiers.Add(new pair(coords.a, coords.b + 2)); } } } if (valid(coords.a - 2, coords.b)) { if (!grid[coords.a - 2, coords.b]) { // Debug.Log(grid[coords.a - 2, coords.b]); pair p3 = new pair(coords.a - 2, coords.b); if (!frontiers.Contains(p3)) { frontiers.Add(new pair(coords.a - 2, coords.b)); } } } if (valid(coords.a, coords.b - 2)) { if (!grid[coords.a, coords.b - 2]) { // Debug.Log(grid[coords.a, coords.b - 2]); pair p4 = new pair(coords.a, coords.b - 2); if (!frontiers.Contains(p4)) { frontiers.Add(new pair(coords.a, coords.b - 2)); } } } frontiers.Remove(coords); //remove chosen cell from list of frontier cells } //positions of start and end rooms (along top and bottom rows) int start = 2 * UnityEngine.Random.Range(1, width / 2) - 1; int end = 2 * UnityEngine.Random.Range(1, width / 2) - 1; grid[0, start] = true; //passage from start room to maze grid[width, end] = true; //passage from maze to end room (use width not width-1 because grid is actually width+1 wide) startRoom = Instantiate(startRoomPrefab) as StartRoom; startRoom.name = "Start Room"; startRoom.transform.parent = transform; startRoom.transform.localPosition = new Vector3(0f, 0f, 0f); endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.name = "End Room"; endRoom.transform.parent = transform; endRoom.transform.localPosition = new Vector3(StartRoom.WIDTH / 2 + width + 2f + EndRoom.WIDTH / 2, 0, end + 1f - EndRoom.WIDTH / 2 - start + 1f); int catX = 2 * UnityEngine.Random.Range(1, width / 2 + 1) - 3; int catZ = 2 * UnityEngine.Random.Range(1, width / 2 + 1) - 3; cat = Instantiate(catPrefab) as Cat; cat.name = "Cat"; cat.transform.parent = transform; cat.transform.localPosition = new Vector3(catX + 1f + StartRoom.WIDTH / 2, 0f, catZ + 1f - start + 1f); for (int z = 0; z < width + 1; ++z) { for (int x = 0; x < width + 1; ++x) { if (grid[x, z]) //if a passage { Passage pass = Instantiate(passagePrefab) as Passage; maze[x, z] = pass; pass.name = "Tile " + x + ", " + z; pass.transform.parent = transform; pass.transform.localPosition = new Vector3(x + 1f + StartRoom.WIDTH / 2, 0f, z - start); //want tile at (1,1) to be at position x = 0 z = 0 so player starts in top left } else //else a wall { Wall wall = Instantiate(wallPrefab) as Wall; maze[x, z] = wall; wall.name = "Tile " + x + ", " + z; wall.transform.parent = transform; wall.transform.localPosition = new Vector3(x + 1f + StartRoom.WIDTH / 2, 0f, z - start); //want tile at (1,1) to be at position x = 0 z = 0 so player starts in top left } } } }
private void CreateMap() { MazeGenerator mazeGenerator = new MazeGenerator(); MazeCell[,] mazeCells = mazeGenerator.GenerateMaze(5, 5, RollDice(1000)); int mazeCellSizeX = mazeCells.GetLength(0); int mazeCellSizeY = mazeCells.GetLength(1); m_Map = new Room[mazeCellSizeX, mazeCellSizeY]; for (int x = 0; x < mazeCellSizeX; x++) { for (int y = 0; y < mazeCellSizeY; y++) { GameObject room = Instantiate(m_RoomPrefabs[RollDice(m_RoomPrefabs.Count)], new Vector3(x * ROOM_OFFSET, 0, y * ROOM_OFFSET), Quaternion.identity); m_Map[x, y] = room.GetComponent <Room>(); // Set Exits m_Map[x, y].HasExitTop = mazeCells[x, y].top; m_Map[x, y].HasExitDown = mazeCells[x, y].down; m_Map[x, y].HasExitLeft = mazeCells[x, y].left; m_Map[x, y].HasExitRight = mazeCells[x, y].right; // Set Enemy Spawner As Default m_Map[x, y].SetEnemySpawner(); } } // Overwrite PoIs for needed PoIs m_Map[2, 2].SetStartRoom(); int diceRollX; int diceRollY; bool PoIsSet = false; bool endRoomSet = false; bool treasureRoomSet = false; do { if (m_RepairSpotsToRepair < 4) { diceRollX = RollDice(5); diceRollY = RollDice(5); if (m_Map[diceRollX, diceRollY].m_PointOfInterestComponent is EnemySpawner) { m_Map[diceRollX, diceRollY].SetRepairSpot(); m_RepairSpotsToRepair++; } } else { if (!endRoomSet) { diceRollX = RollDice(5); diceRollY = RollDice(5); if (m_Map[diceRollX, diceRollY].m_PointOfInterestComponent is EnemySpawner) { m_Map[diceRollX, diceRollY].SetEndRoom(); m_EndRoom = m_Map[diceRollX, diceRollY].m_PointOfInterestComponent as EndRoom; endRoomSet = true; } } else { if (!treasureRoomSet) { diceRollX = RollDice(5); diceRollY = RollDice(5); if (m_Map[diceRollX, diceRollY].m_PointOfInterestComponent is EnemySpawner) { m_Map[diceRollX, diceRollY].SetTreasureChest(); treasureRoomSet = true; } } else { PoIsSet = true; } } } } while (!PoIsSet); m_Player.transform.position = m_Map[2, 2].m_DownSpawnPointPlayer.position + Vector3.up; m_CurrentRoomIndexX = 2; m_CurrentRoomIndexY = 2; }