private void DisplayGridToggle() { GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); showGrid = EditorGUILayout.Toggle("Grid", showGrid); if (EditorGUI.EndChangeCheck()) { GameObject grid = GameObject.FindWithTag("Grid"); GridListener gridListener = grid.GetComponent <GridListener>(); gridListener.IsGridVisible(showGrid); } GUILayout.EndHorizontal(); }
public void LoadGameInstance(Game g) { if (g != null) { State = GameState.PAUSE; // Saving all the listeners during the copy of the new instance GridListener gl = SudokuGrid.ActionOnGrid; SudokuGrid = g.SudokuGrid; Solution = g.Solution; if (g.SudokuStopwatch != null) { /*Action onStopwatchActiveStateChange = SudokuStopwatch.OnActiveStateChange; * Action onStopwatchSecondChange = SudokuStopwatch.OnSecondChange; * Action onStopwatchMinuteChange = SudokuStopwatch.OnMinuteChange; * Action onStopwatchHourChange = SudokuStopwatch.OnHourChange; * * SudokuStopwatch = new StopwatchEngine.Stopwatch(onStopwatchActiveStateChange, * onStopwatchSecondChange, onStopwatchMinuteChange, onStopwatchHourChange);*/ SudokuStopwatch.Second = g.SudokuStopwatch.Second; SudokuStopwatch.Second = g.SudokuStopwatch.Minute; SudokuStopwatch.Second = g.SudokuStopwatch.Hour; } else { SudokuStopwatch.Second = 0; SudokuStopwatch.Second = 0; SudokuStopwatch.Second = 0; } // Applying again the listener on the new instance SudokuGrid.ActionOnGrid = gl; // Finally, changing the game state State = g.State; } }
/// <summary> /// Construct a game instance by initilizing the grid (with <paramref name="gl"/>), the variables <c>ColumnProduct</c>, /// <c>ColumnSum</c>, <c>RowProduct</c> and <c>RowSum</c>. This constructor do not compute any grid (you must call <c>ComputeGrid</c> method). /// </summary> /// <param name="gl"></param> public Game(GridListener gl = null, Action OnSecondChange = null, ActionOnGameState OnGameStateChange = null) { this.OnGameStateChange = OnGameStateChange != null ? OnGameStateChange : new ActionOnGameState((oldState, newState) => { }); State = GameState.PAUSE; SudokuGrid = new Grid(new GridListener( (x, y, value) => { gl?.ActionOnGridChange?.Invoke(x, y, value); this.CheckWin(); })); // The constructor init the grid Solution = new Grid(); InitConst(); if (OnSecondChange == null) { SudokuStopwatch = new StopwatchEngine.Stopwatch(() => { }, () => { }); } else { SudokuStopwatch = new StopwatchEngine.Stopwatch(() => { }, () => { OnSecondChange(); }); } }