Example #1
0
        // active les nouvelles lignes
        void ActivateCoord(GridCoord firstCoord, List <GridCoord> line)
        {
            Debug.Log("size:" + line.Count);
            if (line.Count == 0)
            {
                return;
            }
            firstCoord.SetOwned();
            if (localClient)
            {
                localClient.CmdSpawnNewPointFX(firstCoord.gameObject);
            }

            foreach (GridCoord sndCoord in line)
            {
                if (sndCoord != firstCoord)
                {
                    if (localClient)
                    {
                        sndCoord.SetOwned();
                        //Debug.Log("line drawn");
                        localClient.CmdCreateNewLine(firstCoord.gameObject, sndCoord.gameObject);
                        if (sndCoord == endPoint || firstCoord == endPoint)
                        {
                            //Debug.Log("hello maggle");
                            localClient.CmdEndGrid(endPoint.gameObject, cable);
                        }
                    }
                }

                // activation des points entre les 2 points principaux
                if (firstCoord.GetPosition().x == sndCoord.GetPosition().x)
                {
                    int x     = firstCoord.GetPosition().x;
                    int lowY  = (firstCoord.GetPosition().y < sndCoord.GetPosition().y) ? firstCoord.GetPosition().y : sndCoord.GetPosition().y;
                    int highY = (firstCoord.GetPosition().y < sndCoord.GetPosition().y) ? sndCoord.GetPosition().y : firstCoord.GetPosition().y;

                    for (int i = lowY + 1; i < highY; i++)
                    {
                        _coordsMatrix[x][i].SetActivated();
                    }
                }
                else if (firstCoord.GetPosition().y == sndCoord.GetPosition().y)
                {
                    int y     = firstCoord.GetPosition().y;
                    int lowX  = (firstCoord.GetPosition().x < sndCoord.GetPosition().x) ? firstCoord.GetPosition().x : sndCoord.GetPosition().x;
                    int highX = (firstCoord.GetPosition().x < sndCoord.GetPosition().x) ? sndCoord.GetPosition().x : firstCoord.GetPosition().x;

                    for (int i = lowX + 1; i < highX; i++)
                    {
                        _coordsMatrix[i][y].SetActivated();
                    }
                }
            }
        }
Example #2
0
        bool Good(GridCoord coord)
        {
            if (coord)
            {
                //Debug.Log("coord");
                //Debug.Log("coord: (" + coord.GetPosition().x + "," + coord.GetPosition().y + ")");
                //Debug.Log("coord: (" + _coordsMatrix[coord.GetPosition().x][coord.GetPosition().y].GetPosition().x + "," + _coordsMatrix[coord.GetPosition().x][coord.GetPosition().y].GetPosition().y + ")");
                //Debug.Log(coord.name + ", " + _coordsMatrix[coord.GetPosition().x][coord.GetPosition().y].name);
                if (coord == _coordsMatrix[coord.GetPosition().x][coord.GetPosition().y])
                {
                    //Debug.Log("good position");

                    if (coord.IsAvailable())
                    {
                        //Debug.Log("av");

                        return(true);
                    }
                }
            }
            return(false);
        }
