Beispiel #1
0
    private void CreateWall(MuseumCell cell, MuseumCell otherCell, CellDirection direction)
    {
        bool hasPainting = Random.value < paintingDensity;

        MuseumWall wall = Instantiate(wallPrefab) as MuseumWall;

        wall.Initialize(cell, otherCell, direction);
        if (otherCell != null)
        {
            wall = Instantiate(wallPrefab) as MuseumWall;
            wall.Initialize(otherCell, cell, direction.GetOpposite());
        }

        if (hasPainting)
        {
            Painting painting = Instantiate(paintingPrefab) as Painting;
            painting.Initialize(cell, direction);

            if (paintings.Length > 0)
            {
                string paintingName = paintings[(int)Random.Range(0, paintings.Length)];
                painting.LoadTexture(paintingName);
            }
        }
    }
Beispiel #2
0
    private void CreatePassageInSameRoom(MuseumCell cell, MuseumCell otherCell, CellDirection direction)
    {
        MuseumRoom room = cell.room;

        bool isDisplayCase = Random.value < displayCaseProbability;

        if (isDisplayCase)
        {
            MuseumDisplayCase displayCase = Instantiate(displayCasePrefab) as MuseumDisplayCase;
            displayCase.Initialize(cell, otherCell, direction);
            displayCase = Instantiate(displayCasePrefab) as MuseumDisplayCase;
            displayCase.Initialize(otherCell, cell, direction.GetOpposite());

            if (paintings.Length > 0)
            {
                string paintingName = paintings[(int)Random.Range(0, paintings.Length)];
                displayCase.LoadTexture(paintingName);
            }
        }
        else
        {
            MuseumPassage passage = Instantiate(passagePrefab) as MuseumPassage;
            passage.Initialize(cell, otherCell, direction);
            passage = Instantiate(passagePrefab) as MuseumPassage;
            passage.Initialize(otherCell, cell, direction.GetOpposite());
        }
    }
    public IEnumerator GenerateBTA()
    {
        DateTime startTime = DateTime.Now;

        for (int x = 0; x < width; x++)
        {
            for (int z = 0; z < height; z++)
            {
                // print(String.Format("x: {0}, z: {1}", x, z));
                CellLocation current_location = new CellLocation(x, z);
                Cell         currentCell      = PlaceCell(current_location);

                if (x == 0 && z == 0)
                {
                    currentCell.Material = entryCellMaterial;
                    entryCell            = currentCell;
                }
                else if (x == height - 1 && z == width - 1)
                {
                    currentCell.Material = exitCellMaterial;
                    CellDirection exitCellDirection = GetDirectionThatLeadstoOutOfBound(currentCell);
                    currentCell.AddConnection(exitCellDirection);
                    exitCell = currentCell;
                }

                List <int> validDirections = new List <int>();
                if (x > 0)
                {
                    validDirections.Add(2);
                }
                if (z > 0)
                {
                    validDirections.Add(1);
                }

                if (validDirections.Count > 0)
                {
                    validDirections.Shuffle();
                    CellDirection selectedDirection = (CellDirection)validDirections[0];
                    CellLocation  neighbourLocation = currentCell.Location + selectedDirection.ToRelativeCellLocation();
                    // print(String.Format("nx: {0}, nz: {1}", neighbourLocation.x, neighbourLocation.z));
                    CellDirection fromDirection = selectedDirection.GetOpposite();
                    currentCell.AddConnection(selectedDirection);
                    cells[neighbourLocation.x, neighbourLocation.z].AddConnection(fromDirection);
                }

                currentLength++;
                cellDistances[currentCell.Location.x, currentCell.Location.z] = currentLength;
                activeCells.Add(currentCell);
                yield return(new WaitForSeconds(delay));
            }
        }

        CreateCellWalls();
        DateTime endTime   = DateTime.Now;
        String   totalTime = endTime.Subtract(startTime).ToString();

        print("Total time taken: " + totalTime);
        print("Generate complete");
    }
