// Will take the bandanna from the chosenCharacter and give it to the attacking character.
    public void captureBandanna(GameObject attackedCharacter)
    {
        playerStatus playerStatus = GameObject.Find("GridMap").GetComponent <playerStatus>();
        playerSelect playerSelect = GameObject.Find("GameCamera").GetComponent <playerSelect>();
        GameObject   bandanna;

        string currentCharacter = playerSelect.currentCharacter;

        if (playerStatus.turn == 1)
        { // attacking left team
            bandanna = playerStatus.bandannaLeft;
            switch (attackedCharacter.name)
            {
            case "player1SlotA":
                playerStatus.leftA.hasBandana = false;
                giveBandannaToCurrent(bandanna);
                break;

            case "player1SlotB":
                playerStatus.leftB.hasBandana = false;
                giveBandannaToCurrent(bandanna);
                break;

            case "player1SlotC":
                playerStatus.leftC.hasBandana = false;
                giveBandannaToCurrent(bandanna);
                break;

            default:
                break;
            }
        }
        else
        {
            Debug.Log("42, attackedCharacter.name = " + attackedCharacter.name);
            bandanna = playerStatus.bandannaRight;
            switch (attackedCharacter.name)
            {
            case "player2SlotA":
                playerStatus.rightA.hasBandana = false;
                Debug.Log("48");
                giveBandannaToCurrent(bandanna);
                Debug.Log("50");
                break;

            case "player2SlotB":
                playerStatus.rightB.hasBandana = false;
                giveBandannaToCurrent(bandanna);
                break;

            case "player2SlotC":
                playerStatus.rightC.hasBandana = false;
                giveBandannaToCurrent(bandanna);
                break;

            default:
                break;
            }
        }
    }
    private void giveBandannaToCurrent(GameObject bandanna)
    {
        playerSelect playerSelect = GameObject.Find("GameCamera").GetComponent <playerSelect>();
        playerStatus playerStatus = GameObject.Find("GridMap").GetComponent <playerStatus>();
        GameObject   newParent;
        GameObject   gridObject = GameObject.Find("GridMap"), level0Map = GameObject.Find("Level0Map");
        GameObject   team1level0Map = GameObject.Find("Level0Map/Teams/player1Team");
        GameObject   team2level0Map = GameObject.Find("Level0Map/Teams/player2Team");

        switch (playerSelect.currentCharacter)
        {
        case "A":
            playerStatus.leftA.hasBandana = true;
            newParent = GameObject.Find("player1SlotA");
            playerStatus.bandannaRight.transform.SetParent(newParent.transform);
            // need to warp the bandnana as well in each case!!!!!!
            playerStatus.bandannaRight.transform.position = team1level0Map.transform.Find(newParent.name).position;
            break;

        case "B":
            playerStatus.leftB.hasBandana = true;
            newParent = GameObject.Find("player1SlotB");
            playerStatus.bandannaRight.transform.SetParent(newParent.transform);
            playerStatus.bandannaRight.transform.position = team1level0Map.transform.Find(newParent.name).position;
            break;

        case "C":
            playerStatus.leftC.hasBandana = true;
            newParent = GameObject.Find("player1SlotC");
            playerStatus.bandannaRight.transform.SetParent(newParent.transform);
            playerStatus.bandannaRight.transform.position = team1level0Map.transform.Find(newParent.name).position;
            break;

        case "A2":
            playerStatus.rightA.hasBandana = true;
            newParent = GameObject.Find("player2SlotA");
            playerStatus.bandannaRight.transform.SetParent(newParent.transform);
            playerStatus.bandannaRight.transform.position = team2level0Map.transform.Find(newParent.name).position;
            break;

        case "B2":
            playerStatus.rightB.hasBandana = true;
            newParent = GameObject.Find("player2SlotB");
            playerStatus.bandannaRight.transform.SetParent(newParent.transform);
            playerStatus.bandannaRight.transform.position = team2level0Map.transform.Find(newParent.name).position;
            break;

        case "C2":
            playerStatus.rightC.hasBandana = true;
            newParent = GameObject.Find("player2SlotC");
            playerStatus.bandannaRight.transform.SetParent(newParent.transform);
            playerStatus.bandannaRight.transform.position = team2level0Map.transform.Find(newParent.name).position;
            break;

        default:
            break;
        }
        return;
    }
    // This function is wrongly named, warp actually moves the player. This func would have moved the player but pathfinding was scrapped.
    public void MoveCurrentCharacter(int x, int y)
    {
        // Determine which character is currently selected.
        gridPlacement      gridPlacement      = GameObject.Find("GridMap").GetComponent <gridPlacement>();
        playerSelect       playerSelect       = gameCamera.GetComponent <playerSelect>();
        changeGridMaterial changeGridMaterial = GameObject.Find("GameManager").GetComponent <changeGridMaterial>();
        playerStatus       playerStatus       = GameObject.Find("GridMap").GetComponent <playerStatus>();

        gridObject = GameObject.Find("GridMap");

        if (playerStatus.turn == 0)
        {
            if (playerSelect.currentCharacter == "A")
            {
                selectedCharacter = GameObject.Find("player1SlotA");
            }
            else if (playerSelect.currentCharacter == "B")
            {
                selectedCharacter = GameObject.Find("player1SlotB");
            }
            else if (playerSelect.currentCharacter == "C")
            {
                selectedCharacter = GameObject.Find("player1SlotC");
            }
            else
            {
                selectedCharacter = null;
            }
        }
        else
        {
            if (playerSelect.currentCharacter == "A2")
            {
                selectedCharacter = GameObject.Find("player2SlotA");
            }
            else if (playerSelect.currentCharacter == "B2")
            {
                selectedCharacter = GameObject.Find("player2SlotB");
            }
            else if (playerSelect.currentCharacter == "C2")
            {
                selectedCharacter = GameObject.Find("player2SlotC");
            }
            else
            {
                selectedCharacter = null;
            }
        }
        // If in move mode, then move the player.
        if (moveButton.GetComponentInChildren <Text>().text == "Confirm Move")
        {
            // Highlight selected hex (where the user wants to move).
            if (choseATile == false)
            {
                changeGridMaterial.exemptHexName = "Tile_" + x + "_" + y + "";
                changeGridMaterial.changeHexRed(x, y);
                choseATile = true;
                oldX       = x;
                oldY       = y;
            }
            else
            {
                changeGridMaterial.changeHexBlue(oldX, oldY);
                changeGridMaterial.exemptHexName = "Tile_" + x + "_" + y + "";
                changeGridMaterial.changeHexRed(x, y);
                oldX = x;
                oldY = y;
            }



            /*
             *   // Dijkstra's Algorithm for pathfinding!!
             *       Dictionary<Node, float> dist = new Dictionary<Node, float>();
             *       Dictionary<Node, Node> prev = new Dictionary<Node, Node>();
             *
             *       List<Node> unvisited = new List<Node>();
             *
             *       Node source = graph[selectedCharacter.GetComponent<characterPosition>().hexTile_X, selectedCharacter.GetComponent<characterPosition>().hexTile_Y];
             *       Node target = graph[x,y];
             *
             *       dist[source] = 0;
             *       prev[source] = null;
             *
             *       foreach(Node vertex in graph)
             *       {
             *           if(vertex != source){
             *               dist[vertex] = Mathf.Infinity;
             *               prev[vertex] = null;
             *           }
             *           unvisited.Add(vertex);
             *       }
             *       while(unvisited.Count > 0){
             *           Node u = null;
             *           foreach (Node possibleU in unvisited)
             *           {
             *               if(u == null || dist[possibleU] < dist[u]){
             *                   u = possibleU;
             *               }
             *           }
             *
             *           if(u == target){
             *               break;
             *           }
             *
             *           unvisited.Remove(u);
             *
             *           foreach(Node vertex in u.neighbours){
             *              float alt = dist[u] + CostToEnterTile(vertex.x, vertex.y);
             *               if(alt < dist[vertex]){
             *                   dist[vertex] = alt;
             *                   prev[vertex]  = u;
             *               }
             *           }
             *       }
             *       // if here, shortest route, or no route.
             *       if(prev[target] == null){
             *           return;
             *       }
             *       List<Node> currentPath = new List<Node>();
             *       Node curr = target;
             *
             *       while(curr != null){
             *           currentPath.Add(curr);
             *           curr = prev[curr];
             *       }
             *
             *       currentPath.Reverse();
             *
             *       selectedCharacter.GetComponent<characterPosition>().currentPath = currentPath;
             */
        }
    }
    // 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;
            }
        }
    }
