/// <summary> /// Spawns a unit. /// </summary> /// <param name="unitIndex">Which type of unit, indexed from unit Prefabs</param> /// <param name="pos">The spawn position</param> /// <param name="friendly">Is the unit friendly</param> private void SpawnUnit(int unitIndex, Vector2Int pos, bool friendly) { SpaceManager space = gameBoard[pos.x, pos.y]; GamePiece clone = Instantiate(unitPrefabs[unitIndex], unitParent).GetComponent <GamePiece>(); space.OccupiedPiece = clone; allUnits.Add(clone); clone.friendly = friendly; if (clone.friendly) { clone.GetComponent <Image>().color = Color.blue; } }
/// <summary> /// Ends the game. /// </summary> /// <param name="victory"> True if local player won. </param> private void EndGame(bool victory) { gameOver = true; SpaceManager.DisableSelection(); menuButton.SetActive(false); returnToMainButton.SetActive(true); suggestMoveButton.gameObject.SetActive(false); if (victory) { turnDisplayerText.text = "Congratualations, you've won!"; } else { turnDisplayerText.text = "You lost. Better luck next time..."; } }
/// <summary> /// Suggests a move for the player. /// </summary> public void ShowSuggestedMove() { if (!MyTurn || gameOver) { return; } if (suggestedMovesHighlighted) { SpaceManager.DisableSelection(); return; } SpaceManager.DisableSelection(); suggestedMovesHighlighted = true; SpaceManager unitSpace = gameBoard[suggestedMoves[0].x, suggestedMoves[0].y]; SpaceManager moveSpace = gameBoard[suggestedMoves[1].x, suggestedMoves[1].y]; SpaceManager.selectedSpace = unitSpace; unitSpace.Highlighted = true; moveSpace.Highlighted = true; }
/// <summary> /// Generates the 8x8-Board. /// </summary> private void CreateBoard() { bool gray = false; for (int i = 0; i < 8; i++) { for (int foo = 0; foo < 8; foo++) { SpaceManager clone = Instantiate(boardPrefab, boardParent).GetComponent <SpaceManager>(); clone.position = new Vector2Int(i, foo); gameBoard[i, foo] = clone; if (gray) { clone.GetComponent <Image>().color = Color.gray; } clone.gameObject.name = $"Boardspace [{i}, {foo}]"; gray = !gray; } gray = !gray; } LayoutRebuilder.ForceRebuildLayoutImmediate(boardParent); }