Exemple #1
0
    //this is how we tell if a hex is occupied
    public void OccupiedHex()
    {
        string clickTile;
        //open and access the map and click
        GameObject       board = GameObject.Find("map");
        Map_v12          map   = board.GetComponent <Map_v12>();
        ClickableTile_v5 click = board.GetComponent <ClickableTile_v5>();

        clickTile = click.clickCoor;
        //access the lizard battle so it runs on that, not the general battle script
        GameObject liz       = GameObject.Find("Lizard");
        Lizard_v3  lizClass  = liz.GetComponent <Lizard_v3>();
        Battle_v3  lizBattle = liz.GetComponent <Battle_v3>();

        //Debug.Log(clickTile);
        //this is how battle is called, and the condition is if the hex is in occupied hex list AND is in the lizards neighbor list
        if ((lizBattle.OccupiedHexs.ContainsKey(clickTile)) && (lizClass.actualNeighbors.Contains(clickTile)))
        {
            GameObject bird      = GameObject.Find(lizBattle.OccupiedHexs[clickTile]);
            Bird_v3    birdClass = bird.GetComponent <Bird_v3>();
            lizBattle.enemy = birdClass.unit;
            lizBattle.Battle();
        }

        //Healing
        if ((lizClass.healingTiles.Contains(clickTile)) && (lizClass.actualNeighbors.Contains(clickTile)))
        {
            Debug.Log("Lizard walked into a healing fountain and replenished 10 Health");
            self.health += 10;
            lizClass.healingTiles.Remove(clickTile);

            //lizBattle.healing();
            Debug.Log(self.health);
        }
    }