示例#5
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;
        }
    }
示例#6
0
    void doMelee(string chosenCharacter)
    {
        GameObject      meleeButton = GameObject.Find("MeleeButton"), infoBar = GameObject.Find("InfoBar"), chosenEnemy;
        GameObject      gridObject      = GameObject.Find("GridMap");
        playerSelect    playerSelect    = GameObject.Find("GameCamera").GetComponent <playerSelect>();
        playerStatus    playerStatus    = GameObject.Find("GridMap").GetComponent <playerStatus>();
        bandannaCapture bandannaCapture = GameObject.Find("GridMap").GetComponent <bandannaCapture>();

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

            if (playerStatus.turn == 1)// Right is attacking left. ChoosenCharacter = left's guy that is getting attacked.
            {
                if (chosenCharacter == "A")
                {
                    chosenEnemy = GameObject.Find("player1SlotA");
                    playerStatus.leftA.isCaptured = true;
                    if (playerStatus.leftA.hasBandana)
                    {
                        bandannaCapture.captureBandanna(chosenEnemy);
                    }
                    // Send to barrel.
                    infoBar.GetComponentInChildren <Text>().text = "Sent left's A player to the monkey barrel!";
                    chosenEnemy.transform.position = gridObject.transform.Find("Tile_27_7").position;
                }
                if (chosenCharacter == "B")
                {
                    chosenEnemy = GameObject.Find("player1SlotB");
                    playerStatus.leftB.isCaptured = true;
                    if (playerStatus.leftB.hasBandana)
                    {
                        bandannaCapture.captureBandanna(chosenEnemy);
                    }
                    // Send to barrel.
                    infoBar.GetComponentInChildren <Text>().text = "Sent left's B player to the monkey barrel!";
                    chosenEnemy.transform.position = gridObject.transform.Find("Tile_27_7").position;
                }
                if (chosenCharacter == "C")
                {
                    chosenEnemy = GameObject.Find("player1SlotC");
                    playerStatus.leftC.isCaptured = true;
                    if (playerStatus.leftC.hasBandana)
                    {
                        bandannaCapture.captureBandanna(chosenEnemy);
                    }
                    // Send to barrel.
                    infoBar.GetComponentInChildren <Text>().text = "Sent left's C player to the monkey barrel!";
                    chosenEnemy.transform.position = gridObject.transform.Find("Tile_27_7").position;
                }
            }
            else // left is attacking right.
            {
                if (chosenCharacter == "A")
                {
                    Debug.Log("meleeing rightA");
                    chosenEnemy = GameObject.Find("player2SlotA");
                    playerStatus.rightA.isCaptured = true;

                    if (playerStatus.rightA.hasBandana)
                    {
                        Debug.Log("hasB = true rightA");
                        bandannaCapture.captureBandanna(chosenEnemy);
                    }
                    // Send to barrel.
                    infoBar.GetComponentInChildren <Text>().text = "Sent rights's A player to the monkey barrel!";
                    chosenEnemy.transform.position = gridObject.transform.Find("Tile_2_7").position;
                }
                if (chosenCharacter == "B")
                {
                    chosenEnemy = GameObject.Find("player2SlotB");
                    playerStatus.rightB.isCaptured = true;
                    if (playerStatus.rightB.hasBandana)
                    {
                        bandannaCapture.captureBandanna(chosenEnemy);
                    }
                    // Send to barrel.
                    infoBar.GetComponentInChildren <Text>().text = "Sent rights's B player to the monkey barrel!";
                    chosenEnemy.transform.position = gridObject.transform.Find("Tile_2_7").position;
                }
                if (chosenCharacter == "C")
                {
                    chosenEnemy = GameObject.Find("player2SlotC");
                    playerStatus.rightC.isCaptured = true;
                    if (playerStatus.rightC.hasBandana)
                    {
                        bandannaCapture.captureBandanna(chosenEnemy);
                    }
                    // Send to barrel.
                    infoBar.GetComponentInChildren <Text>().text = "Sent rights's C player to the monkey barrel!";
                    chosenEnemy.transform.position = gridObject.transform.Find("Tile_2_7").position;
                }
            }
        }
    }