// EngageCombat function deals with the combat within the game. public void EngageCombat(GameObject gameObject, object[] tiles, GameObject prevPiece) { colourManager.CompleteAction(prevPiece); gameObject.GetComponent <Player_Piece_Properties>().HP -= prevPiece.GetComponent <Player_Piece_Properties>().attackDamage; healthBar.fillAmount = gameObject.GetComponent <Player_Piece_Properties>().HP / gameObject.GetComponent <Player_Piece_Properties>().InitialHP; if (gameObject.GetComponent <Player_Piece_Properties>().HP > 0) { movementManager.ClearHighlights(tiles); return; } else { // If the unit taken out was a Chief, end the game, otherwise destroy the object. if (gameObject.GetComponent <Properties>().description == "Player_Piece_Chief") { gameManager.EndGame(gameObject); } movementManager.ManageMovement(gameObject, tiles, prevPiece); unitManager.ChangeTraitorSide(gameObject, prevPiece); Destroy(gameObject); object[] pieces = GameObject.FindGameObjectsWithTag("Player_Piece"); foreach (GameObject traitorPiece in pieces) { if (traitorPiece.GetComponent <Properties>().description == "Player_Piece_Traitor") { colourManager.CompleteAction(traitorPiece); } } return; } }
// This function is called whenever the user clicks on the scene. The function uses Case-switch statements to determine what type of object was clicked. private void OnMouseUp() { object[] tiles = GameObject.FindGameObjectsWithTag("Tile"); // The Case-switch statement used in order to determine what type of gameobject was clicked. Uses the description property in order to determine the type of gameobject. switch (gameObject.GetComponent <Properties>().description) { case "Player_Piece_Chief": case "Player_Piece_Hunter": case "Player_Piece_Archer": case "Player_Piece_Dragon": case "Player_Piece_Traitor": movementManager.CheckTileColour(gameObject, tiles, prevPiece); // Checks to see if the piece has already been activated. If so, nothing happens, otherwise the game will highlight the available moves with said piece. if (gameObject.GetComponent <Player_Piece_Properties>().activated == true) { return; } if (gameObject == prevPiece) { foreach (GameObject tile in tiles) { if (tile.GetComponent <Renderer>().material.color == colourManager.babyBlue || tile.GetComponent <Renderer>().material.color == colourManager.turqoise || tile.GetComponent <Renderer>().material.color == Color.yellow) { colourManager.CompleteAction(gameObject); movementManager.ClearHighlights(tiles); return; } } if (gameObject.GetComponent <Properties>().description == "Player_Piece_Traitor") { colourManager.CompleteAction(gameObject); movementManager.ClearHighlights(tiles); } movementManager.ClearHighlights(tiles); prevPiece = null; } else { foreach (GameObject tile in tiles) { if (tile.GetComponent <Renderer>().material.color == colourManager.babyBlue || tile.GetComponent <Renderer>().material.color == Color.green) { return; } } movementManager.HighlightMovement(gameObject.GetComponent <Properties>().CurrentTile, gameObject.GetComponent <Player_Piece_Properties>().movementSpeed, gameObject); prevPiece = gameObject; } break; case "Traitor": // While the traitor piece is inactive, do not have any interactions with it. break; // If a tile is clicked and the current available moves are highlighted, then the piece GameObject will do a certain action depending on the colour of the highlight. case "Tile": object[] pieces = GameObject.FindGameObjectsWithTag("Player_Piece"); if (gameObject.GetComponent <Renderer>().material.color == Color.yellow) { unitManager.CreateUnit(gameObject, unitPiece); movementManager.ClearHighlights(tiles); unitPiece = null; } else if (gameObject.GetComponent <Renderer>().material.color == colourManager.turqoise) { movementManager.ClearHighlights(tiles); colourManager.CompleteAction(prevPiece); } else if (gameObject.GetComponent <Renderer>().material.color == Color.green) { movementManager.ManageMovement(gameObject, tiles, prevPiece); movementManager.HighlightAttackRange(gameObject.GetComponent <Properties>().CurrentTile, prevPiece.GetComponent <Player_Piece_Properties>().attackRange, pieces, prevPiece); } else if (gameObject.GetComponent <Renderer>().material.color == colourManager.babyBlue) { movementManager.ManageMovement(gameObject, tiles, repositionPiece); colourManager.CompleteAction(prevPiece); repositionPiece = null; } break; default: Debug.Log("ERROR"); break; } }