Exemple #1
0
    public void InitializeViewData(GameRenderData data)
    {
        _resultsContainer.gameObject.SetActive(false);
        _resultsContainer.InitializeViewData(data.OnGetToMenu);

        _gridSize  = data.GridSize;
        _piecePool = data.GridList;

        for (int i = 0; i < _gridSize.x; i++)
        {
            List <CellView> cells = new List <CellView>();
            for (int j = 0; j < _gridSize.y; j++)
            {
                GameObject pieceGO = _gridPieces.gameObject.AddChild(_piecePrefab);
                pieceGO.transform.localScale = Vector3.one;
                PieceView piece   = pieceGO.GetComponent <PieceView>();
                PieceDO   pieceDo = data.GridList[i][j];

                if (piece != null)
                {
                    piece.Initialize(pieceDo);
                    piece.transform.localPosition = new Vector3(PIECE_WIDTH * i - _offsetX, PIECE_HEIGHT * j - _offsetY);
                }

                GameObject cellGO = _gridCells.gameObject.AddChild(_cellPrefab);
                cellGO.transform.localScale    = Vector3.one;
                cellGO.transform.localPosition = piece.transform.localPosition;
                cellGO.name = String.Format("cell {0}/{1}", i, j);
                CellView cell = cellGO.GetComponent <CellView>();
                cell.Piece = piece;
                cell.Initialize(data.SelectCell);
                cells.Add(cell);
            }
            _cells.Add(cells);
        }
        SetNeighbors();

        _piecePrefab.SetActive(false);
        _cellPrefab.SetActive(false);

        _currentScore = 0;
        _scoreCounter = new NguiLabelCounterInt(_scoreLabel);
        _scoreCounter.SetInitialCounterValue(_currentScore);

        _currentDiamondScore      = 0;
        _diamondProgressBar.value = 0;
        _addDiamondPiece          = data.AddDiamondPiece;
    }
    private void LoadResources()
    {
        _viewProvider.Get <GameView>(view =>
        {
            _gameView = view;

            var data = new GameRenderData();

            data.OnGetToMenu = OnGetToMenu;
            data.GridSize    = new Vector2(_config.GetGridWidth(), _config.GetGridHeight());

            while (true)
            {
                var grid = new List <List <PieceDO> >();

                for (var i = 0; i < _config.GetGridWidth(); i++)
                {
                    var col = new List <PieceDO>();

                    for (var j = 0; j < _config.GetGridHeight(); j++)
                    {
                        col.Add(CreatePiece(i, j));
                    }
                    grid.Add(col);
                }

                _grid = grid;

                break;
            }

            data.SelectCell      = OnSelectCell;
            data.AddDiamondPiece = AddDiamondPiece;
            data.GridList        = _grid;

            _gameView.InitializeViewData(data);

            CheckForMatches();

            _gameView.SetViewActive(true);

            ResourcesLoaded();
        });

        _networkSystem.OnDisconnect        += OnDisconnect;
        _networkSystem.OnConnectionSuccess += OnReconnect;
    }
    public override void Init()
    {
        _gameService = _serviceProvider.Get <GameService>();
        _menuService = _serviceProvider.Get <MenuService>();
        _gameService.Reset();
        _viewProvider.Get <GameView>(view =>
        {
            _gameView = view;

            GameRenderData renderData = new GameRenderData();
            renderData.GameService    = _gameService;
            renderData.GameFinished   = OnGameFinished;

            _gameView.gameObject.SetActive(true);
            _gameView.Init(renderData);
        });
    }
Exemple #4
0
 public void Init(GameRenderData renderData)
 {
     _renderData = renderData;
     InitPool();
     StartGame();
 }