예제 #1
0
    // Moves the player.
    public void warp(string hexName)
    {
        int currentX, desiredX, currentY, desiredY;
        stringTileToIntCoords stringTileToIntCoords = GameObject.Find("GridMap").GetComponent <stringTileToIntCoords>();
        gridPlacement         gridPlacement         = GameObject.Find("GridMap").GetComponent <gridPlacement>();
        playerSelect          playerSelect          = gameCamera.GetComponent <playerSelect>();
        playerStatus          playerStatus          = GameObject.Find("GridMap").GetComponent <playerStatus>();

        if (moveButton.GetComponentInChildren <Text>().text == "Confirm Move")
        {
            // Find the desired and current x and y coords of the selecetd monkey.
            switch (selectedCharacter.name)
            {
            case "player1SlotA":
                currentX = stringTileToIntCoords.getXposition(gridPlacement.leftA);
                currentY = stringTileToIntCoords.getYposition(gridPlacement.leftA);
                break;

            case "player1SlotB":
                currentX = stringTileToIntCoords.getXposition(gridPlacement.leftB);
                currentY = stringTileToIntCoords.getYposition(gridPlacement.leftB);
                break;

            case "player1SlotC":
                currentX = stringTileToIntCoords.getXposition(gridPlacement.leftC);
                currentY = stringTileToIntCoords.getYposition(gridPlacement.leftC);
                break;

            case "player2SlotA":
                currentX = stringTileToIntCoords.getXposition(gridPlacement.rightA);
                currentY = stringTileToIntCoords.getYposition(gridPlacement.rightA);
                break;

            case "player2SlotB":
                currentX = stringTileToIntCoords.getXposition(gridPlacement.rightB);
                currentY = stringTileToIntCoords.getYposition(gridPlacement.rightB);
                break;

            case "player2SlotC":
                currentX = stringTileToIntCoords.getXposition(gridPlacement.rightC);
                currentY = stringTileToIntCoords.getYposition(gridPlacement.rightC);
                break;

            default:
                currentX = 0;
                currentY = 0;
                break;
            }
            desiredX = stringTileToIntCoords.getXposition(hexName);
            desiredY = stringTileToIntCoords.getYposition(hexName);

            // Determine if desired coords are within range.
            if (Math.Abs(desiredX - currentX) > 30 || Math.Abs(desiredY - currentY) > 30) // FIX RANGE TO 2
            {
                infoBar.GetComponentInChildren <Text>().text = "Out of range";
                return;
            }
            // Determine if the terrain is obstrcuted by nature.
            if (tiles[desiredX, desiredY] == (int)TerrainType.Impassable)
            {
                infoBar.GetComponentInChildren <Text>().text = "Terrain is impassable";
                return;
            }
            // Determine is another player is on that hex.
            if (gridPlacement.checkHexOccupied(hexName))
            {
                infoBar.GetComponentInChildren <Text>().text = "Tile is occupied";
                return;
            }

            // Move.
            selectedCharacter.transform.position         = gridObject.transform.Find(hexName).position;
            infoBar.GetComponentInChildren <Text>().text = "";

            // Update position.
            switch (selectedCharacter.name)
            {
            case "player1SlotA":
                gridPlacement.leftA      = hexName;
                playerStatus.leftA.moved = true;
                break;

            case "player1SlotB":
                gridPlacement.leftB      = hexName;
                playerStatus.leftB.moved = true;
                break;

            case "player1SlotC":
                gridPlacement.leftC      = hexName;
                playerStatus.leftC.moved = true;
                break;

            case "player2SlotA":
                gridPlacement.rightA      = hexName;
                playerStatus.rightA.moved = true;
                break;

            case "player2SlotB":
                gridPlacement.rightB      = hexName;
                playerStatus.rightB.moved = true;
                break;

            case "player2SlotC":
                gridPlacement.rightC      = hexName;
                playerStatus.rightC.moved = true;
                break;
            }
        }
    }
