Example #1
0
    public void Start()
    {
        //setup game status, when it get changes
        gameStatus.Subscribe(status =>
        {
            print("Game status: " + status.ToString());
            btnRestart.gameObject.SetActive(status != GameStatus.InProgress);
        })
        .AddTo(gameObject);

        //setup button restart
        btnRestart.OnClickAsObservable()
        .Subscribe(unit =>
        {
            SceneManager.LoadScene(0);     //restart the game
        })
        .AddTo(gameObject);

        //setup the layout
        gridLayout.constraint      = GridLayoutGroup.Constraint.FixedColumnCount;
        gridLayout.constraintCount = gameSetting.Width;

        //build the board
        gameBoard.Build();

        //create cells
        foreach (var data in cellData)
        {
            var cell = cellFactory.Create();
            cell.SetParent(container);
            cell.SetCellData(data);
            cells.Add(cell);
        }

        //solve the game
        Observable.FromCoroutine(_ => gameSolver.Solve(1f)).Subscribe(_ => { print("Finished"); })
        .AddTo(this);
    }