Example #3
0
        public void RpcCheckLines(GameObject coord)
        {
            GridCoord        firstCoord = coord.GetComponent <GridCoord>();
            List <GridCoord> newPoints  = new List <GridCoord>();

            if (!startPointDone)
            {
                if (firstCoord == startPoint)
                {
                    newPoints.Add(firstCoord);
                    newPoints.Add(startPoint);
                    startPointDone = true;
                    currentPoint   = firstCoord;
                }
            }
            else
            {
                if (currentPoint.GetPosition().x == firstCoord.GetPosition().x)
                {
                    int x     = currentPoint.GetPosition().x;
                    int lowY  = (firstCoord.GetPosition().y < currentPoint.GetPosition().y) ? firstCoord.GetPosition().y : currentPoint.GetPosition().y;
                    int highY = (firstCoord.GetPosition().y < currentPoint.GetPosition().y) ? currentPoint.GetPosition().y : firstCoord.GetPosition().y;

                    bool canAdd = true;
                    for (int i = lowY + 1; i < highY; i++)
                    {
                        if (_coordsMatrix[x][i].isActivated())
                        {
                            canAdd = false;
                        }
                    }
                    if (canAdd)
                    {
                        newPoints.Add(firstCoord);
                        newPoints.Add(currentPoint);
                        currentPoint = firstCoord;
                    }
                }
                else if (currentPoint.GetPosition().y == firstCoord.GetPosition().y)
                {
                    int y     = currentPoint.GetPosition().y;
                    int lowX  = (firstCoord.GetPosition().x < currentPoint.GetPosition().x) ? firstCoord.GetPosition().x : currentPoint.GetPosition().x;
                    int highX = (firstCoord.GetPosition().x < currentPoint.GetPosition().x) ? currentPoint.GetPosition().x : firstCoord.GetPosition().x;

                    bool canAdd = true;
                    for (int j = lowX + 1; j < highX; j++)
                    {
                        if (_coordsMatrix[j][y].isActivated())
                        {
                            canAdd = false;
                        }
                    }
                    if (canAdd)
                    {
                        newPoints.Add(firstCoord);
                        newPoints.Add(currentPoint);
                        currentPoint = firstCoord;
                    }
                }
            }
            //foreach (GridCoord c in newPoints)
            //{
            //    Debug.Log("(" + c.GetPosition().x + "," + c.GetPosition().y + ")");
            //}

            ActivateLine(firstCoord, newPoints);
        }
Example #4
0
        // renvoie la liste de points avec lesquels le point coord va former des nouvelles lignes
        List <GridCoord> CheckLines(GridCoord firstCoord)
        {
            List <GridCoord> newPoints = new List <GridCoord>();

            if (!startPointDone)
            {
                Debug.Log("start");
                if (firstCoord == startPoint)
                {
                    newPoints.Add(firstCoord);
                    newPoints.Add(startPoint);
                    startPointDone = true;
                    currentPoint   = firstCoord;
                }
                return(newPoints);
            }
            else
            {
                if (currentPoint.GetPosition().x == firstCoord.GetPosition().x)
                {
                    int x     = currentPoint.GetPosition().x;
                    int lowY  = (firstCoord.GetPosition().y < currentPoint.GetPosition().y) ? firstCoord.GetPosition().y : currentPoint.GetPosition().y;
                    int highY = (firstCoord.GetPosition().y < currentPoint.GetPosition().y) ? currentPoint.GetPosition().y : firstCoord.GetPosition().y;

                    bool canAdd = true;
                    for (int i = lowY + 1; i < highY; i++)
                    {
                        if (_coordsMatrix[x][i].isActivated())
                        {
                            canAdd = false;
                        }
                    }
                    if (canAdd)
                    {
                        newPoints.Add(firstCoord);
                        newPoints.Add(currentPoint);
                        currentPoint = firstCoord;
                    }
                }
                else if (currentPoint.GetPosition().y == firstCoord.GetPosition().y)
                {
                    int y     = currentPoint.GetPosition().y;
                    int lowX  = (firstCoord.GetPosition().x < currentPoint.GetPosition().x) ? firstCoord.GetPosition().x : currentPoint.GetPosition().x;
                    int highX = (firstCoord.GetPosition().x < currentPoint.GetPosition().x) ? currentPoint.GetPosition().x : firstCoord.GetPosition().x;

                    bool canAdd = true;
                    for (int j = lowX + 1; j < highX; j++)
                    {
                        if (_coordsMatrix[j][y].isActivated())
                        {
                            canAdd = false;
                        }
                    }
                    if (canAdd)
                    {
                        newPoints.Add(firstCoord);
                        newPoints.Add(currentPoint);
                        currentPoint = firstCoord;
                    }
                }
            }

            return(newPoints);
        }