Esempio n. 1
0
    public void checkAllPieces()
    {
        HELPER.ITEMS[,] itemsNeedToDestroy = new HELPER.ITEMS[matrixServer.GetLength(0), matrixServer.GetLength(1)];
        for (int i = 0; i < matrixServer.GetLength(0); i++)
        {
            for (int j = 0; j < matrixServer.GetLength(1); j++)
            {
                if (!matrixServer[i, j].Equals(HELPER.ITEMS.NULL))
                {
                    List <int[]> result = checkMuch(i, j, matrixServer[i, j]);

                    if (result.Count != 0)
                    {
                        foreach (int[] item in result)
                        {
                            int[] pos = item;
                            matrixServer[pos[0], pos[1]] = HELPER.ITEMS.NULL;
                            print("X = " + item[0] + " Y = " + item[1]);
                        }
                    }
                }
            }
        }
        proxy.reaction_answer(matrixServer);

        // updateMatrix(matrixServer);//
    }
Esempio n. 2
0
    public void updateMatrix(HELPER.ITEMS[,] matrix)
    {
        HELPER.ITEMS[,] addedMatrix = new HELPER.ITEMS[matrix.GetLength(0), matrix.GetLength(1)];

        Array values = Enum.GetValues(typeof(HELPER.ITEMS));

        System.Random random = new System.Random();


        for (int i = 0; i < matrix.GetLength(0); i++)
        {
            for (int j = 0; j < matrix.GetLength(1); j++)
            {
                if (matrix[i, j].Equals(HELPER.ITEMS.NULL))
                {
                    HELPER.ITEMS randomItem = (HELPER.ITEMS)values.GetValue(random.Next(values.Length - 1));
                    addedMatrix[i, j]  = randomItem;
                    matrixServer[i, j] = randomItem;
                }
                else
                {
                    addedMatrix[i, j] = HELPER.ITEMS.NULL;
                }
            }
        }
        proxy.sendMatrixToClient(addedMatrix);
    }
Esempio n. 3
0
    private List <int[]> checkMuch(int x, int y, HELPER.ITEMS type)
    {
        List <int[]> results           = new List <int[]>();
        List <int[]> horisontalResults = checkHorisontal(x, y, type);
        List <int[]> verticalResults   = checkVertical(x, y, type);

        int[] pos = new int[2];

        if (horisontalResults.Count > 1)
        {
            results.AddRange(horisontalResults);
        }

        if (verticalResults.Count > 1)
        {
            results.AddRange(verticalResults);
        }

        if (results.Count > 1)
        {
            pos[0] = x;
            pos[1] = y;
            results.Add(pos);
        }

        return(results);
    }
Esempio n. 4
0
    public void init(int initX, int initY, HELPER.ITEMS type, DinamicGrid newGridRef)
    {
        _x       = initX;
        _y       = initY;
        _type    = type;
        _gridRef = newGridRef;

        _moveComponent = GetComponent <MovablePiece>();
    }
Esempio n. 5
0
 public void swap2Pieces(int x1, int y1, int x2, int y2)
 {
     if (isAdjacent(x1, y1, x2, y2))
     {
         HELPER.ITEMS temp = matrixServer[x1, y1];
         matrixServer[x1, y1] = matrixServer[x2, y2];
         matrixServer[x2, y2] = temp;
         proxy.sentAnswerToSwap(x1, y1, x2, y2);
     }
 }
Esempio n. 6
0
 private Sprite getPieceView(HELPER.ITEMS type)
 {
     foreach (PiecePrefab item in piecePrefabArray)
     {
         if (item.type == type)
         {
             return(item.sprite);
         }
     }
     return(null);
 }
Esempio n. 7
0
    private BasePiece createGamePiece(int x, int y, HELPER.ITEMS type, int outSide = 0)
    {
        GameObject newPiece = Instantiate(_piecePrefabsDict[type], getGridPosition(x, y + outSide), Quaternion.identity);

        newPiece.name = "Piece(" + x + "," + y + ")";
        newPiece.GetComponent <SpriteRenderer>().sprite = getPieceView(type);
        newPiece.transform.parent = grid;

        _pieces[x, y] = newPiece.GetComponent <BasePiece>();
        _pieces[x, y].init(x, y, type, this as DinamicGrid);
        return(_pieces[x, y]);
    }
Esempio n. 8
0
    public void initMatrix()
    {
        Array values = Enum.GetValues(typeof(HELPER.ITEMS));

        System.Random random = new System.Random();

        for (int i = 0; i < matrixServer.GetLength(0); i++)
        {
            for (int j = 0; j < matrixServer.GetLength(1); j++)
            {
                HELPER.ITEMS randomItem = (HELPER.ITEMS)values.GetValue(random.Next(values.Length - 1));
                matrixServer[i, j] = randomItem;
            }
        }

        proxy.sendStartMatrixToClient(matrixServer);
    }
Esempio n. 9
0
 public HELPER.ITEMS[,] repotToServer(BasePiece[,] piece)
 {
     HELPER.ITEMS[,] mesMatrix = new HELPER.ITEMS[piece.GetLength(0), piece.GetLength(1)];
     for (int i = 0; i < mesMatrix.GetLength(0); i++)
     {
         for (int j = 0; j < mesMatrix.GetLength(1); j++)
         {
             if (piece[i, j] == null)
             {
                 mesMatrix[i, j] = HELPER.ITEMS.NULL;
             }
             else
             {
                 mesMatrix[i, j] = piece[i, j]._type;
             }
         }
     }
     return(mesMatrix);
 }
Esempio n. 10
0
    private List <int[]> checkVertical(int x, int y, HELPER.ITEMS type)
    {
        List <int[]> result = new List <int[]>();



        for (int j = (y + 1); j < matrixServer.GetLength(1); j++)
        {
            if (!matrixServer[x, j].Equals(HELPER.ITEMS.NULL) && matrixServer[x, j].Equals(type))
            {
                int[] pos = new int[2];
                pos[0] = x;
                pos[1] = j;
                result.Add(pos);
            }
            else
            {
                break;
            }
        }

        for (int j = (y - 1); j >= 0; j--)
        {
            if (!matrixServer[x, j].Equals(HELPER.ITEMS.NULL) && matrixServer[x, j].Equals(type))
            {
                int[] pos = new int[2];
                pos[0] = x;
                pos[1] = j;
                result.Add(pos);
            }
            else
            {
                break;
            }
        }

        return(result);
    }
Esempio n. 11
0
    private List <int[]> checkHorisontal(int x, int y, HELPER.ITEMS type)
    {
        List <int[]> result = new List <int[]>();


        for (int i = x + 1; i < matrixServer.GetLength(0); i++)
        {
            if (!matrixServer[i, y].Equals(HELPER.ITEMS.NULL) && matrixServer[i, y].Equals(type))
            {
                int[] pos = new int[2];
                pos[1] = y;
                pos[0] = i;
                result.Add(pos);
            }
            else
            {
                break;
            }
        }

        for (int i = x - 1; i >= 0; i--)
        {
            if (!matrixServer[i, y].Equals(HELPER.ITEMS.NULL) && matrixServer[i, y].Equals(type))
            {
                int[] pos = new int[2];
                pos[1] = y;
                pos[0] = i;
                result.Add(pos);
            }
            else
            {
                break;
            }
        }

        return(result);
    }