Beispiel #4
0
 /// <summary>
 /// This function does the actual pairing of two cells. This function is required separately for the wrapped coordinate system,
 /// since there the two coordinates and the direction don't have a direct connection.
 /// </summary>
 /// <param name="currentCoordinates">This cells coordinates.</param>
 /// <param name="neighborCoordinates">The neighboring cell's coordinates.</param>
 /// <param name="toNeighbor">The direction towards the neighboring cell.</param>
 void PairCells(Vector2 currentCoordinates, Vector2 neighborCoordinates, CellDirection toNeighbor)
 {
     //Debug.Log(currentCoordinates);
     //Debug.Log(neighborCoordinates);
     GetCell(currentCoordinates).AddNeighbor(toNeighbor, GetCell(neighborCoordinates));
     GetCell(neighborCoordinates).AddNeighbor(toNeighbor.Opposite(), GetCell(currentCoordinates));
 }
Beispiel #5
0
    public Cell MakeConnection(Cell currentCell)
    {
        List <int> randomizedCellDirections = CellDirections.GetRandomizedCellDirections; // e.g [2, 1, 0, 3]

        for (int i = 0; i < randomizedCellDirections.Count; i++)
        {
            // The random direction from the current cell
            CellDirection direction = (CellDirection)randomizedCellDirections[i];

            // The neighbor cell location from the direction
            CellLocation nextLocation = currentCell.Location + direction.ToRelativeCellLocation();

            if (CanPlaceCell(nextLocation))
            {
                CellDirection fromDirection = direction.GetOpposite();
                Cell          nextCell      = PlaceCell(nextLocation, fromDirection);
                currentCell.AddConnection(direction); // Direction that connects it to the newly generated cell
                currentCell.name += "_" + direction;

                return(nextCell);
            }
        }

        return(null);
    }
 public static Vector2 Offset(CellDirection direction)
 {
     if (direction == CellDirection.N)
     {
         return(new Vector2(0, 1));
     }
     else if (direction == CellDirection.NE)
     {
         return(new Vector2(1, 1));
     }
     else if (direction == CellDirection.E)
     {
         return(new Vector2(1, 0));
     }
     else if (direction == CellDirection.SE)
     {
         return(new Vector2(1, -1));
     }
     else if (direction == CellDirection.S)
     {
         return(new Vector2(0, -1));
     }
     else if (direction == CellDirection.SW)
     {
         return(new Vector2(-1, -1));
     }
     else if (direction == CellDirection.W)
     {
         return(new Vector2(-1, 0));
     }
     else
     {
         return(new Vector2(-1, 1));
     }
 }
Beispiel #7
0
        public override void Modify(CellDirection cellDir)
        {
            var sameDirOppLines = state.OppLines.Filter(cellDir.AnalyzedCell, cellDir.Direction).ToList();

            if (!sameDirOppLines.Any())
            {
                return;
            }
            if (sameDirOppLines.Count >= 2 && sameDirOppLines.All(l => l.IsCellMiddle(cellDir.Cell)))
            {
                SplitCase(cellDir, sameDirOppLines);
                return;
            }
            foreach (var sameDirOppLine in sameDirOppLines)
            {
                if (sameDirOppLine.IsCellMiddle(cellDir.Cell))
                {
                    SplitCase(cellDir, new List <Line> {
                        sameDirOppLine
                    });
                }
                else
                {
                    sameDirOppLine.CalcPropsAndEstimate(state.Board);
                }
            }
        }
Beispiel #8
0
    public Cell PlaceCell(CellLocation location, CellDirection fromDirection)
    {
        Cell cell = PlaceCell(location);

        cell.AddConnection(fromDirection);
        return(cell);
    }
Beispiel #9
0
        public override void Modify(CellDirection cellDir)
        {
            var sameDirLines   = state.MyLines.Filter(cellDir.AnalyzedCell, cellDir.Direction).ToList();
            var mirrorDirLines = state.MyLines.Filter(mirrorCellDir.AnalyzedCell, mirrorCellDir.Direction).ToList();

            var intersect = sameDirLines.Intersect(mirrorDirLines).ToList();

            foreach (var intersectedLine in intersect)
            {
                intersectedLine.AddMiddleCell(cellDir.Cell);
            }

            var sameDirLine   = sameDirLines.Except(intersect).FirstOrDefault();
            var mirrorDirLine = mirrorDirLines.Except(intersect).FirstOrDefault();

            var isStrangeLongBrokenThree = StrangeLongBrokenThree(cellDir);

            if (isStrangeLongBrokenThree)
            {
                AddMyLine(CreateMaxCellLine(cellDir.Swap()));
                RemoveOneCellLine(sameDirLine);
                RemoveOneCellLine(mirrorDirLine);
            }

            var shouldNotAddLine = intersect.Any() || isStrangeLongBrokenThree;

            ProcessSide(cellDir, sameDirLine, shouldNotAddLine);
            ProcessSide(mirrorCellDir, mirrorDirLine, shouldNotAddLine);
        }
