Пример #1
0
 // active les nouvelles lignes
 void ActivateLine(GridCoord firstCoord, List <GridCoord> line)
 {
     foreach (GridCoord sndCoord in line)
     {
         //shiny line between 2 points
     }
 }
Пример #2
0
        //[Command]
        void Fire()
        {
            RaycastHit info;
            Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));

            if (Physics.Raycast(ray, out info, 100, layerMask))
            {
                GridCoord coord = info.collider.GetComponent <GridCoord>();
                if (coord)
                {
                    CmdSetCoord(coord.gameObject);
                    return;
                }
                GridController controller = info.collider.GetComponent <GridController>();
                if (controller)
                {
                    Debug.Log("gello");

                    gridManager.currentGrid = controller;
                    CmdResetGrid();
                    //gridManager.currentGrid.RpcReset();
                    return;
                }
            }
        }
Пример #3
0
        public void SetPositions(GridCoord coord1, GridCoord coord2)
        {
            _coords[0] = coord1;
            _coords[1] = coord2;

            _line.SetPosition(0, coord1.transform.position);
            _line.SetPosition(1, coord2.transform.position);
        }
Пример #4
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();
                    }
                }
            }
        }
Пример #5
0
        public void RpcSetPositions(GameObject firstCoord, GameObject sndCoord)
        {
            GridCoord coord1 = firstCoord.GetComponent <GridCoord>();
            GridCoord coord2 = sndCoord.GetComponent <GridCoord>();

            _coords[0] = coord1;
            _coords[1] = coord2;

            _line.SetPosition(0, coord1.transform.position);
            _line.SetPosition(1, coord2.transform.position);
        }
Пример #6
0
        public void RpcSetCoord(GameObject gridObj, GameObject currentClient)
        {
            Debug.Log("rpcSetCoord");
            localClient = currentClient.GetComponent <Character>();
            GridCoord coord = gridObj.GetComponent <GridCoord>();


            if (Good(coord))
            {
                List <GridCoord> newline = CheckLines(coord);
                ActivateCoord(coord, newline);
            }
        }
Пример #7
0
 public void RpcReset()
 {
     for (int i = 0; i < _coordsMatrix.Length; i++)
     {
         for (int j = 0; j < _coordsMatrix[i].Length; j++)
         {
             Debug.Log("ij:" + i + "," + j);
             _coordsMatrix[i][j].Reset();
         }
     }
     Debug.Log("RESET");
     currentPoint   = startPoint;
     startPointDone = false;
 }
Пример #8
0
        void InitGrid()
        {
            Debug.Log("length:" + _coordsArray.Length);
            _coordsMatrix = new GridCoord[(int)Mathf.Sqrt(_coordsArray.Length)][];
            for (int i = 0; i < _coordsMatrix.Length; i++)
            {
                _coordsMatrix[i] = new GridCoord[(int)Mathf.Sqrt(_coordsArray.Length)];
            }

            foreach (GridCoord coord in _coordsArray)
            {
                IntVector2 pos = coord.GetPosition();
                _coordsMatrix[pos.x][pos.y] = coord;
            }
        }
Пример #9
0
 void Ping(bool isPinging)
 {
     if (isPinging)
     {
         RaycastHit info;
         Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
         if (Physics.Raycast(ray, out info, 100, layerMask))
         {
             GridCoord coord = info.collider.GetComponent <GridCoord>();
             if (coord)
             {
                 CmdPing(coord.gameObject);
             }
         }
     }
     else
     {
         CmdDestroyFXPing();
     }
 }
Пример #10
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);
        }
Пример #11
0
        void Start()
        {
            currentPoint = startPoint;
            _lines       = new List <LineHandler>();

            for (int i = 0; i < _coordsArray.Length; i++)
            {
                _coordsArray[i] = null;
            }

            int j = 0;

            foreach (Transform child in transform)
            {
                if (child.tag == ("GridCoord"))
                {
                    _coordsArray[j] = child.GetComponent <GridCoord>();
                    j++;
                }
            }


            InitGrid();
        }
Пример #12
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);
        }
Пример #13
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);
        }