public TileLogic GetTile(int tile) { TileLogic t = null; tiles.TryGetValue(tile, out t); return(t); }
void CheckAnswer(string[] userInput, bool fromLocalUser) { string userAnswer = GetUserAnswer(); if (userAnswer == currentTile.GetCurrentAnswer(currentDirectionIsAcross) && !currentTile.DidSolveCurrentAnswer(currentDirectionIsAcross)) { Debug.Log("send the correct answer to the other players"); //Debug.Log("the user has input the correct answer"); //put the correct answer in the user grid and select the next tile UpdateUserGrid(); int offset = 1; if (!currentDirectionIsAcross) { offset = (int)Mathf.Sqrt(tiles.Length); } string[] tempFriendlyGrid = CopyGrid(localPlayerGrid); for (int j = 0; j < currentUserInput.Length; j++) { int index = currentTile.index + j * offset; if (userGrid[index] == "") { tempFriendlyGrid[index] = currentUserInput[j]; } } networkingLogic.UpdateBoard(tempFriendlyGrid, enemyPlayerGrid, neutralGrid); TileLogic nextTile = currentTile; for (int i = 0; i < tiles.Length; i++) { TileLogic tl = tiles[(currentTile.index + i + 1) % tiles.Length]; if (tl != null) { //if the tile has as grid number and can be selected if (tl.clueNumber > 0 && (!tl.didSolveAcross || !tl.didSolveDown)) { nextTile = tl; break; } } } DidSelectTile(nextTile); } else { if (!canInteract) { Debug.Log("dont do the animation or set the delay"); } else { StartCoroutine(ReselectTileWithDelay(currentUserInput, fromLocalUser)); } //ShowWordSelected(currentTile, currentDirectionIsAcross); // reselect the current tile to show the user that the answer is wrong } }
//Create a tile from the prefab and set the size and properties TileLogic CreateTile(float tileScale, int row, int col, float tileSize) { GameObject tile = Instantiate(tilePrefab, gridParent.transform, false); TileLogic tileLogic = tile.GetComponent <TileLogic>(); if (tileLogic == null) { return(null); } tileLogic.ScaleTile(tileScale, tileSize, true); float a = row - (int)(crossword.size.rows / 2) + ((crossword.size.rows % 2 + 1) % 2) * .5f; float b = col - (int)(crossword.size.cols / 2) + ((crossword.size.cols % 2 + 1) % 2) * .5f; tile.transform.localPosition = new Vector2(b * tileSize, -(a * tileSize)); int index = IndexForRowAndCol(row, col); string _downAnswer = GetClueOrAnswer(false, false, index); string _downClue = GetClueOrAnswer(true, false, index); string _acrossAnswer = GetClueOrAnswer(false, true, index); string _acrossClue = GetClueOrAnswer(true, true, index); tileLogic.SetupTile(crossword.grid[index], crossword.gridnums[index], _acrossClue, _acrossAnswer, _downClue, _downAnswer, IndexForRowAndCol(row, col)); return(tileLogic); }
//Loop through the crossword data and create the necessary tiles void CreateGrid(int[] scoreMults) { float size = GetTileSize(); float tileScale = size / tilePrefab.GetComponent <RectTransform>().rect.width; TileLogic[] tiles = new TileLogic[crossword.size.rows * crossword.size.cols]; int index = 0; int[] lastColIndices = new int[crossword.size.cols]; for (int k = 0; k < lastColIndices.Length; k++) { lastColIndices[k] = -1; } for (int row = 0; row < crossword.size.rows; row++) { int lastNumberedAcrossClueIndex = -1; for (int col = 0; col < crossword.size.cols; col++) { index = IndexForRowAndCol(row, col); bool isBlank = IsGridSpotBlank(row, col); if (isBlank) { lastNumberedAcrossClueIndex = -1; lastColIndices[col] = -1; tiles[index] = null; continue; } tiles[index] = CreateTile(tileScale, row, col, size); TileLogic tileLogic = tiles[index]; if (index < scoreMults.Length) { tileLogic.SetScoreMult(scoreMults[index]); // set the randomly generated score multiplier for the tile } if (tileLogic.acrossAnswer != null) // if the clue has an across answer, set it as the most recent { lastNumberedAcrossClueIndex = index; } else if (lastNumberedAcrossClueIndex > -1)// if the clue does not have an across answer, set it's parent across answer to be the most recent across { tileLogic.parentAcrossIndex = lastNumberedAcrossClueIndex; } //now do the same for the down answers if (tileLogic.downAnswer != null) { lastColIndices[col] = index; } else if (lastColIndices[col] > -1) { tileLogic.parentDownIndex = lastColIndices[col]; } } } GameManager.instance.SetTileArray(tiles); // store the tile array in the game manager }
void ApplyResourceEffect(NaturalResource resource, int x, int y) { for (int xx = -resource.rangeAction; xx < resource.rangeAction; xx++) { for (int yy = -resource.rangeAction; yy < resource.rangeAction; yy++) { bool xValid = x + xx >= 0 && x + xx < 15; bool yValid = y + yy >= 0 && y + yy < 15; bool inRange = Mathf.Abs(xx) + Mathf.Abs(yy) <= resource.rangeAction; if (xValid && yValid && inRange && (xx != 0 || yy != 0)) { TileLogic currTile = tiles[x + xx, y + yy].GetComponent <TileLogic>(); currTile.luminosity += resource.luminosity; currTile.humidity += resource.humidity; currTile.nutrients += resource.nutrients; } } } for (int xx = -resource.rangeHealing; xx < resource.rangeHealing; xx++) { for (int yy = -resource.rangeHealing; yy < resource.rangeHealing; yy++) { bool xValid = x + xx >= 0 && x + xx < 15; bool yValid = y + yy >= 0 && y + yy < 15; bool inRange = Mathf.Abs(xx) + Mathf.Abs(yy) < resource.rangeHealing; if (xValid && yValid && inRange) { TileLogic currTile = tiles[x + xx, y + yy].GetComponent <TileLogic>(); currTile.recovered = true; } } } }
public void MergeHeads(TileLogic tile) { pathTiles.Add(tile); tile.IsChecked = true; coordinates = tile; ROTATION rot = CountRotationHead(); int mat = ChooseMaterial(); //head coordinates.gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); //rest if (pathTiles.Count >= 2) { pathTiles[pathTiles.Count - 2].GetComponent <SpriteRenderer>().sprite = box.sprites[mat]; if (mat == 2) { rot = CountRotationSecond(); } pathTiles[pathTiles.Count - 2].gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); } GameManager.Instance.CheckIfAllClicked(); pathTiles[0].GetComponent <SpriteRenderer>().sprite = box.sprites[0]; transform.position = pathTiles[0].gameObject.transform.position; coordinates = pathTiles[0]; pathTiles.RemoveAt(pathTiles.Count - 1); }
//Loop through the crossword data and create the necessary tiles void CreateGrid(int[] scoreMults) { float size = GetTileSize(); float tileScale = size / tilePrefab.GetComponent <RectTransform>().rect.width; TileLogic[] tiles = new TileLogic[crossword.size.rows * crossword.size.cols]; int index = 0; for (int row = 0; row < crossword.size.rows; row++) { for (int col = 0; col < crossword.size.cols; col++) { index = IndexForRowAndCol(row, col); bool isBlank = IsGridSpotBlank(row, col); if (isBlank) { tiles[index] = null; continue; } tiles[index] = CreateTile(tileScale, row, col, size, scoreMults); } } GameManager.instance.SetTileArray(tiles); // store the tile array in the game manager }
void PushDown() { int levelsCleared = 0; for (int i = 0; i < ClearingLevels.Length; i++) { if (ClearingLevels[i]) { for (int y = i - levelsCleared; y < GridY; y++) { for (int x = 0; x < GridX; x++) { for (int z = 0; z < GridZ; z++) { if (y < GridY - 1) { GameState[x, y, z] = GameState[x, y + 1, z]; TileLogic currentTileController = TileLiterals[x, y, z].GetComponent(typeof(TileLogic)) as TileLogic; TileLogic previousTileController = TileLiterals[x, y + 1, z].GetComponent(typeof(TileLogic)) as TileLogic; currentTileController.SetColor(previousTileController.GetColor()); } else { GameState[x, y, z] = false; } } } } levelsCleared += 1; Score += 1; ClearingLevels[i] = false; } } UpdateBoard(); }
public void OnCheckRayCast() { RaycastHit2D hit = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { GameObject hitGO = hit.transform.gameObject; if (hitGO.tag == "MapTile") { originTile = hitGO.GetComponent <TileLogic>(); if (originTile.resource == null) { if (resourceSelected != null) { originTile.OnApplyResource(resourceSelected); } } else { SetNaturalResource(originTile.resource); } } } else { SetNaturalResource(null); } }
IEnumerator Jump(TileLogic to) { int id1 = LeanTween.move(transform.gameObject, to.worldPos, MoveSpeed).id; LeanTween.moveLocalY(jumper.gameObject, jumpHeigth, MoveSpeed * 0.5f). setLoopPingPong(1).setEase(LeanTweenType.easeInOutQuad); float timeOrderUpdate = MoveSpeed; if (tileAtual.floor.tilemap.tileAnchor.y > to.floor.tilemap.tileAnchor.y) { timeOrderUpdate *= 0.85f; } else { timeOrderUpdate *= 0.2f; } yield return(new WaitForSeconds(timeOrderUpdate)); tileAtual = to; SR.sortingOrder = to.contentOrder; while (LeanTween.descr(id1) != null) { yield return(null); } to.content = this.gameObject; }
void DropNaturalResource() { RaycastHit2D hit = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { GameObject hitGO = hit.collider.gameObject; if (hitGO.tag == "MapTile") { hitGO.GetComponent <TileLogic>().OnApplyResource(resourceSelected); if (originTile != null) { originTile.OnRemoveResource(resourceSelected); } else { } } else if (hitGO.tag == "ShopTile") { if (originTile != null) { print("venta"); flagSelected = false; originTile.OnRemoveResource(resourceSelected); } } } resourceSelected = null; originTile = null; }
void DragNaturalResource() { RaycastHit2D hit = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { GameObject hitGO = hit.transform.gameObject; if (hitGO.tag == "ShopTile") { originTile = null; resourceSelected = hitGO.GetComponent <NaturalResource>(); print("Compra"); } else if (hitGO.tag == "MapTile") { originTile = hitGO.GetComponent <TileLogic>(); resourceSelected = originTile.resource; originTile.resource = resourceSelected; print("YaY"); } } else { print("Nay!"); } }
public static TileLogic GetTile(Vector3Int pos) { TileLogic tile = null; instance.tiles.TryGetValue(pos, out tile); return(tile); }
void InNECheck(Floor floor, TileLogic t, Vector3Int NEPosition) { if (floor.tilemap.HasTile(NEPosition)) { t.contentOrder = floor.order; } }
//Create a tile from the prefab and set the size and properties TileLogic CreateTile(float tileScale, int row, int col, float tileSize, int[] scoreMults) { GameObject tile = Instantiate(tilePrefab, gridParent.transform, false); TileLogic tileLogic = tile.GetComponent <TileLogic>(); if (tileLogic == null) { return(null); } int index = IndexForRowAndCol(row, col); if (index < scoreMults.Length) { tileLogic.SetScoreMult(scoreMults[index]); // set the randomly generated score multiplier for the tile } tileLogic.ScaleTile(tileScale, tileSize, true); float a = row - (int)(crossword.size.rows / 2) + ((crossword.size.rows % 2 + 1) % 2) * .5f; //set the position of the tile in the grid based on the row and col float b = col - (int)(crossword.size.cols / 2) + ((crossword.size.cols % 2 + 1) % 2) * .5f; tile.transform.localPosition = new Vector2(b * tileSize, -(a * tileSize)); string downAnswer = GetClueOrAnswer(false, false, index); string downClue = GetClueOrAnswer(true, false, index); string acrossAnswer = GetClueOrAnswer(false, true, index); string acrossClue = GetClueOrAnswer(true, true, index); tileLogic.SetupTile(crossword.grid[index], crossword.gridnums[index], acrossClue, acrossAnswer, downClue, downAnswer, index); return(tileLogic); }
void ShowWordSelected(TileLogic tile, bool isAcross) { currentTile = tile; currentDirectionIsAcross = isAcross; //currentUserText = ""; //currentInputIndex = 0; if (isAcross) { //clueText.text = tile.acrossClue; SetClueText(tile.acrossClue); //currentUserInput = new string[tile.acrossAnswer.Length]; currentUserInput = BlankGrid(tile.acrossAnswer.Length); } else { SetClueText(tile.downClue); //clueText.text = tile.downClue; //currentUserInput = new string[tile.downAnswer.Length]; currentUserInput = BlankGrid(tile.downAnswer.Length); } //SelectButton(downButton, !isAcross); //SelectButton(acrossButton, isAcross); HighlightTiles(tile, isAcross); UpdateBoardTilesText(); }
public void SetTileOrder(TileLogic[] tiles) { tileFillOrder = new TileLogic[tiles.Length]; // copy the tile array to the new tile order for (int i = 0; i < tiles.Length; i++) { tileFillOrder[i] = tiles[i]; } //shuffle the order to create a random fill order for (int i = 0; i < tiles.Length; i++) { int randomSwapIndex = 0; if (HomeLogic.isUsingSkillz) { randomSwapIndex = SkillzCrossPlatform.Random.Range(0, tiles.Length); } else { randomSwapIndex = Random.Range(0, tiles.Length); } TileLogic tempTile = tileFillOrder[i]; tileFillOrder[i] = tileFillOrder[randomSwapIndex]; tileFillOrder[randomSwapIndex] = tempTile; } }
public bool OnApplyResource(int x, int y, NaturalResource _resource) { TileLogic tile = tiles[x, y].GetComponent <TileLogic>(); if (_resource.CheckTerrain(tile)) { ApplyResourceEffect(_resource, x, y); AkSoundEngine.PostEvent("pl_plant_add", gameObject); //if (_resource.typeShape == NaturalResource.shapeAction.sphere) //{ // var range = _resource.rangeAction; // // List<Vector2> tileAlreadyInflueced = new List<Vector2>(); // tileAlreadyInflueced.Add(new Vector2(x, y)); // // for (int i = 0; i < range; i++) // { // // } // //} return(true); } else { return(false); } }
public void Move(TileLogic tile) { pathTiles.Add(tile); tile.IsChecked = true; coordinates = tile; gameObject.transform.position = tile.transform.position; ROTATION rot = CountRotationHead(); int mat = ChooseMaterial(); //head coordinates.GetComponent <Renderer>().sharedMaterial = materials[1]; coordinates.gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); //rest if (pathTiles.Count >= 2) { pathTiles[pathTiles.Count - 2].GetComponent <Renderer>().sharedMaterial = materials[mat]; if (mat == 2) { rot = CountRotationSecond(); } pathTiles[pathTiles.Count - 2].gameObject.transform.rotation = Quaternion.Euler(RotationFromROTATION(rot)); } box.SubMoves(); GameManager.Instance.CheckIfAllClicked(); }
protected void MoveSelector(TileLogic t) { Selector.instance.tile = t; Selector.instance.spriteRenderer.sortingOrder = t.contentOrder; Selector.instance.transform.position = t.worldPos; machine.selectedTile = t; }
public void DidSelectTile(TileLogic tile) { if (canInteract) { DidSelectTileWithDirection(tile, true, false); autoSubmit.ResetSubmissionTimer(); } }
public Tile(TileState state, TileType type, TileProperty property, TileLogic logic, GridController grid) { this.state = state; this.type = type; this.property = property; this.logic = logic; this.grid = grid; }
void InitCoast(TileLogic logic, int x, int y) { int food = 10; int light = 8; int water = Mathf.Clamp(10 - x / 2, 0, 10); logic.OnInit(x, y, light, water, food); }
void InitRiver(TileLogic logic, int x, int y) { int food = 8; int light = 9; int water = Mathf.Clamp(10 - Mathf.Abs(x - y), 0, 10); logic.OnInit(x, y, light, water, food); }
public void OnInit() { render = GetComponent <SpriteRenderer>(); int auxIdx = Random.Range(9, 11); render.sprite = spriteTerrains[auxIdx];//Solo prueba data = GetComponent <TileLogic>(); render.material.color = Color.white; }
void CreateTile(Vector3Int pos, Floor floor) { Vector3 worldPos = grid.CellToWorld(pos); // Debug.Log(worldPos); worldPos.y += (floor.tilemap.tileAnchor.y / 2) - 0.5f; TileLogic tile = new TileLogic(pos, worldPos, floor); tiles.Add(pos, tile); }
protected void OnMoveTileSelector(object sender, object args) { Vector3Int input = (Vector3Int)args; TileLogic t = Board.GetTile(Selector.instance.position + input); if (t != null) { MoveSelector(t); } }
public Unit CreateUnit(Vector3Int pos, string name) { TileLogic t = Board.GetTile(pos); Unit unit = Instantiate(unitPrefab, t.worldPos, Quaternion.identity, holder.transform); unit.tile = t; unit.name = name; return(unit); }
private void Start() { int tileMask = (1 << LayerMask.NameToLayer("MapTiles")); RaycastHit2D hit = Physics2D.Raycast(transform.position + new Vector3(0, 0, -1), new Vector3(0, 0, 1), 10, tileMask); pathTiles.Add(hit.collider.gameObject.GetComponent <TileLogic>()); coordinates = pathTiles[0]; coordinates.IsChecked = true; coordinates.GetComponent <SpriteRenderer>().sprite = box.sprites[0]; coordinates.ColorTiler(box.color); }
void CheckNullPosition() { if (Selector.instance.tile == null) { TileLogic t = Board.GetTile(new Vector3Int(0, 0, 0)); Selector.instance.tile = t; Selector.instance.spriteRenderer.sortingOrder = t.contentOrder; Selector.instance.transform.position = t.worldPos; } }