예제 #1
0
 void SetGridObject(int x, int y, TGridObject value)
 {
     if (x >= 0 && y >= 0 && x < GameManagerData.GetBoardSize() && y < GameManagerData.GetBoardSize())
     {
         gridArray[x, y] = value;
         //if (OnGridValueChanged != null) OnGridValueChanged(this, new OnGridValueChangedEventArgs { x = x, y = y });
     }
 }
예제 #2
0
    private void SetStartAndEndPoint(Transform gridParent)
    {
        var startNodePosition = (GameManagerData.GetStartPointX() * GameManagerData.GetBoardSize()) + GameManagerData.GetStartPointY();

        gridParent.GetChild(startNodePosition).GetComponent <SpriteRenderer>().sprite = startSprite;

        var endNodePosition = (GameManagerData.GetEndPointX() * GameManagerData.GetBoardSize()) + GameManagerData.GetEndPointY();

        gridParent.GetChild(endNodePosition).GetComponent <SpriteRenderer>().sprite = endSprite;
    }
예제 #3
0
    public void CheckNumberOfObstacles()
    {
        var maxNumberOfObstacles = GameManagerData.GetBoardSize() * GameManagerData.GetBoardSize() / 2;

        if (GetComponent <InputField>().text.Length > 0 && int.Parse(GetComponent <InputField>().text.ToString()) > maxNumberOfObstacles)
        {
            CustomEvents.showWarningDialogEvent.Invoke("Number of obstacles can't be larger than: " + maxNumberOfObstacles); //half of the board size!
            GetComponent <InputField>().text = GetComponent <InputField>().text.Remove(0);
        }
    }
예제 #4
0
 public TGridObject GetGridObject(int x, int y)
 {
     if (x >= 0 && y >= 0 && x < GameManagerData.GetBoardSize() && y < GameManagerData.GetBoardSize())
     {
         return(gridArray[x, y]);
     }
     else
     {
         return(default(TGridObject));
     }
 }
예제 #5
0
 private void PopulateData()
 {
     numberOfTheRuns.text = GetNumberOfTheRuns();
     boardSize.text       = GameManagerData.GetBoardSize().ToString();
     obstacleCount.text   = GameManagerData.GetNumberOfObstacles().ToString();
     algorithmsUsed.text  = GetUsedAlgorithms();
     numberOfFieldsCheckedForFirstAlghoritm.text  = GetNumberOfCheckedFields(CurrentAlgorithmType.A_star);
     numberOfFieldsCheckedForSecondAlghoritm.text = GetNumberOfCheckedFields(CurrentAlgorithmType.Greedy_suboptimal);
     timeSpentForFirstRunner.text  = GetTimeSpent("Runner1");
     timeSpentForSecondRunner.text = GetTimeSpent("Runner2");
 }
    void SetInputValue()
    {
        var fieldType = GetComponent <InputFieldTyperController>().fieldType;

        if (fieldType == InputFieldEnums.InputFieldsTypes.BoardInputField)
        {
            int value = (!string.IsNullOrEmpty(GetComponent <InputField>().text))
                ? int.Parse(GetComponent <InputField>().text)
                : GameManagerData.GetBoardSize();

            GameManagerData.SetBoardSize(value);
        }
        else if (fieldType == InputFieldEnums.InputFieldsTypes.ObstaclesInputField)
        {
            int value = (!string.IsNullOrEmpty(GetComponent <InputField>().text))
                ? int.Parse(GetComponent <InputField>().text)
                : GameManagerData.GetNumberOfObstacles();

            GameManagerData.SetNumberOfObstacles(value);
        }
        else if (fieldType == InputFieldEnums.InputFieldsTypes.StartPosXInputField)
        {
            int value = (!string.IsNullOrEmpty(GetComponent <InputField>().text))
                ? int.Parse(GetComponent <InputField>().text)
                : GameManagerData.GetStartPointX();

            GameManagerData.SetStartPointX(value);
        }
        else if (fieldType == InputFieldEnums.InputFieldsTypes.StartPosYInputField)
        {
            int value = (!string.IsNullOrEmpty(GetComponent <InputField>().text))
                ? int.Parse(GetComponent <InputField>().text)
                : GameManagerData.GetStartPointY();

            GameManagerData.SetStartPointY(value);
        }
        else if (fieldType == InputFieldEnums.InputFieldsTypes.EndPosXInputField)
        {
            int value = (!string.IsNullOrEmpty(GetComponent <InputField>().text))
                ? int.Parse(GetComponent <InputField>().text)
                : GameManagerData.GetEndPointX();

            GameManagerData.SetEndPointX(value);
        }
        else if (fieldType == InputFieldEnums.InputFieldsTypes.EndPosYInputField)
        {
            int value = (!string.IsNullOrEmpty(GetComponent <InputField>().text))
                ? int.Parse(GetComponent <InputField>().text)
                : GameManagerData.GetEndPointY();

            GameManagerData.SetEndPointY(value);
        }
    }
    public List <Node> GetWalkableNeighbours(Node currentNode, List <Node> nodesArray)
    {
        List <Node> neighbourList = new List <Node>();

        if (currentNode.coorX - 1 >= 0)
        {
            //Left
            AddNodeToList(currentNode.coorX - 1, currentNode.coorY, nodesArray, neighbourList);
            //left down

            if (currentNode.coorY - 1 >= 0)
            {
                AddNodeToList(currentNode.coorX - 1, currentNode.coorY - 1, nodesArray, neighbourList);
            }
            //left up

            if (currentNode.coorY + 1 < GameManagerData.GetBoardSize())
            {
                AddNodeToList(currentNode.coorX - 1, currentNode.coorY + 1, nodesArray, neighbourList);
            }
        }

        if (currentNode.coorX + 1 < GameManagerData.GetBoardSize())
        {
            //Right
            AddNodeToList(currentNode.coorX + 1, currentNode.coorY, nodesArray, neighbourList);
            //right down
            if (currentNode.coorY - 1 >= 0)
            {
                AddNodeToList(currentNode.coorX + 1, currentNode.coorY - 1, nodesArray, neighbourList);
            }
            //right up
            if (currentNode.coorY + 1 < GameManagerData.GetBoardSize())
            {
                AddNodeToList(currentNode.coorX + 1, currentNode.coorY + 1, nodesArray, neighbourList);
            }
        }

        //Down
        if (currentNode.coorY - 1 >= 0)
        {
            AddNodeToList(currentNode.coorX, currentNode.coorY - 1, nodesArray, neighbourList);
        }
        //UP
        if (currentNode.coorY + 1 < GameManagerData.GetBoardSize())
        {
            AddNodeToList(currentNode.coorX, currentNode.coorY + 1, nodesArray, neighbourList);
        }

        return(neighbourList);
    }