예제 #2
0
    // Should be executed when the player selects the Melee button.
    public void meleeAttack()
    {
        gridPlacement         gridPlacement = GameObject.Find("GridMap").GetComponent <gridPlacement>();
        gridScript            gridScript = GameObject.Find("GridMap").GetComponent <gridScript>();
        stringTileToIntCoords stringTileToIntCoords = GameObject.Find("GridMap").GetComponent <stringTileToIntCoords>();
        playerSelect          playerSelect = GameObject.Find("GameCamera").GetComponent <playerSelect>();
        playerStatus          playerStatus = GameObject.Find("GridMap").GetComponent <playerStatus>();
        string        currentPosition, enemyApos, enemyBpos, enemyCpos;
        int           currentX, currentY;
        List <string> surroundingTiles = new List <string>();
        // bool AisOK = false, BisOK = false, CisOK = false;
        GameObject meleeButton = GameObject.Find("MeleeButton"), infoBar = GameObject.Find("InfoBar"), chosenEnemy;
        GameObject gridObject = GameObject.Find("GridMap");


        // Clicked Melee button when text is Melee
        if (meleeButton.GetComponentInChildren <Text>().text == "Melee")
        {
            meleeButton.GetComponentInChildren <Text>().text = "Confirm Melee";


            // Check to see if another monkey of the oposing team is next to your currently selected character.

            // Find the current position of currently selected monkey.
            switch (playerSelect.currentCharacter)
            {
            case "A":
                currentPosition = gridPlacement.leftA;
                break;

            case "B":
                currentPosition = gridPlacement.leftB;
                break;

            case "C":
                currentPosition = gridPlacement.leftC;
                break;

            case "A2":
                currentPosition = gridPlacement.rightA;
                break;

            case "B2":
                currentPosition = gridPlacement.rightB;
                break;

            case "C2":
                currentPosition = gridPlacement.rightC;
                break;

            default:
                currentPosition = "Tile_0_0";
                break;
            }

            currentX = stringTileToIntCoords.getXposition(currentPosition);
            currentY = stringTileToIntCoords.getYposition(currentPosition);

            Debug.Log("currentPosInMelee = " + currentX + ", " + currentY);

            // Find positions of enemies.
            if (playerStatus.turn == 0)
            {
                enemyApos = gridPlacement.rightA;
                enemyBpos = gridPlacement.rightB;
                enemyCpos = gridPlacement.rightC;
            }
            else
            {
                enemyApos = gridPlacement.leftA;
                enemyBpos = gridPlacement.leftB;
                enemyCpos = gridPlacement.leftB;
            }

            // Compile list of surroindg tiles.
            if (currentY % 2 == 0)// even hex row
            {
                surroundingTiles.Add("Tile_" + currentX + "_" + (currentY + 1));
                surroundingTiles.Add("Tile_" + (currentX - 1) + "_" + (currentY + 1));
                surroundingTiles.Add("Tile_" + (currentX - 1) + "_" + currentY);
                surroundingTiles.Add("Tile_" + (currentX - 1) + "_" + (currentY - 1));
                surroundingTiles.Add("Tile_" + currentX + "_" + (currentY - 1));
                surroundingTiles.Add("Tile_" + (currentX + 1) + "_" + currentY);
            }
            else
            {// odd hex row
                surroundingTiles.Add("Tile_" + (currentX + 1) + "_" + (currentY + 1));
                surroundingTiles.Add("Tile_" + currentX + "_" + (currentY + 1));
                surroundingTiles.Add("Tile_" + (currentX - 1) + "_" + currentY);
                surroundingTiles.Add("Tile_" + currentX + "_" + (currentY - 1));
                surroundingTiles.Add("Tile_" + (currentX + 1) + "_" + (currentY - 1));
                surroundingTiles.Add("Tile_" + (currentX + 1) + "_" + currentY);
            }

            // Loop thru surrounding tiles to see if any ememyPositions conflict, if so mark that.
            for (int i = 0; i < 6; i++)
            {
                if (enemyApos == surroundingTiles[i])
                {
                    playerStatus.AisOK = true;
                    Debug.Log("AisOK");
                }
                if (enemyBpos == surroundingTiles[i])
                {
                    playerStatus.BisOK = true;
                    Debug.Log("BisOK");
                }
                if (enemyCpos == surroundingTiles[i])
                {
                    playerStatus.CisOK = true;
                    Debug.Log("CisOK");
                }
            }
        }

        if (meleeButton.GetComponentInChildren <Text>().text == "Confirm Melee")
        {
            if (playerStatus.turn == 1)
            {
                switch (playerSelect.meleeingCharacter)
                {
                case "A":

                    if (playerStatus.AisOK)
                    {
                        chooseA = true;
                        chooseB = false;
                        chooseC = false;
                    }
                    break;

                case "B":

                    if (playerStatus.BisOK)
                    {
                        chooseA = false;
                        chooseB = true;
                        chooseC = false;
                    }
                    break;

                case "C":

                    if (playerStatus.CisOK)
                    {
                        chooseA = false;
                        chooseB = false;
                        chooseC = true;
                    }
                    break;

                default:
                    return;
                }
            }
            else
            {
                switch (playerSelect.meleeingCharacter)
                {
                case "A2":

                    if (playerStatus.AisOK)
                    {
                        chooseA = true;
                        chooseB = false;
                        chooseC = false;
                    }
                    break;

                case "B2":
                    if (playerStatus.BisOK)
                    {
                        chooseA = false;
                        chooseB = true;
                        chooseC = false;
                    }
                    break;

                case "C2":
                    if (playerStatus.CisOK)
                    {
                        chooseA = false;
                        chooseB = false;
                        chooseC = true;
                    }
                    break;

                default:
                    return;
                }
            }

            // Make call to doMelee function.
            if (chooseA)
            {
                doMelee("A");
            }
            if (chooseB)
            {
                doMelee("B");
            }
            if (chooseC)
            {
                doMelee("C");
            }

            chooseA            = false;
            chooseB            = false;
            chooseC            = false;
            playerStatus.AisOK = false;
            playerStatus.BisOK = false;
            playerStatus.CisOK = false;
        }
    }