Exemple #2
0
    public void Battle()
    {
        //access lizard and his battle script
        GameObject liz       = GameObject.Find("Lizard");
        Lizard_v3  lizClass  = liz.GetComponent <Lizard_v3>();
        Battle_v3  lizBattle = liz.GetComponent <Battle_v3>();
        //access the map and clickableTile scripts
        GameObject       board  = GameObject.Find("map");
        Map_v12          map    = board.GetComponent <Map_v12>();
        ClickableTile_v5 click  = board.GetComponent <ClickableTile_v5>();
        GameObject       textEd = GameObject.Find("textControl");

        Debug.Log("A Battle has Begun!");
        textEd.BroadcastMessage("textUpdate", "A Battle has Begun!");
        canvas.SetActive(true);
        GameObject scrH = GameObject.Find("Scriptholder");

        scrH.SendMessage("setRUnit", gameObject.name);
        mapHolder.SetActive(false);
    }
    public void Battle()
    {
        //access lizard and his battle script
        GameObject liz       = GameObject.Find("Lizard");
        Lizard_v3  lizClass  = liz.GetComponent <Lizard_v3>();
        Battle_v3  lizBattle = liz.GetComponent <Battle_v3>();
        //access the map and clickableTile scripts
        GameObject       board = GameObject.Find("map");
        Map_v12          map   = board.GetComponent <Map_v12>();
        ClickableTile_v5 click = board.GetComponent <ClickableTile_v5>();

        //debug info about battle
        Debug.Log("A Battle has Begun!");
        //attack lowers the enemy's health
        enemy.health = enemy.health - self.attack;
        Debug.Log("Bird has " + enemy.health + " health remaining!");
        //it also hurts our hero equal to enemy's attack value.
        self.health = self.health - enemy.attack;
        Debug.Log(self.name + " has " + self.health + " health remaining!");
        //if an enemy is killed, this is what we do
        if (enemy.health <= 0)
        {
            //tell us he died, name him dead, and then destroy the game object
            Debug.Log(enemy.toonName + " has DIED!");
            GameObject dead = GameObject.Find(lizBattle.OccupiedHexs[click.clickCoor]);
            Destroy(dead);
            lizBattle.OccupiedHexs.Remove(click.clickCoor);
            //increment birds slain for scoring purposes
            birdsSlain += 1;
            Debug.Log("Lizard has slain " + birdsSlain + " birds");
        }
        //if the hero dies. This should end game more elegently than crashing, as we do now.
        if (self.health <= 0)
        {
            Debug.Log(self.toonName + " has DIED");
            GameObject dead = GameObject.Find("Lizard");
            Destroy(dead);
        }
    }
    //buildmap function
    public void buildMapTiles()
    {
        i = 1;
        // size of map in tiles
        float x_offset = .76f;
        float y_offset = .89f;

        //start loop to formulate grid. The grid ends up WIDTH x HEIGHT Hexs
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {   //odd column? If so, we push it over some. If not, aligned ass normal
                float y_pos = y * y_offset;


                if (x % 2 == 1)
                {
                    y_pos += y_offset / 2;
                }
                //randomize an integer so we can assign what type of tile will be used
                //for each instantiation. Thus, this allows for a randomized tile board.
                int tileType = Random.Range(1, 6);

                if (tileType == 1)
                {
                    hex_prefab = fire_prefab;
                }

                else if (tileType == 2)
                {
                    hex_prefab = basic_prefab;
                }
                else if (tileType == 3)
                {
                    hex_prefab = water_prefab;
                }
                else if (tileType == 4)
                {
                    //temporary strings to make entry for list of healing tiles
                    string tmpXStr;
                    string tmpYStr;
                    string healTileStr;
                    //hex prefab assignment
                    hex_prefab = healing_prefab;
                    //string creation
                    tmpXStr     = (x - (width / 2)).ToString();
                    tmpYStr     = (y - (height / 2)).ToString();
                    healTileStr = '(' + tmpXStr + ", " + tmpYStr + ')';
                    //add tile coordinates to dictionary
                    GameObject liz      = GameObject.Find("Lizard");
                    Lizard_v3  lizClass = liz.GetComponent <Lizard_v3>();
                    lizClass.healingTiles.Add(healTileStr);
                }

                else if (tileType == 5)
                {
                    string tmpXStr;
                    string tmpYStr;
                    hex_prefab = enemy_prefab;

                    //on all black tiles, spawn an instantiated version of our bird object
                    GameObject bird = (GameObject)Instantiate(enemy, new Vector3(x * x_offset, .5f, y_pos), Quaternion.Euler(90, 180, 0));
                    //name it Bird + i with i incrementing, so we can access them easily
                    bird.name = "Bird " + i;
                    Bird_v3   birdScript = bird.AddComponent <Bird_v3>();
                    Battle_v3 battle     = bird.GetComponent <Battle_v3>();
                    //assign each bird with its unity coordinates and its tile coordinates.
                    birdScript.xLoc    = (x * x_offset);
                    birdScript.yLoc    = (y_pos);
                    birdScript.xTile   = (x - (width / 2));
                    birdScript.yTile   = (y - (height / 2));
                    tmpXStr            = (x - (width / 2)).ToString();
                    tmpYStr            = (y - (height / 2)).ToString();
                    birdScript.tileStr = '(' + tmpXStr + ", " + tmpYStr + ')';
                    //create a NEW base unit for each unit, so they do NOT share health
                    baseUnit sub = new baseUnit();
                    battle.self     = sub;
                    birdScript.unit = sub;
                    //open lizards list of occupied hexes and append each spawned birds location for tracking
                    GameObject liz       = GameObject.Find("Lizard");
                    Battle_v3  lizBattle = liz.GetComponent <Battle_v3>();
                    bird.transform.SetParent(this.transform);
                    lizBattle.OccupiedHexs.Add(birdScript.tileStr, bird.name);

                    //increment i for naming and tracking total number of birds
                    i++;
                }
                //once we randomize which prefab we are using, this is what actually creates, names, and parents each tile in map
                GameObject       hex_ob = (GameObject)Instantiate(hex_prefab, new Vector3(x * x_offset, 0, y_pos), Quaternion.Euler(90, 90, 0));
                ClickableTile_v5 ct     = hex_ob.AddComponent <ClickableTile_v5>();
                //This assigns values to each tile that contain its location in our coordinate system and in unity gamespace. This is tracked
                //via the ClickableTile script on the MAP game object
                ct.tileX = (x - (width / 2));
                ct.tileY = (y - (height / 2));
                ct.xLoc  = x * x_offset;
                ct.yLoc  = y_pos;
                ct.x     = x;
                ct.y     = y;
                ct.map   = this;

                //dictionary pairings
                string coor;
                string unityCoor;
                string xString;
                string yString;
                string unityXStr;
                string unityYStr;
                float  xFloat;
                float  yFloat;
                int    xCenterConv;
                int    yCenterConv;

                //this was a major update that shifted our coordinate system (behind the scenes mostly) to an orientation
                //where 0,0 was center and everything radiated out from there. Simplified movement in the end
                xCenterConv = (x - (width / 2));
                yCenterConv = (y - (height / 2));
                //creating an (x,y) coordinate pair to store a key of (hexX, hexY)
                xString = xCenterConv.ToString();
                yString = yCenterConv.ToString();
                //creating an (x,y) coordinate pair as a value for (HexUnitySpaceX, HexUnitySpaceY)
                xFloat    = x * x_offset;
                yFloat    = y_pos;
                unityXStr = (xFloat).ToString();
                unityYStr = yFloat.ToString();
                //convert these values to strings for storage in dict
                coor      = "(" + xString + ", " + yString + ")";
                unityCoor = "(" + unityXStr + ", " + unityYStr + ")";
                //unityCoor = string.Format("({0:0.0##}, {0:0.0##})", unityXStr, unityYStr);
                //add (hexX, HexY) : (HexUnitySpaceX, HexUnitySpaceY
                tileLocPairs.Add(coor, unityCoor);
                tileLocPairsInverse.Add(unityCoor, coor);
                //is also reason our updated coordinate system works
                //Starts communicating with our neighbor script to determine which hex border one another
                Neighbor_v3 neighbor = hex_ob.AddComponent <Neighbor_v3>();
                //creating and sending info for each neighbor script on each hex
                string xright;
                string xleft;
                string yup;
                string ydown;
                //up down left and right
                xright = (xCenterConv + 1).ToString();
                xleft  = (xCenterConv - 1).ToString();
                yup    = (yCenterConv + 1).ToString();
                ydown  = (yCenterConv - 1).ToString();
                //hex 0 0
                if ((x == 0) & (y == 0))
                {
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //if origin is 0-0 in bottom left, this is top left
                if ((x == 0) & (y == height - 1))
                {
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //top right
                if ((x == width - 1) & (y == height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //bottom right
                if ((x == width - 1) & (y == 0))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //left-most x minus the two endpoints
                if ((x == 0) & ((0 < y) & (y < height - 1)))
                {
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //right-most x minus the two endpoints
                if ((x == width - 1) & ((0 < y) & (y < height - 1)))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //all even columns at y = 0
                if ((x % 2 == 0) & (x != 0) & (x != width - 1) & (y == 0))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //all even columns y = map height
                if ((x % 2 == 0) & (x != 0) & (x != width - 1) & (y == height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + ydown + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //all even columns other than y = 0 and y = map height (essentially all even-column non-endpoints)
                if ((x % 2 == 0) & (x != 0) & (x != width - 1) & (y != 0) & (y != height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + ydown + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //all odd columns y = 0
                if ((x % 2 == 1) & (y == 0))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + yup + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yup + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //all odd columns y = height
                if ((x % 2 == 1) & (y == height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //all odd columns non-endpoints
                if ((x % 2 == 1) & (y != 0) & (y != height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + yup + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yup + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //names each hex with coordinate point, puts all instantiated hexs within map empty game element.
                hex_ob.name = "Hex_" + x + "_" + y;
                hex_ob.transform.SetParent(this.transform);
            }
        }
    }
Exemple #5
0
    public void battleWithResults(bool qResult)
    {
        //access lizard and his battle script
        GameObject liz       = GameObject.Find("Lizard");
        Lizard_v3  lizClass  = liz.GetComponent <Lizard_v3>();
        Battle_v3  lizBattle = liz.GetComponent <Battle_v3>();
        //access the map and clickableTile scripts
        GameObject       board = GameObject.Find("map");
        Map_v12          map   = board.GetComponent <Map_v12>();
        ClickableTile_v5 click = board.GetComponent <ClickableTile_v5>();

        GameObject textEd = GameObject.Find("textControl");

        if (qResult == true)
        {
            Debug.Log("Player Answered Correctly");
            textEd.BroadcastMessage("textUpdate", "Correct! You recieved a stat buff to help in battle.");
            self.attack  = self.attack * 2;
            enemy.health = enemy.health - self.attack;
            Debug.Log("Bird has " + enemy.health + " health remaining!");
            //it also hurts our hero equal to enemy's attack value.
            self.health = self.health - enemy.attack;
            Debug.Log(self.name + " has " + self.health + " health remaining!");
            self.attack = self.attack / 2;
        }
        else
        {
            Debug.Log("Player Answered Incorrectly");
            textEd.BroadcastMessage("textUpdate", "Incorrect! Your defense is weakened.");
            self.health -= 2;
            enemy.health = enemy.health - self.attack;
            Debug.Log("Bird has " + enemy.health + " health remaining!");
            //it also hurts our hero equal to enemy's attack value.
            self.health = self.health - enemy.attack;
            Debug.Log(self.name + " has " + self.health + " health remaining!");
        }

        /*
         * enemy.health = enemy.health - self.attack;
         * Debug.Log("Bird has " + enemy.health + " health remaining!");
         * //it also hurts our hero equal to enemy's attack value.
         * self.health = self.health - enemy.attack;
         * Debug.Log(self.name + " has " + self.health + " health remaining!");
         */
        //if an enemy is killed, this is what we do
        if (enemy.health <= 0)
        {
            //tell us he died, name him dead, and then destroy the game object
            Debug.Log(enemy.toonName + " has DIED!");
            GameObject dead = GameObject.Find(lizBattle.OccupiedHexs[click.clickCoor]);
            Destroy(dead);
            lizBattle.OccupiedHexs.Remove(click.clickCoor);
            //increment birds slain for scoring purposes
            birdsSlain += 1;
            Debug.Log("Lizard has slain " + birdsSlain + " birds");
        }
        //if the hero dies. This should end game more elegently than crashing, as we do now.
        if (self.health <= 0)
        {
            Debug.Log(self.toonName + " has DIED");
            GameObject dead = GameObject.Find("Lizard");
            Destroy(dead);
        }
    }
    //buildmap function
    public void buildMapTiles()
    {
        // size of map in tiles
        float x_offset = .76f;
        float y_offset = .89f;

        //start loop to formulate grid. The grid ends up WIDTH x HEIGHT Hexs
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {   //odd column? If so, we push it over some. If not, aligned ass normal
                float y_pos = y * y_offset;

                if (x % 2 == 1)
                {
                    y_pos += y_offset / 2;
                }
                //randomize an integer so we can assign what type of tile will be used
                //for each instantiation. Thus, this allows for a randomized tile board.
                int tileType = Random.Range(1, 4);
                if (tileType == 1)
                {
                    hex_prefab = fire_prefab;
                }
                else if (tileType == 2)
                {
                    hex_prefab = water_prefab;
                }
                else if (tileType == 3)
                {
                    hex_prefab = goth_prefab;
                    GameObject bird = (GameObject)Instantiate(enemy, new Vector3(x * x_offset, .5f, y_pos), Quaternion.Euler(90, 180, 0));
                }
                //once it has which prefab to use, this is what actually creates, names, and parents each tile in map

                GameObject       hex_ob = (GameObject)Instantiate(hex_prefab, new Vector3(x * x_offset, 0, y_pos), Quaternion.Euler(90, 90, 0));
                ClickableTile_v5 ct     = hex_ob.AddComponent <ClickableTile_v5>();
                //This assigns values to each tile that contain its location in our coordinate system and in unity gamespace
                ct.tileX = (x - (width / 2));
                ct.tileY = (y - (height / 2));
                ct.xLoc  = x * x_offset;
                ct.yLoc  = y_pos;
                ct.x     = x;
                ct.y     = y;
                //ct.map = this;

                //test dictionary pairings
                string coor;
                string unityCoor;
                string xString;
                string yString;
                string unityXStr;
                string unityYStr;
                float  xFloat;
                float  yFloat;
                int    xCenterConv;
                int    yCenterConv;


                xCenterConv = (x - (width / 2));
                yCenterConv = (y - (height / 2));


                //creating an (x,y) coordinate pair to store a key of (hexX, hexY)
                xString = xCenterConv.ToString();
                yString = yCenterConv.ToString();
                //creating an (x,y) coordinate pair as a value for (HexUnitySpaceX, HexUnitySpaceY)
                xFloat    = x * x_offset;
                yFloat    = y_pos;
                unityXStr = (xFloat).ToString();
                unityYStr = yFloat.ToString();

                //convert these values to strings for storage in dict
                coor      = "(" + xString + ", " + yString + ")";
                unityCoor = "(" + unityXStr + ", " + unityYStr + ")";
                //unityCoor = string.Format("({0:0.0##}, {0:0.0##})", unityXStr, unityYStr);
                //add (hexX, HexY) : (HexUnitySpaceX, HexUnitySpaceY
                tileLocPairs.Add(coor, unityCoor);
                tileLocPairsInverse.Add(unityCoor, coor);



                //Starts communicating with our neighbor script to determine which hex border one another
                Neighbor_v3 neighbor = hex_ob.AddComponent <Neighbor_v3>();
                //creating and sending info for each neighbor script on each hex
                string xright;
                string xleft;
                string yup;
                string ydown;
                //up down left and right
                xright = (xCenterConv + 1).ToString();
                xleft  = (xCenterConv - 1).ToString();
                yup    = (yCenterConv + 1).ToString();
                ydown  = (yCenterConv - 1).ToString();
                //hex 0 0
                if ((x == 0) & (y == 0))
                {
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //if origin is 0-0 in bottom left, this is top left
                if ((x == 0) & (y == height - 1))
                {
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //top right
                if ((x == width - 1) & (y == height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //bottom right
                if ((x == width - 1) & (y == 0))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //left-most x minus the two endpoints
                if ((x == 0) & ((0 < y) & (y < height - 1)))
                {
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //right-most x minus the two endpoints
                if ((x == width - 1) & ((0 < y) & (y < height - 1)))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //all even columns at y = 0
                if ((x % 2 == 0) & (x != 0) & (x != width - 1) & (y == 0))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //all even columns y = map height
                if ((x % 2 == 0) & (x != 0) & (x != width - 1) & (y == height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + ydown + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //all even columns other than y = 0 and y = map height (essentially all even-column non-endpoints)
                if ((x % 2 == 0) & (x != 0) & (x != width - 1) & (y != 0) & (y != height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + ydown + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //all odd columns y = 0
                if ((x % 2 == 1) & (y == 0))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + yup + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yup + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //all odd columns y = height
                if ((x % 2 == 1) & (y == height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                }
                //all odd columns non-endpoints
                if ((x % 2 == 1) & (y != 0) & (y != height - 1))
                {
                    neighbor.neighborX.Add("(" + xleft + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yCenterConv + ")");
                    neighbor.neighborX.Add("(" + xleft + ", " + yup + ")");
                    neighbor.neighborX.Add("(" + xright + ", " + yup + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + ydown + ")");
                    neighbor.neighborY.Add("(" + xCenterConv + ", " + yup + ")");
                }
                //names each hex with coordinate point, puts all instantiated hexs within map empty game element.
                hex_ob.name = "Hex_" + x + "_" + y;
                hex_ob.transform.SetParent(this.transform);
            }
        }
    }
    void OnMouseUp()

    {
        string xstr;
        string ystr;
        string unityStr;
        string unityStrX;
        string unityStrY;
        //testing
        int length;
        //end testing


        GameObject board = GameObject.Find("map");

        map = board.GetComponent <Map_v12>();
        ClickableTile_v5 ct = board.GetComponent <ClickableTile_v5>();

        GameObject liz       = GameObject.Find("Lizard");
        Lizard_v3  lizard    = liz.GetComponent <Lizard_v3>();
        Battle_v3  lizBattle = liz.GetComponent <Battle_v3>();

        lizBattle.OccupiedHexs.Remove(lizard.tileStr);

        GameObject           mouse      = GameObject.Find("mouse");
        MouseInputControl_v3 mouseInput = mouse.GetComponent <MouseInputControl_v3>();

        ct.clickX = tileX;
        ct.clickY = tileY;
        xstr      = tileX.ToString();
        ystr      = tileY.ToString();

        ct.clickCoor = "(" + xstr + ", " + ystr + ")";

        unityStr = map.tileLocPairs[ct.clickCoor];
        string[] tiles = unityStr.Split(new char[] { '(', ',', ')' });
        //x tile coordinate
        unityStrX = tiles[1];
        unityStrY = tiles[2];
        ct.xLoc   = float.Parse(unityStrX);
        //y tile coordinate
        ct.yLoc = float.Parse(unityStrY);


        lizard.lizardMove();
        lizard.characterLocationUpdate();


        //test from here down(battle testing)
        Battle_v3 battle = liz.GetComponent <Battle_v3>();

        battle.OccupiedHex();
        battle.OccupiedHexList();

        length = battle.OccupiedHexs.Count;

        //selected unit toggling?
        //mouseInput.SelectedUnit();

        if (length == 0)
        {
            Debug.Log("No Occupied Hexs");
        }
        if (length >= 1)
        {
            //foreach (var units in battle.OccupiedHexs)
            //  Debug.Log("Key:" + units.Key + " Value:" + units.Value);
        }

        /*
         * Debug.Log("Click!");
         * map.MoveUnitTo(xLoc, yLoc);
         * GameObject liz = GameObject.Find("Lizard");
         * lizard lizard = liz.GetComponent<lizard>();
         * lizard.characterLocationUpdate();
         */
    }
Exemple #8
0
    //test movement module
    public void lizardMove()
    {
        //open map and clickable tile
        GameObject       board = GameObject.Find("map");
        Map_v12          map   = board.GetComponent <Map_v12>();
        ClickableTile_v5 click = board.GetComponent <ClickableTile_v5>();
        //declarations
        string xstr;
        string ystr;

        xstr = click.x.ToString();
        ystr = click.y.ToString();
        float charHeight;

        //opening lizard and lizards battle script for battle
        GameObject liz      = GameObject.Find("Lizard");
        Battle_v3  battle   = liz.GetComponent <Battle_v3>();
        Lizard_v3  lizClass = liz.GetComponent <Lizard_v3>();

        //give movement permissions: aka these below are the only valid click options to move/attack
        //left or right 2
        if (((click.clickX == xTile - 2 & click.clickY == yTile) || (click.clickX == xTile + 2 & click.clickY == yTile)) ||
            //left or right 1
            ((click.clickX == xTile - 1 & click.clickY == yTile) || (click.clickX == xTile + 1 & click.clickY == yTile)) ||
            //diagonal up 2
            ((click.clickX == xTile - 2 & click.clickY == yTile + 1) || (click.clickX == xTile + 2 & click.clickY == yTile + 1)) ||
            //up and down 1
            ((click.clickX == xTile & click.clickY == yTile - 1) || (click.clickX == xTile & click.clickY == yTile + 1)) ||
            //diagonal down 2
            ((click.clickX == xTile - 2 & click.clickY == yTile - 1) || (click.clickX == xTile + 2 & click.clickY == yTile - 1)) ||
            //bug cases, because they are dependent on orientation of x value being odd/even
            //diagonal up 1 if x is even
            (((click.clickX == xTile - 1 & click.clickY == yTile + 1) || (click.clickX == xTile + 1 & click.clickY == yTile + 1)) & (xTile % 2 == 0)) ||
            //diagonal down 1 if x is odd
            (((click.clickX == xTile - 1 & click.clickY == yTile - 1) || (click.clickX == xTile + 1 & click.clickY == yTile - 1)) & ((xTile % 2 == 1) || (xTile % 2 == -1))))

        {
            //names we need
            float unityX;
            float unityY;
            unityX     = click.xLoc;
            unityY     = click.yLoc;
            charHeight = .5f;
            //checks if the coordinates of the tile clicked on matches the coordinates of a list containing all occupied tiles
            //if true (ie if tile is occuppied) then battle commences

            //this needs to be cleaned up/unwrapped I believe it is wholly unneccessary/redundent here, as battle is called elsewhere
            if (battle.OccupiedHexs.ContainsKey(click.clickCoor))
            {
                //Debug.Log("BATTLE");
                //battle.Battle();
            }

            else if (lizClass.healingTiles.Contains(click.clickCoor))
            {
                //heal
            }

            //otherwise, move if it is a valid destination
            else
            {
                //restart neighbors list because we moved
                actualNeighbors.Clear();

                //find the list of move tiles and destroy all the game objects
                GameObject[] moveTilesArray;
                moveTilesArray = GameObject.FindGameObjectsWithTag("moveHex");
                foreach (GameObject moveTile in moveTilesArray)
                {
                    Destroy(moveTile);
                }
                //move to the unity coordinates of valid click/move/attack tile
                liz.transform.position = new Vector3(unityX, charHeight, unityY);
                //temporary strings we will be using to create next batch of highlight tiles and update our list of neighbors for valid locations
                string unityXStr;
                string unityYStr;
                string neighUnityStr;
                //spawn optional move highlights, ensure these spawns are bound in the map
                //down 1
                if ((unityY - .89f) >= 0)
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX, 0, unityY - .89f), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX).ToString();
                    unityYStr     = Math.Round((unityY - .89f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    Debug.Log(neighUnityStr);
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //to the left 1 and up 1
                if (((unityX - .76f) >= 0) && ((unityY + .445f) <= 5.8))
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX - .76f, 0, unityY + .445f), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX - .76f).ToString();
                    unityYStr     = Math.Round((unityY + .445f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //left 1, down 1
                if (((unityX - .76f) >= 0) && (unityY - (.445f) >= 0))
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX - (.76f), 0, unityY - (.445f)), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX - .76f).ToString();
                    unityYStr     = Math.Round((unityY - .445f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //to the left 2
                if (unityX - (.76f * 2) >= 0)
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX - (.76f * 2), 0, unityY), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX - (.76f * 2)).ToString();
                    unityYStr     = Math.Round(unityY, 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //to the left 2, up 2
                if ((unityX - (.76f * 2) >= 0) && ((unityY + .89f) <= 5.785))
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX - (.76f * 2), 0, unityY + .89f), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX - (.76f * 2)).ToString();
                    unityYStr     = Math.Round((unityY + .89f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //to the left 2, down 2
                if ((unityX - (.76f * 2) >= 0) && ((unityY - .89f) >= 0))
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX - (.76f * 2), 0, unityY - .89f), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX - (.76f * 2)).ToString();
                    unityYStr     = Math.Round((unityY - .89f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //to the right one, up one
                if (((unityX + .76f) <= 4.56) && ((unityY + (.445f)) <= 5.8))
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX + .76f, 0, unityY + (.445f)), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX + .76f).ToString();
                    unityYStr     = Math.Round((unityY + .445f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //to the right one, down 1
                if (((unityX + .76f) <= 4.56) && ((unityY - (.445f)) >= 0))
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX + .76f, 0, unityY - .445f), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX + .76f).ToString();
                    unityYStr     = Math.Round((unityY - .445f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //to the right 2
                if ((unityX + (.76f * 2)) <= 4.56)
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX + (.76f * 2), 0, unityY), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX + (.76f * 2)).ToString();
                    unityYStr     = Math.Round(unityY, 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //right 2, up 2
                if (((unityX + (.76f * 2)) <= 4.56) && (unityY + .89f <= 5.8))
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX + (.76f * 2), 0, unityY + .89f), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX + (.76f * 2)).ToString();
                    unityYStr     = Math.Round((unityY + .89f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //right 2, up 2
                if (((unityX + (.76f * 2)) <= 4.56) && (unityY - .89f >= 0))
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX + (.76f * 2), 0, unityY - .89f), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX + (.76f * 2)).ToString();
                    unityYStr     = Math.Round((unityY - .89f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
                //one up
                if ((unityY + .89f) <= 5.8)
                {
                    GameObject moveTiles = (GameObject)Instantiate(mouseHexPrefab, new Vector3(unityX, 0, unityY + .89f), Quaternion.Euler(90, 90, 0));
                    moveTiles.gameObject.tag = "moveHex";
                    //we take our unity location, turn it into a string, then add this neighbor to list if it is "in bounds" of map
                    unityXStr     = (unityX).ToString();
                    unityYStr     = Math.Round((unityY + .89f), 3).ToString();
                    neighUnityStr = '(' + unityXStr + ", " + unityYStr + ')';
                    actualNeighbors.Add(map.tileLocPairsInverse[neighUnityStr]);
                }
            }
        }
        //too far to move there, tell the player so in a better way than this.
        else
        {
            Debug.Log("Cannot move this far");
        }
    }
Exemple #9
0
    //test movement module
    public void lizardMove()
    {
        GameObject       board = GameObject.Find("map");
        Map_v11          map   = board.GetComponent <Map_v11>();
        ClickableTile_v5 click = board.GetComponent <ClickableTile_v5>();
        //declarations
        string xstr;
        string ystr;

        xstr = click.x.ToString();
        ystr = click.y.ToString();
        float charHeight;

        //new, for 2-Y movement in a turn
        int    twoYup      = yTile + 1;
        int    twoYDown    = yTile - 1;
        string twoYUpStr   = twoYup.ToString();
        string twoYDownStr = twoYDown.ToString();

        //finds, assignments
        GameObject liz = GameObject.Find("Lizard");

        /*
         *
         *
         * //finds the hex on which the lizard sits
         * GameObject currentHex = GameObject.Find("Hex_" + xstr + "_" + ystr);
         * //2Yup neighbor game object
         * GameObject twoYUpHex = GameObject.Find("Hex_" + xstr + "_" + twoYUpStr);
         * //2YDown neighbor ob
         * GameObject twoYDownHex = GameObject.Find("Hex_" + xstr + "_" + twoYDownStr);
         * //pulls the neighbors for that hex
         * Neighbor_v3 neighbors = currentHex.GetComponent<Neighbor_v3>();
         * //also pulls the neighbor for 1UpYaxis so he can move 1 X, 1 Y, or 2 Y in a single turn
         * Neighbor_v3 neighbor2Yup = twoYUpHex.GetComponent<Neighbor_v3>();
         * //pulls neighbor 1DownAxis
         * Neighbor_v3 neighbor2YDown = twoYDownHex.GetComponent<Neighbor_v3>();
         *
         */



        //new, used to find battle
        Battle_v3 battle = liz.GetComponent <Battle_v3>();

        //valid neighbor click
        if (((click.clickX == xTile + 1 || click.clickX == xTile + 2 ||
              click.clickX == xTile - 1 || click.clickX == xTile - 2) &
             ((click.clickY == yTile + 1) || (click.clickY == yTile - 1) ||
              (click.clickY == yTile))) ||
            ((click.clickY == yTile + 1 || click.clickY == yTile - 1) & click.clickX == xTile))
        {
            //string unityCoor;
            float unityX;
            float unityY;

            //unityCoor = map.tileLocPairs[click.clickCoor];
            unityX     = click.xLoc;
            unityY     = click.yLoc;
            charHeight = .5f;



            //new shit to make occupied hexs un-enterable
            if (battle.OccupiedHexs.ContainsKey(click.clickCoor))
            {
                battle.Battle();
            }
            //otherwise, move if it is a valid destination
            else
            {
                liz.transform.position = new Vector3(unityX, charHeight, unityY);
            }
        }
        //too far to move there
        else
        {
            Debug.Log("Cannot move this far");
        }
    }