예제 #1
0
    public void ColorCell(Vector3 position, Color color)
    {
        position = transform.InverseTransformPoint(position);
        HexCoordinates coordinates = HexCoordinates.FromPosition(position);
        int            index       = coordinates.X + coordinates.Z * boardWidth + coordinates.Z / 2;

        HexCell cell = cells [index];

        if (cell.GetPlayer() > -1)
        {
            Clicked(cell);
            if (cell.GetPlayer() == getPTurn() && (cell.GetInfo().actions > 0 || cell.GetInfo().attacks > 0))
            {
                if (cell.GetActive())
                {
                    ResetCells();
                    Deactivated(cell);
                }
                else
                {
                    ResetCells();
                    cell.paintNeigbors();
                    cell.SetActive(true);
                }
            }
            else if (cell.GetPlayer() != getPTurn())
            {
                HexDirection dir = cell.getActiveNeigbor();
                if (dir != HexDirection.None)
                {
                    HexCell attacker = cell.GetNeighbor(dir);
                    attackCell(attacker, cell);
                    if (attacker.checkRanged() && cell.GetNeighbor(HexUtilities.oppositeSide(dir)))
                    {
                        attackCell(attacker, cell.GetNeighbor(HexUtilities.oppositeSide(dir)));
                    }
                    attacker.GetInfo().attacks--;
                }
                else
                {
                    dir = cell.getActiveLancer();
                    if (dir != HexDirection.None && cell.GetNeighbor(dir).GetNeighbor(dir).checkRanged())
                    {
                        HexCell attacker = cell.GetNeighbor(dir).GetNeighbor(dir);
                        attackCell(attacker, cell);
                        attackCell(attacker, cell.GetNeighbor(dir));
                        attacker.GetInfo().attacks--;
                    }
                }
            }
        }
        else
        {
            HexDirection dir = cell.getActiveNeigbor();
            if (dir != HexDirection.None)
            {
                moveCell(cell, dir);
            }
        }
        hexMesh.Triangulate(cells);
    }