Beispiel #10
0
        protected Line CreateMaxCellLine(CellDirection cellDir)
        {
            //create line with maximum possible number of cells. Distance <= 4 | X X*| X  X*| X X *| XX XX*|
            var cells = new List <Cell> {
                cellDir.AnalyzedCell
            };
            var line = new Line(cells, state.MyCellType);
            var dist = 1;

            for (int i = cellDir.Distance + 1; i <= 4; i++)
            {
                var cell = cellDir.Analyzed(i);
                if (cell.IsEmptyWithBoard(state.Board))
                {
                    dist++;
                }
                if (cell.IsType(state.Board, state.OpponentCellType))
                {
                    break;
                }
                if (cell.IsType(state.Board, state.MyCellType))
                {
                    var tmpCellDir = new CellDirection(cell, cellDir.MirrorDirection, dist);
                    line.AddOuterCell(tmpCellDir);
                    dist = 1;
                }
            }

            line.AddOuterCellAndEstimate(state.Board, cellDir);
            return(line);
        }
Beispiel #11
0
	private void CreatePassage (MapCell cell, MapCell otherCell, CellDirection direction) {
		if(cell == null) return;

		Passage passage = Instantiate(passagePrefab) as Passage;
		passage.Initialize(cell, otherCell, direction);
		passage = Instantiate(passagePrefab) as Passage;
		passage.Initialize(otherCell, cell, direction.GetOpposite());
	}
Beispiel #12
0
 public void Initialize(MuseumCell cell, CellDirection direction)
 {
     this.cell               = cell;
     this.direction          = direction;
     transform.parent        = cell.transform;
     transform.localPosition = Vector3.zero;
     transform.localRotation = direction.ToRotation();
 }
Beispiel #13
0
 public void AddNeighbor(CellDirection direction, Cell cell)
 {
     // If the cell is valid and not yet in the neighbor dictionary, then add it.
     if (cell != null && !neighbors.ContainsKey(direction))
     {
         neighbors.Add(direction, cell);
     }
 }
Beispiel #14
0
    private void SetExitCell(Cell cell)
    {
        cell.Material = exitCellMaterial;
        CellDirection exitCellDirection = GetDirectionThatLeadstoOutOfBound(cell);

        cell.AddConnection(exitCellDirection);
        exitCell = cell;
    }
Beispiel #15
0
 public void RemoveConnection(CellDirection direction)
 {
     if (connections[direction] != null)
     {
         Destroy(edges[direction].gameObject);
         connections[direction] = null;
     }
 }
Beispiel #16
0
	public void Initialize (MapCell cell, MapCell otherCell, CellDirection direction) {
		this.cell = cell;
		this.otherCell = otherCell;
		this.direction = direction;
		cell.SetEdge(direction, this);
		transform.parent = cell.transform;
		transform.localPosition = Vector3.zero;
		transform.localRotation = direction.ToRotation();
	}
Beispiel #17
0
        public void NotSetNextCellReturnsNullTest(CellDirection direction)
        {
            var baseCell = new GridCell('A');
            // no next cells set

            var result = baseCell.GetNextCell(direction);

            result.Should().BeNull();
        }
Beispiel #18
0
    public Transform CreateWall(CellDirection direction)
    {
        Transform wall = Instantiate(wallPrefab);

        wall.transform.parent = transform;
        wall.localPosition    = Vector3.zero;
        wall.localRotation    = direction.ToRotation();
        return(wall);
    }
        public void CanStringBeAssignedToGridTest(string populateText, int startRow, int startColumn,
                                                  string desiredString, CellDirection direction, bool expectedCanBeAssigned)
        {
            var grid      = new StringSearchGrid(populateText);
            var startCell = grid.GetCell(startRow, startColumn);

            var canBeAssignedResult = startCell.CanBeAssigned(desiredString, direction);

            canBeAssignedResult.Should().Be(expectedCanBeAssigned);
        }
