/// <summary> /// Entry point to create a new level /// </summary> public void Init(int level, float animationSpeed = 1f, float delayScale = 1f, bool restart = false) { if (level < 0 || level > _puzzleSpawner.LevelCount) { Debug.LogWarning("Requested level is outside of bounds, ignoring request"); return; } // Destroy the previous level _puzzleSpawner.DestroyBoard(); _saveState.Started = true; // Spawn the new level _puzzle = _puzzleSpawner.SpawnBoard(level, animationSpeed, delayScale, restart); _playerState = _puzzle.PlayerState; CurrentLevel = level; // Reset the puzzle view state _arcMap.Reset(_puzzleSpawner.ArcMap); _fieldMap.Reset(_puzzleSpawner.FieldMap); _nodeMap = _puzzleSpawner.NodeMap; // Init all scripts that require additional information on startup _boardAction.Init(); _puzzleView.Init(_puzzle.StartNode.Position, _puzzle.BoardSize); _boardInput.Init(_puzzleSpawner.NodeMap); gameObject.name = $"PuzzleGame ({level})*"; TimeElapsed += Metadata.TimeElapsed; // Start with a pulled node if defined if (Metadata.StartPull == Direction.None) { return; } var startNode = _nodeMap[_puzzle.StartNode.Position]; Play(startNode, Metadata.StartPull); _puzzleView.Rotate(startNode, PulledArcView, Metadata.StartPull, true); _boardAction.HighlightAll(); LevelStateChanged?.Invoke(LevelState(), _puzzle.Win); }
public bool Play(NodeView nodeView, Direction dir) { // Push move if (IsPulled) { FieldView fieldView; var pushMove = _fieldMap.TryGetField(nodeView.Position, dir, out fieldView) && PushArc(nodeView, fieldView); if (!pushMove) { return(false); } PushNodePath = _playerState.PushPath(_lastNodePulled.Node, nodeView.Node) .Select(node => _nodeMap[node.Position]) .ToList(); LevelStateChanged?.Invoke(LevelState(), _puzzle.Win); return(true); } // Pull move ArcView arcView; var pullMove = _arcMap.TryGetArc(nodeView.Position, dir.Opposite(), out arcView) && PullArc(arcView, dir); _lastNodePulled = nodeView; if (pullMove) { LevelStateChanged?.Invoke(LevelState(), _puzzle.Win); } return(pullMove); }
/// <summary> /// Change the current level state /// </summary> /// <param name="state"></param> protected virtual void ChangeLevelState(LevelState newState) { if (CurrentLevelState == newState) { return; } LevelState oldState = CurrentLevelState; CurrentLevelState = newState; LevelStateChanged?.Invoke(oldState, newState); switch (newState) { case LevelState.Complete: LevelStats.time = LevelTime - TimeLeft; LevelComplete?.Invoke(); break; case LevelState.Failed: LevelFailed?.Invoke(); break; } }
private static void OnLevelStateChanged(Level.GameState gameState) { LevelStateChanged?.Invoke(CurrentLevel, gameState); }
protected void RaiseStateChangedEvent(State newState) { stateChangedEventParams.State = newState; LevelStateChanged?.Invoke(this, stateChangedEventParams); }