protected override bool Initialize0(GameDifficulty difficulty, DiagnosticsReport diagnosticsReport) { // query hole states from physical interface int[] currentHoleStates = new int[HoleCount]; for (int i = 0; i < HoleCount; i++) { currentHoleStates[i] = Physical.GetHoleState(i); } scenario = DynamiteScenario.ChooseScenario(difficulty, wall, currentHoleStates); Log.Info("Dynamite scenario '{0}' selected.", scenario.Name); lastInstructionsSolvedState = new bool[scenario.InstructionCount]; for (int i = 0; i < lastHoleStates.Length; i++) { lastHoleStates[i] = -1; } for (int i = 0; i < TriggersGame.ButtonCount; i++) { Physical.SetLEDColor(i, Color.black); } return(true); }
protected override GameState Update0(float deltaTime) { // query hole states from physical interface int[] newHoleStates = new int[HoleCount]; for (int i = 0; i < HoleCount; i++) { newHoleStates[i] = Physical.GetHoleState(i); } // update hole states in solution checker bool[] instructionsSolved = wall.CheckSolution(scenario, newHoleStates); // compare old and new hole states to send notifications on changes for (int i = 0; i < HoleCount; i++) { if (newHoleStates[i] != lastHoleStates[i]) { if (lastHoleStates[i] == -1) // if there was no stick and now there is { Log.Verbose("Dynamite: Stick {0} has been inserted into hole {1}.", newHoleStates[i], i); OnStickInserted?.Invoke(this, new StickEventArgs(DynamiteStick.Sticks[newHoleStates[i]], i)); } if (newHoleStates[i] == -1) // if there was a stick and now there isn't { Log.Verbose("Dynamite: Stick {0} has been removed from hole {1}.", lastHoleStates[i], i); OnStickRemoved?.Invoke(this, new StickEventArgs(DynamiteStick.Sticks[lastHoleStates[i]], i)); } } lastHoleStates[i] = newHoleStates[i]; } for (int i = 0; i < lastInstructionsSolvedState.Length; i++) { if (lastInstructionsSolvedState[i] != instructionsSolved[i]) { Log.Verbose("Dynamite: Instruction {0} has been {1}.", i, instructionsSolved[i] ? "solved" : "unsolved"); OnInstructionSolvedStateChanged?.Invoke(this, new InstructionSolvedStateChangedArgs(i, instructionsSolved[i])); } lastInstructionsSolvedState[i] = instructionsSolved[i]; } if (instructionsSolved.Contains(false)) { return(GameState.Running); } return(GameState.Completed); }