Beispiel #20
0
            private static IEnumerable <int> findAffectedCells(int cell, CellDirection dir)
            {
                var x = cell % 9;
                var y = cell / 9;

                for (; inRange(x) && inRange(y); x += dx(dir), y += dy(dir))
                {
                    yield return(x + 9 * y);
                }
            }
Beispiel #21
0
 private void SplitCase(CellDirection cellDir, List <Line> sameDirOppLines)
 {
     skipDirections.Add(cellDir.MirrorDirection);
     foreach (var sameDirOppLine in sameDirOppLines)
     {
         state.OppLines.Remove(sameDirOppLine);
     }
     AddOpponentLine(GetMaxLine(cellDir.AnalyzedCell, cellDir.Direction));
     AddOpponentLine(GetMaxLine(cellDir.Cell + cellDir.MirrorDirection, cellDir.MirrorDirection));
 }
Beispiel #22
0
    public void AddConnection(CellDirection direction)
    {
        Transform connection = Instantiate(connectionPrefab);

        connection.transform.parent = transform;
        connection.localPosition    = Vector3.zero;
        connection.localRotation    = direction.ToRotation();
        connection.gameObject.SetActive(pathVisible);
        connections[direction] = connection;
    }
    bool RequestForMovement(CellDirection cellDirection)
    {
        var neighbor = currentCell.GetOrSetNeighbor(cellDirection);

        if (neighbor != null)
        {
            neighbor.IsClickable = true;
            neighbor.OnClicked.AddListener(MoveToCellManager);
        }
        return(neighbor != null);
    }
Beispiel #24
0
 public void SetNextCell(CellDirection direction, GridCell cell)
 {
     if (this.nextCells.ContainsKey(direction))
     {
         this.nextCells[direction] = cell;
     }
     else
     {
         this.nextCells.Add(direction, cell);
     }
 }
Beispiel #25
0
 private void ProcessSide(CellDirection cellDir, Line line, bool shouldNotAddLine)
 {
     if (CanAddCell(line, cellDir))
     {
         line.AddOuterCellAndEstimate(state.Board, cellDir);
     }
     else if (!shouldNotAddLine)
     {
         AddMyLine(CreateMaxCellLine(cellDir));
     }
 }
Beispiel #26
0
        public void SetGetNextCellTest(CellDirection direction)
        {
            var baseCell = new GridCell('A');
            var nextCell = new GridCell('B');

            baseCell.SetNextCell(direction, nextCell);

            var result = baseCell.GetNextCell(direction);

            result.Should().Be(nextCell);
            result.Value.Should().Be('B');
        }
Beispiel #27
0
 /// <summary>
 /// Get the oppposite of a given direction .
 /// </summary>
 /// <param name="direction">direction one wants the opposite of</param>
 /// <returns>the opposite direction</returns>
 public static CellDirection Opposite(this CellDirection direction)
 {
     // make sure to not overflow
     if ((int)direction < 4)
     {
         return(direction + 4);
     }
     else
     {
         return(direction - 4);
     }
 }
Beispiel #28
0
        public bool CanBeAssigned(string desiredString, CellDirection direction)
        {
            var cellSequence = this.GetSequence(direction, desiredString.Length).ToList();

            if (cellSequence.Count < desiredString.Length)
            {
                return(false);
            }

            bool assignable = desiredString.Select((c, i) => cellSequence[i].CanBeAssigned(c)).All(a => a);

            return(assignable);
        }
Beispiel #29
0
        private static IEnumerable <int> findAffectedCells(int cell, int gridWidth, int gridHeight, CellDirection direction)
        {
            var x = cell % 9;
            var y = cell / 9;

            while (x >= 0 && x < gridWidth && y >= 0 && y < gridHeight)
            {
                yield return(x + 9 * y);

                x += direction switch { CellDirection.Left => - 1, CellDirection.Right => 1, _ => 0 };
                y += direction switch { CellDirection.Up => - 1, CellDirection.Down => 1, _ => 0 };
            }
        }
