Beispiel #1
0
    void OnMouseDown()
    {
        Competitor humanPlayer = players[0];

        //If the owner of this tile is the human player
        if (owner != null && owner.Equals(humanPlayer))
        {
            Debug.Log("Selected hex has " + this.getTotalUnits() + " units.");

            //and the human player already selected a tile
            if (humanPlayer.getSelected() != null)
            {
                if (humanPlayer.getSelected() == this)//selected tile is this one, deselect it
                {
                    deselect();
                }
                else  //this is a different tile with the same owner, transfer units to here if adjacent, and deselect both

                //transfer units, if adjacent
                {
                    if (this.isNeighbor(humanPlayer.getSelected()))
                    {
                        Hex other       = humanPlayer.getSelected();
                        int numTransfer = other.getMobileUnits();
                        this.addUnits(numTransfer);
                        other.subUnits(numTransfer);

                        //deselect both tiles
                        deselect();
                        humanPlayer.getSelected().deselect();
                    }
                    else  //make this tile the selected one
                    {
                        select();
                    }
                }
            }
            else  //no tile selected, so select this one
            {
                select();
                Debug.Log("No tile was selected");
            }
        }
        else if (humanPlayer.getSelected() != null) //Owner of the tile is an AI, or it is unowned

        {
            if (this.isNeighbor(humanPlayer.getSelected())) //if the two tiles are neighbors
            {
                Hex.fight(humanPlayer.getSelected(), this); //then fight
            }
        }
        else
        {
        }
    }