예제 #8
0
 public void CheckEndPointXY()
 {
     if (GetComponent <InputField>().text.Length > 0 && GetComponent <InputField>().text[0] != '-')
     {
         if (int.Parse(GetComponent <InputField>().text.ToString()) > GameManagerData.GetBoardSize() - 1)
         {
             CustomEvents.showWarningDialogEvent.Invoke("End point can't be bigger or same as a board size!");
             if (GetComponent <InputField>().text.Length > 0)
             {
                 GetComponent <InputField>().text = GetComponent <InputField>().text.Remove(0);
             }
         }
     }
 }
    private void GenerateNewGame()
    {
        var maxNumberOfObstacles = GameManagerData.GetBoardSize() * GameManagerData.GetBoardSize() / 2;

        int newNumberOfObstacles = GameManagerData.GetNumberOfObstacles() + 1;

        if (maxNumberOfObstacles < newNumberOfObstacles)
        {
            CustomEvents.showWarningDialogEvent.Invoke("Number of obstacles can't be larger than: " + maxNumberOfObstacles); //half of the board size!
        }
        else
        {
            GameManagerData.SetNumberOfObstacles(newNumberOfObstacles);
            CustomEvents.createTableEvent.Invoke();
        }
    }
예제 #10
0
    public Grid(float cellSize, Transform gridParent,
                Sprite walkableSprite, Sprite obstacleSprite, Sprite startSprite, Sprite endSprite,
                List <Coordinate> obstaclesCoordinatesList, Func <Grid <TGridObject>, int, int, TGridObject> CreateGridObject)
    {
        this.cellSize            = cellSize;
        this.walkableSpriteImage = walkableSprite;
        this.obstacleSpriteImage = obstacleSprite;
        this.startSprite         = startSprite;
        this.endSprite           = endSprite;
        this.gridParent          = gridParent;

        gridArray   = new TGridObject[GameManagerData.GetBoardSize(), GameManagerData.GetBoardSize()];
        spriteArray = new Sprite[GameManagerData.GetBoardSize(), GameManagerData.GetBoardSize()];

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                bool isWalkable = true;

                Coordinate current = new Coordinate(x, y);

                foreach (var item in obstaclesCoordinatesList)
                {
                    if (item.x == current.x && item.y == current.y)
                    {
                        isWalkable = false;
                    }
                }

                gridArray[x, y]   = CreateGridObject(this, x, y);
                spriteArray[x, y] = CreateWorldSprite(gridParent, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f, isWalkable);
            }
        }

        SetStartAndEndPoint(gridParent);
        SetCameraBasedOnBoardSize();

        //SetValue(2, 1, 33);
    }
예제 #11
0
    public void CreateTable()
    {
        for (int x = 0; x < GameManagerData.GetBoardSize(); x++)
        {
            for (int y = 0; y < GameManagerData.GetBoardSize(); y++)
            {
                var localPosition = GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f;
                GenerateNodeObject(TilesHolder, localPosition, x, y);
            }
        }

        nodeList.AddRange(tempList);
        //remove start node and end node
        tempList.RemoveAll(node => IsStartNode(node.coorX, node.coorY) || IsEndNode(node.coorX, node.coorY));

        nodesArray = tempList.ToArray();

        var listOfObstacles = GetComponent <ObstaclesGenerator>().StartObstaclesGenerator(nodesArray, StartNode, EndNode);

        SetObstaclesToBoard(listOfObstacles);

        CreatePlayers();
    }
 void Start()
 {
     Camera.main.orthographicSize        = GameManagerData.GetBoardSize() * 1.1f;
     Camera.main.transform.localPosition = new Vector3(GameManagerData.GetBoardSize() / (float)2, Camera.main.transform.localPosition.y, Camera.main.transform.localPosition.z);
 }
 //get index from coordinates
 int GetIndex(int x, int y)
 {
     return((x * GameManagerData.GetBoardSize()) + y + 1);
 }
예제 #14
0
    internal void ColorPath(int x, int y)
    {
        int fieldToColor = x * GameManagerData.GetBoardSize() + y;

        gridParent.GetChild(fieldToColor).GetComponent <SpriteRenderer>().sprite = startSprite;
    }