Пример #1
0
    private void GenerateIsland(HexagonTille source, HashSet <HexagonTille> islandTiles, HashSet <HexagonTille> nonCheckedTiles)
    {
        islandTiles.Clear();
        islandTiles.Add(source);
        var islandCopy = new List <HexagonTille>(islandTiles);

        bool added = true;

        while (added)
        {
            added = false;
            for (int i = 0; i < islandCopy.Count; i++)
            {
                var islandTile = islandCopy[i];

                var neighbourList  = islandTile.NeighbourList;
                int neighbourCount = neighbourList.Count;

                for (int j = 0; j < neighbourCount; j++)
                {
                    var neighbour = neighbourList[j];
                    if (islandTiles.Add(neighbour))
                    {
                        added = true;
                        islandCopy.Add(neighbour);
                        nonCheckedTiles.Remove(neighbour);
                    }
                }
            }
        }
    }
Пример #2
0
 private void MoveToTile(HexagonTille destination)
 {
     if (destination.Action == HexagonTille.ActionType.Move)
     {
         movementController.MoveToTile(destination);
     }
 }
 private void HandleHexagonClick(HexagonTille tile)
 {
     //if (Tiles.Contains(tile) && tile.Action == HexagonTille.ActionType.ChooseAction)
     if (Tiles.Contains(tile))
     {
         systemElementClick.Invoke(this);
     }
 }
Пример #4
0
    private void ApplyRange(HexagonTille tile)
    {
        if (tile.IsComponent || tile.HasPlayer)
        {
            return;
        }

        tile.ColorMiddleTile(moveRangeColor);
        tile.Action = HexagonTille.ActionType.Move;
    }
Пример #5
0
    public void Initialize(HexagonTille tile)
    {
        gameObject.SetActive(true);
        CurrentTile = tile;

        movementController       = Instantiate(movementController);
        movementController.virus = this;
        movementController.SetPlayerPosition(tile);
        movementController.InitPlayerAnimationController();
    }
Пример #6
0
 private void AddTiles(HexagonTille origin)
 {
     foreach (var tile in origin.NeighbourList)
     {
         if (moveSet.Add(tile))
         {
             queue.Enqueue(tile);
         }
     }
 }
Пример #7
0
    public void CreateMoveRange(HexagonTille sourceTile)
    {
        int moveRange = virus.ActionPoints / moveCost;
        var moveList  = rangeCreator.CreateMoveRange(moveRange, sourceTile);

        foreach (var tile in moveList)
        {
            ApplyRange(tile);
            tilesToReset.Add(tile);
        }
    }
Пример #8
0
 public void MoveToTile(HexagonTille tile)
 {
     if (playerAnimationController != null)
     {
         playerAnimationController.Move(tile);
     }
     else
     {
         SetPlayerPosition(tile);
     }
 }
Пример #9
0
    public void SetPlayerPosition(HexagonTille tile)
    {
        virus.transform.position = tile.transform.position;

        virus.CurrentTile.HasPlayer = false;
        int moveDistance = virus.CurrentTile.HexagonCoordinates.DistanceTo(tile.HexagonCoordinates);

        virus.CurrentTile           = tile;
        virus.CurrentTile.HasPlayer = true;
        ResetMoveList(true);
        virus.ActionPoints -= (moveDistance * moveCost);
    }
Пример #10
0
    private void ColorTiles()
    {
        int ColorAreasCount = colorList.Value.Count;

        listOfColoreArea = new List <Tuple <Color, List <HexagonTille> > >(ColorAreasCount);
        HashSet <HexagonTille> tmpTileSet = new HashSet <HexagonTille>(hexTileList);

        var rand = random.Value;

        for (int i = 0; i < ColorAreasCount; i++)
        {
            listOfColoreArea.Add(new Tuple <Color, List <HexagonTille> >(colorList.Value[i], new List <HexagonTille>()));

            var tile = hexTileList.GetRandom(rand);
            tile.ColorTile(listOfColoreArea[i].Item1);
            listOfColoreArea[i].Item2.Add(tile);
            tmpTileSet.Remove(tile);
        }

        int[] lastChecked = new int[ColorAreasCount];

        while (tmpTileSet.Count != 0)
        {
            for (int i = 0; i < ColorAreasCount; i++)
            {
                var color        = listOfColoreArea[i].Item1;
                var coloredList  = listOfColoreArea[i].Item2;
                int coloredCount = coloredList.Count;

                for (int j = lastChecked[i]; j < coloredCount; j++)
                {
                    HexagonTille tile = coloredList[j];
                    for (int k = 0; k < tile.NeighbourList.Count; k++)
                    {
                        var neighbour = tile.NeighbourList[k];

                        if (neighbour.IsColored)
                        {
                            continue;
                        }

                        neighbour.ColorTile(color);
                        coloredList.Add(neighbour);
                        tmpTileSet.Remove(neighbour);
                    }
                }
                lastChecked[i] = coloredCount;
            }
        }
    }
