Exemple #1
0
        public void placementTestSimplePasses()
        {
            test_Level0Map = test_Teams = test_player1Team = testMonkey = GameObject.Instantiate(new GameObject());
            test_GridMap   = test_tile1 = test_tile2 = GameObject.Instantiate(new GameObject());

            test_Level0Map.name   = "Level0Map";
            test_Teams.name       = "Teams";
            test_player1Team.name = "player1Team";
            testMonkey.name       = "player1SlotA";
            test_GridMap.name     = "GridMap";
            test_tile1.name       = "Tile_0_0";
            test_tile2.name       = "Tile_5_9";

            testMonkey.transform.parent       = test_player1Team.transform;
            test_player1Team.transform.parent = test_Teams.transform;
            test_Teams.transform.parent       = test_Level0Map.transform;

            test_tile1.transform.parent = test_GridMap.transform;
            test_tile2.transform.parent = test_GridMap.transform;

            gridPlace = test_GridMap.AddComponent <gridPlacement>();
            Assert.AreEqual(testMonkey.transform.position.x, test_tile2.transform.position.x);
        }
Exemple #2
0
    // Thus far this will execute when the moveButton is pressed. It will turn the grid  blue.
    public void changeMaterial()
    {
        exemptHex = false;
        grid      = GameObject.Find("GridMap");

        // The attack button should be hidden if in movement mode, maybe in the future there should be a stand-alone script for this.
        attackButton.SetActive(false);
        hexPrefabChild = hexPrefab.transform.Find("hex_frame").gameObject;

        // Return to normal mode, grid becomes yellow.
        if (moveButton.GetComponentInChildren <Text>().text == "Confirm Move")
        {
            gridScript gridScript = GameObject.Find("GridMap").GetComponent <gridScript>();
            gridScript.warp(exemptHexName);
            gridScript.choseATile = false;

            moveButton.GetComponentInChildren <Text>().text = "Move";
            moveButton.SetActive(false);

            for (i = 0; i <= 32; i++)
            {
                for (j = 0; j <= 12; j++)
                {
                    specificHex = grid.transform.Find("Tile_" + i + "_" + j).gameObject;
                    gridObject  = grid.transform.Find("Tile_" + i + "_" + j).Find("hex_frame").gameObject;
                    gridObject.GetComponent <MeshRenderer>().material = materialList[(int)GridColor.yellow];
                }
            }
        }

        else
        {  // Enter Movement mode, grid becomes blue.
            moveButton.GetComponentInChildren <Text>().text = "Confirm Move";
            gridScript    gridScript    = GameObject.Find("GridMap").GetComponent <gridScript>();
            gridPlacement gridPlacement = GameObject.Find("GridMap").GetComponent <gridPlacement>();
            isBlue = true;

            for (i = 0; i <= 32; i++)
            {
                for (j = 0; j <= 12; j++)
                {
                    specificHex = grid.transform.Find("Tile_" + i + "_" + j).gameObject;
                    gridObject  = grid.transform.Find("Tile_" + i + "_" + j).Find("hex_frame").gameObject;

                    if (exemptHexName == specificHex.name)
                    {
                        exemptHex = true;
                    }

                    if (exemptHex == false)
                    {
                        gridObject.GetComponent <MeshRenderer>().material = materialList[(int)GridColor.blue];
                    }
                    exemptHex = false;
                }
            }

            switch (gridScript.selectedCharacter.name)
            {
            case "player1SlotA":
                displayRangeofMovement(gridPlacement.leftA);
                break;

            case "player1SlotB":
                displayRangeofMovement(gridPlacement.leftB);
                break;

            case "player1SlotC":
                displayRangeofMovement(gridPlacement.leftC);
                break;

            case "player2SlotA":
                displayRangeofMovement(gridPlacement.rightA);
                break;

            case "player2SlotB":
                displayRangeofMovement(gridPlacement.rightB);
                break;

            case "player2SlotC":
                displayRangeofMovement(gridPlacement.rightC);
                break;
            }
        }
    }
    // 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;
            }
        }
    }
Exemple #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;
        }
    }