Ejemplo n.º 1
0
    private static List <Vector2Int> GetFreeDirection(Vector2Int pos, Cell[,] map, ref int[,] ways)
    {
        List <Vector2Int> directions = new List <Vector2Int>();

        for (int y = pos.y - 1; y <= pos.y + 1; y++)
        {
            for (int x = pos.x - 1; x <= pos.x + 1; x++)
            {
                if (x >= 0 && y >= 0 && x < ways.GetLength(1) && y < ways.GetLength(0))
                {
                    if ((x == pos.x && y != pos.y) || (y == pos.y && x != pos.x))
                    {
                        if (ways[y, x] == 0)
                        {
                            Vector2Int newPos = new Vector2Int(x, y);
                            TypeDir    dir    = Cell.ConvertFromVector(newPos - pos);
                            if (map[pos.y, pos.x].GetWall(dir) == 0)
                            {
                                directions.Add(newPos);
                            }
                        }
                    }
                }
            }
        }

        return(directions);
    }
Ejemplo n.º 2
0
    private static Vector2Int GetMinCellForWay(Vector2Int pos, Cell[,] map, int[,] ways)
    {
        Vector2Int minPos = pos;

        for (int y = pos.y - 1; y <= pos.y + 1; y++)
        {
            for (int x = pos.x - 1; x <= pos.x + 1; x++)
            {
                if (x >= 0 && y >= 0 && x < ways.GetLength(1) && y < ways.GetLength(0))
                {
                    if ((x == pos.x && y != pos.y) || (y == pos.y && x != pos.x))
                    {
                        Vector2Int newPos = new Vector2Int(x, y);
                        TypeDir    dir    = Cell.ConvertFromVector(newPos - pos);
                        if (map[pos.y, pos.x].GetWall(dir) == 0)
                        {
                            if (ways[y, x] < ways[minPos.y, minPos.x])
                            {
                                return(new Vector2Int(x, y));
                            }
                        }
                    }
                }
            }
        }

        return(minPos);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Алгоритм тунельного прокладывания лабиринта
    /// </summary>
    private static bool DigMaze(ref Cell[,] map, ref Vector2Int currentPoint, ref Stack <Vector2Int> track)
    {
        map[currentPoint.y, currentPoint.x].Lock = false;

        foreach (var wall in map[currentPoint.y, currentPoint.x].walls.OrderBy(x => x.Value))
        {
            Vector2Int direction = Helper.ConvertDirToVector(wall.Key);
            Vector2Int nextPoint = currentPoint + direction;

            if (Helper.VerifyBorderByCell(_height, _width, nextPoint))
            {
                if (map[nextPoint.y, nextPoint.x].Lock)
                {
                    // unlock
                    map[currentPoint.y, currentPoint.x].SetWall(wall.Key, 0);
                    track.Push(currentPoint);

                    TypeDir nextDir = Helper.ConvertVectorToDir(Helper.InvertVector2(direction));
                    map[nextPoint.y, nextPoint.x].SetWall(nextDir, 0);
                    currentPoint = nextPoint;

                    return(true);
                }
            }
        }

        return(false);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Проверка может ли игрок походить в выбраном направлении
    /// </summary>
    private bool CanPass(Vector2Int dir)
    {
        TypeDir    type    = Helper.ConvertVectorToDir(dir);
        Vector2Int nextPos = currentPos + dir;

        if (nextPos.y >= 0 && nextPos.y < mapController.Map.GetLength(0) && nextPos.x >= 0 && nextPos.x < mapController.Map.GetLength(1))
        {
            return(mapController.Map[currentPos.y, currentPos.x].walls[type] == 0);
        }

        return(false);
    }
Ejemplo n.º 5
0
    public void SetDirectionButton(TypeDir dir)
    {
        switch (dir)
        {
        case TypeDir.Below:
            SetColor(bottom);
            break;

        case TypeDir.Right:
            SetColor(right);
            break;

        case TypeDir.Left:
            SetColor(left);
            break;

        case TypeDir.Top:
            SetColor(top);
            break;
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Метод уничтожения стены в заданой клетке
    /// </summary>
    private static void BreakOneWall(Vector2Int currentPoint, ref Cell[,] map)
    {
        foreach (var wall in map[currentPoint.y, currentPoint.x].walls.OrderBy(x => x.Value))
        {
            Vector2Int direction = Helper.ConvertDirToVector(wall.Key);
            Vector2Int nextPoint = currentPoint + direction;

            if (Helper.VerifyBorderByCell(_height, _width, nextPoint))
            {
                if (map[currentPoint.y, currentPoint.x].GetWall(wall.Key) != 0)
                {
                    // unlock
                    map[currentPoint.y, currentPoint.x].SetWall(wall.Key, 0);

                    TypeDir nextDir = Helper.ConvertVectorToDir(Helper.InvertVector2(direction));
                    map[nextPoint.y, nextPoint.x].SetWall(nextDir, 0);

                    break;
                }
            }
        }
    }
Ejemplo n.º 7
0
    public static Vector2Int ConvertDirToVector(TypeDir dir)
    {
        Vector2Int vector = Vector2Int.zero;

        switch (dir)
        {
        case TypeDir.Top:
            vector = Vector2Int.up;
            break;

        case TypeDir.Right:
            vector = Vector2Int.right;
            break;

        case TypeDir.Below:
            vector = Vector2Int.down;
            break;

        case TypeDir.Left:
            vector = Vector2Int.left;
            break;
        }
        return(vector);
    }
Ejemplo n.º 8
0
 /// <summary>
 /// Метод присвоения веса стене по её типу
 /// </summary>
 public void SetWall(TypeDir dir, int value)
 {
     walls[dir] = value;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Метод получения веса стены по её типу
 /// </summary>
 public int GetWall(TypeDir dir)
 {
     return(walls[dir]);
 }
Ejemplo n.º 10
0
 private void RpcSetHandButton(TypeDir dir)
 {
     input.SetDirectionButton(dir);
 }
Ejemplo n.º 11
0
 private void CmdSetHandButton(TypeDir dir)
 {
     RpcSetHandButton(dir);
 }