Пример #11
0
    public HashSet <HexagonTille> CreateMoveRange(int range, HexagonTille origin)
    {
        moveSet.Clear();
        queue.Clear();

        moveSet.Add(origin);
        queue.Enqueue(origin);

        for (int i = 0; i < range; i++)
        {
            int queueLength = queue.Count;
            for (int j = 0; j < queueLength; j++)
            {
                HexagonTille next = queue.Dequeue();
                AddTiles(next);
            }
        }

        return(moveSet);
    }
    private void GetMediumElement(HashSet <HexagonTille> source)
    {
        int clearRange = 1;

        foreach (var tile in source)
        {
            if (tile.IsClearRange(clearRange))
            {
                HexagonTille second = tile.NeighbourList.Find(neighbourInClearRange);

                if (second == null)
                {
                    continue;
                }

                HexagonTille third = null;

                int neighbourCount = tile.NeighbourList.Count;
                for (int i = 0; i < neighbourCount; i++)
                {
                    var neighbour = tile.NeighbourList[i];
                    if (second.NeighbourList.Contains(neighbour) && neighbour.IsClearRange(clearRange))
                    {
                        third = neighbour;
                        break;
                    }
                }

                if (third == null)
                {
                    continue;
                }

                elementTiles.Add(tile);
                elementTiles.Add(second);
                elementTiles.Add(third);
                return;
            }
        }
    }
    public void ApplyCoordinates()
    {
        tile.HexagonCoordinates = new HexagonCoordinates(0, 0)
        {
            HasCoordinates  = true,
            MadeCoordinates = true
        };
        MakeCoordinates(tile);
        Queue <HexagonTille>   queue   = new Queue <HexagonTille>(tile.NeighbourList);
        HashSet <HexagonTille> hashSet = new HashSet <HexagonTille>(tile.NeighbourList);

        while (queue.Count != 0)
        {
            HexagonTille next = queue.Dequeue();
            MakeCoordinates(next);
            next.HexagonCoordinates = new HexagonCoordinates(next.HexagonCoordinates.X, next.HexagonCoordinates.Z)
            {
                MadeCoordinates = true,
                HasCoordinates  = true
            };

            int neighbourCount = next.NeighbourList.Count;
            for (int i = 0; i < neighbourCount; i++)
            {
                var neighbour = next.NeighbourList[i];
                if (neighbour.HexagonCoordinates.MadeCoordinates)
                {
                    continue;
                }

                if (hashSet.Add(neighbour))
                {
                    queue.Enqueue(neighbour);
                }
            }
        }
        hashSet.Clear();
    }
Пример #14
0
    private void RemoveTile(HexagonTille tile)
    {
        int tileIndex = TileList.BinarySearch(tile);

        TileList.RemoveAt(tileIndex);
    }
 public HexagonalCoordinateController(HexagonTille tille)
 {
     tile = tille;
 }
 public void Move(HexagonTille moveDestination)
 {
     animator.GetBehaviour <MoveOnStateExit>().SetMoveAction(moveAction, moveDestination);
     animator.SetTrigger(moveId);
 }
Пример #17
0
 public void SetMoveAction(Action <HexagonTille> moveAction, HexagonTille moveDestination)
 {
     this.moveAction      = moveAction;
     this.moveDestination = moveDestination;
 }
    private void MakeCoordinates(HexagonTille centerTile)
    {
        Vector3 centerPosition = centerTile.transform.position;


        int neighbourCount = centerTile.NeighbourList.Count;

        for (int i = 0; i < neighbourCount; i++)
        {
            var neighbour = centerTile.NeighbourList[i];
            if (neighbour.HexagonCoordinates.HasCoordinates)
            {
                continue;
            }

            Vector3 neighbourPosition = neighbour.transform.position;
            Size    ySize             = Size.Equal;
            if (neighbourPosition.y > centerPosition.y)
            {
                ySize = Size.Bigger;
            }
            else if (neighbourPosition.y < centerPosition.y)
            {
                ySize = Size.Smaller;
            }

            Size xSize = Size.Smaller;
            if (neighbourPosition.x > centerPosition.x)
            {
                xSize = Size.Bigger;
            }

            int tileX = centerTile.HexagonCoordinates.X;
            int tileZ = centerTile.HexagonCoordinates.Z;
            HexagonCoordinates coordinates;

            if (xSize == Size.Bigger)
            {
                if (ySize == Size.Equal)
                {
                    coordinates = new HexagonCoordinates(tileX + 1, tileZ);
                }
                else if (ySize == Size.Bigger)
                {
                    coordinates = new HexagonCoordinates(tileX, tileZ + 1);
                }
                else
                {
                    coordinates = new HexagonCoordinates(tileX + 1, tileZ - 1);
                }
            }
            else
            {
                if (ySize == Size.Equal)
                {
                    coordinates = new HexagonCoordinates(tileX - 1, tileZ);
                }
                else if (ySize == Size.Bigger)
                {
                    coordinates = new HexagonCoordinates(tileX - 1, tileZ + 1);
                }
                else
                {
                    coordinates = new HexagonCoordinates(tileX, tileZ - 1);
                }
            }

            coordinates.HasCoordinates   = true;
            neighbour.HexagonCoordinates = coordinates;
        }
    }