Beispiel #30
0
        public override void Modify(CellDirection cellDir)
        {
            var sameDirLine = state.MyLines.FilterFirstOrDefault(cellDir.AnalyzedCell, cellDir.Direction);

            if (CanAddCell(sameDirLine, cellDir))
            {
                sameDirLine.AddOuterCellAndEstimate(state.Board, cellDir);
            }
            else
            {
                AddMyLine(CreateMaxCellLine(cellDir));
            }
        }
Beispiel #31
0
    /// <summary>
    /// This function will rotate a given direction in mathematical positive direction (Rechte-Hand Regel).
    /// </summary>
    /// <param name="direction">The initial direction.</param>
    /// <param name="angle">The angle of rotation in 45° steps.</param>
    /// <returns></returns>
    public static CellDirection Rotated(this CellDirection direction, float angle)
    {
        CellDirection newDirection = direction - (int)(angle / 45.0f);

        if ((int)newDirection < 0)
        {
            newDirection += 8;
        }
        else if ((int)newDirection > 7)
        {
            newDirection -= 8;
        }
        return(newDirection);
    }
Beispiel #32
0
    public CellManager GetOrSetNeighbor(CellDirection cellDirection)
    {
        var cellManager = GetNeighbor(cellDirection);

        if (cellManager == null)
        {
            cellManager = CellsManager.GetNeighbor(this, cellDirection);
            if (cellManager != null)
            {
                SetNeighbor(cellManager, cellDirection);
            }
        }
        return(cellManager);
    }
Beispiel #33
0
	private void CreateWall (MapCell cell, MapCell otherCell, CellDirection direction) {
		if(cell == null) return;
		//create 2 walls
//		cell.GetEdge(direction).dest();

		Wall wall = Instantiate(wallPrefab) as Wall;
		wall.Initialize(cell, otherCell, direction);
		wall.transform.localPosition +=
			new Vector3(0, 1, 0);

//		wall.gameObject.layer = LayerMask.NameToLayer ("Obstacles");

		if (otherCell != null) {
//			otherCell.GetEdge(direction.GetOpposite()).dest();
			wall = Instantiate(wallPrefab) as Wall;
			wall.Initialize(otherCell, cell, direction.GetOpposite());
			wall.transform.localPosition +=
				new Vector3(0, 1, 0);
		}
		
	}
Beispiel #34
0
	private void CreateDesk (MapCell cell, MapCell otherCell, CellDirection direction) {
		if(cell == null) return;
		Desk desk = Instantiate(deskPrefab) as Desk;
//		desk.Initialize(cell, otherCell, direction);
		desk.transform.localPosition =
			cell.transform.localPosition+ new Vector3(0, 1,0);
		cell.hasdesk = true;
		desk.transform.parent = cell.transform;

		if(!otherCell.hasdesk){
			Colleague colleague = Instantiate(matePrefab) as Colleague;
			colleague.transform.localRotation = direction.ToRotation();
			colleague.transform.localPosition = cell.transform.localPosition+direction.ToVector3();
			colleague.transform.parent = desk.transform;

		} 
	}
Beispiel #35
0
	private MapCell GetNeighbor(MapCell cell, CellDirection direction){
		MapCell neighbor = null;
		IntVector2 coordinates = cell.coordinates + direction.ToIntVector2();
		if(CoordMakeSense(coordinates)) neighbor = GetCell(coordinates);
		return neighbor;
	}
Beispiel #36
0
	public void SetEdge (CellDirection direction, CellEdge edge) {
		edges[(int)direction] = edge;
	}
Beispiel #37
0
	public CellEdge GetEdge (CellDirection direction) {
		return edges[(int)direction];
	}
Beispiel #38
0
	private void CreateEdge(MapCell cell, CellDirection direction, string wall, bool room){
		MapCell neighbor = GetNeighbor(cell, direction);
		if(wall == "1") CreateWall(cell, neighbor, direction);
		if(wall == "2") CreateDesk(cell, neighbor, direction);
		if(room){
			cell.transform.GetChild(0).GetComponent<Renderer>().material = roomfloormat;
		}
	}