예제 #1
0
        public List <Movable> GetDiogonalsPair(GameObject[,] allObjects)
        {
            List <Movable> fruits = new List <Movable>();

            for (int i = allObjects.GetLength(0) - 1; i > 0; i--)
            {
                for (int j = 0; j < allObjects.GetLength(1); j++)
                {
                    Movable _movable = allObjects[i, j].GetComponent <Movable>();
                    if (_movable != null && allObjects[i, j].GetComponent <Empty>() == null)
                    {
                        if (allObjects[i - 1, j].GetComponent <Empty>() != null)
                        {
                            return(null);
                        }
                        Empty _empty = _movable.GetEmptyNeighboor(new Vector2Int(1, -1), allObjects);
                        if (_movable.GetObjectNeighboor(Vector2Int.right, allObjects) == null && _empty != null)
                        {
                            fruits.Add(_movable);
                            fruits.Add(_empty.GetComponent <Movable>());
                            return(fruits);
                        }
                        _empty = _movable.GetEmptyNeighboor(new Vector2Int(-1, -1), allObjects);
                        if (_movable.GetObjectNeighboor(Vector2Int.left, allObjects) == null && _empty != null)
                        {
                            fruits.Add(_movable);
                            fruits.Add(_empty.GetComponent <Movable>());
                            return(fruits);
                        }
                    }
                }
            }
            return(null);
        }
예제 #2
0
파일: Game.cs 프로젝트: tsur/tictactoe
    void InitBoard()
    {
        board = new Cell[9];
        for (int i = 0; i < 9; i++)
        {
            board[i] = Cell.EMPTY;
        }

        for (int i = 0; i < cellsGameObjects.Length; i++)
        {
            if (cellsGameObjects[i])
            {
                cellsGameObjects[i].GetComponent <SpriteRenderer>().sprite = Empty.GetComponent <SpriteRenderer>().sprite;
            }
            //if (cellsGameObjects[i]) Instantiate(Empty, cellsGameObjects[i].transform.position, Quaternion.identity);
        }
    }
예제 #3
0
 private void FallingDown()
 {
     for (int j = 0; j < _allObjects.GetLength(1); j++)
     {
         Empty lastEmpty = finder.GetLastEmpty(j, _allObjects);
         if (lastEmpty == null)
         {
             List <Movable> pairs = finder.GetDiogonalsPair(_allObjects);
             if (pairs != null)
             {
                 ChangeFruits(pairs[0], pairs[1], true);
                 j = -1;
             }
             continue;
         }
         Movable lastMovable = finder.GetLastMovable(j, _allObjects);
         if (lastMovable != null)
         {
             ChangeFruits(lastMovable, lastEmpty.GetComponent <Movable>(), true);
             j = -1;
         }
     }
     EventHolder.startAnimation.Invoke(moveSpeed);
 }