public void CreateFromGrid_GeneratesTheCorrectGridSquareInfos() { //Arrange var grid = ArrangeGrid(); //Act IGridInfo gridInfo = _factory.CreateFromGrid(grid); //Assert Assert.That(gridInfo, Is.Not.Null, "No instance of a class that implements IGridInfo is returned."); for (var i = 0; i < gridInfo.Squares.Length; i++) { GridSquareInfo[] squareInfoRow = gridInfo.Squares[i]; for (var j = 0; j < squareInfoRow.Length; j++) { GridSquareInfo squareInfo = squareInfoRow[j]; IGridSquare matchingSquare = grid.Squares[i, j]; Assert.That(squareInfo.NumberOfBombs, Is.EqualTo(matchingSquare.NumberOfBombs), $"Number of bombs for square info at [{i}][{j}] is not correct."); Assert.That(squareInfo.Status, Is.EqualTo(matchingSquare.Status), $"Status for square info at [{i}][{j}] is not correct."); } } }
// Use this for initialization void Start() { List <Vector2> squaresToSpawn = new List <Vector2>(); squaresToSpawn.Add(Vector2.zero); List <Vector2> newSquaresToAdd = new List <Vector2>(); List <Vector2> alreadyHasSquare = new List <Vector2>(); for (int n = 0; n < chunkRadius; n++) { newSquaresToAdd.Clear(); foreach (Vector2 squarePosToSpawn in squaresToSpawn) { // Before we spawn a hex, check if there's one there already! //replace with a 2d array that indicates where there are already squares /*if (Physics.Raycast(new Ray(new Vector3(transform.position.x + squarePosToSpawn.x, transform.position.y + squarePosToSpawn.y, -10), Vector3.forward))) * { * continue; * }*/ if (alreadyHasSquare.Contains(squarePosToSpawn)) { continue; } GameObject squareObj = Instantiate(squarePrefab); squareObj.transform.parent = transform; squareObj.transform.localPosition = squarePosToSpawn; alreadyHasSquare.Add(new Vector2(squareObj.transform.position.x, squareObj.transform.position.y)); // Now let's add alls it's neighbors to the list of next ones to spawn. GridSquareInfo squareInfo = squareObj.GetComponent <GridSquareInfo>(); squareInfo.setChunkColor(chunkIndex); foreach (Vector2 neighborOffset in squareInfo.neighborOffsets) { Vector2 neighborPos = squarePosToSpawn + neighborOffset; if (!newSquaresToAdd.Contains(neighborPos)) { newSquaresToAdd.Add(neighborPos); } } } foreach (Vector2 newSquare in newSquaresToAdd) { if (!squaresToSpawn.Contains(newSquare)) { squaresToSpawn.Add(newSquare); } } } }
public void GridContentsChanged(GridSquareInfo info) { var sq = GridMap[info.x, info.y]; var img = sq.GetComponent<Image>(); var obj = info.Objects.OrderByDescending(x => x.MinimapPriority).FirstOrDefault(); if(obj != null) img.color = obj.MapColor; else if (info.GridSquareType == GridSquareType.OutOfBounds) img.color = new Color(0, 0, 0, 0); else img.color = new Vector4(0.1f, 0.1f, 0.1f, 1); //foreach(var o in info.Objects) //{ // if (o == null) // continue; //if(o.tag == "Wall") //{ // img.color = new Vector4(0.33f,0.33f,0.33f,0.5f); // break; //} //else if(o.tag == "Player") //{ // img.color = Color.red; // break; //} //else if(o.GetComponent<PickupIcon>() != null) //{ // img.color = Color.yellow; //} //else //{ // img.color = new Vector4(0,0,0,0.5f); //} //} }