/// <summary> /// Shows the free play screen. /// </summary> private void ShowFreePlayScreen() { if (this.freePlayState == null) { int width = 0; int height = 0; int x = 0; int y = 0; List <int[]> crates = new List <int[]>(); List <int[]> targets = new List <int[]>(); char[,] gameMap = this.LoadMap(ref x, ref y, ref width, ref height, ref crates, ref targets); this.freePlayState = new SokobanFreePlayer(gameMap, new int[2] { width, height }, new int[2] { x, y }, crates, targets); } this.freePlayState.RenderMapState(); }
/// <summary> /// Processes the user input. /// </summary> /// <param name="action">The action.</param> public void ProcessUserInput(MenuActions action) { // Some Menus need to lock some actions. This is only pertinent in the menu system. if (this.bannedActionsList.Contains(action)) { return; } this.bannedActionsList.Clear(); switch (action) { case MenuActions.Up: if (this.freePlay) { this.freePlayState.MovePlayer(AlgorithmConstants.Move.U); } else { this.currentOption = this.currentOption == 0 ? 0 : this.currentOption - 1; } this.DisplayCurrentView(); break; case MenuActions.Down: if (this.freePlay) { this.freePlayState.MovePlayer(AlgorithmConstants.Move.D); } else { this.currentOption = this.currentOption == this.totalOptions - 1 ? this.totalOptions - 1 : this.currentOption + 1; } this.DisplayCurrentView(); break; case MenuActions.Left: if (this.freePlay) { this.freePlayState.MovePlayer(AlgorithmConstants.Move.L); this.DisplayCurrentView(); } break; case MenuActions.Right: if (this.freePlay) { this.freePlayState.MovePlayer(AlgorithmConstants.Move.R); this.DisplayCurrentView(); } break; case MenuActions.Cancel: if (this.freePlay) { this.freePlayState.ResetGame(); this.DisplayCurrentView(); } break; case MenuActions.Back: if (this.freePlay) { this.freePlay = false; this.freePlayState = null; this.menuHistory = new List <Menus>() { Menus.PuzzleSelection }; this.currentMenu = Menus.PuzzleSelection; this.DisplayCurrentView(); } break; case MenuActions.Enter: this.SelectMenuOption(); break; case MenuActions.Optimization: OptimizationService.Instance.Optimize = !OptimizationService.Instance.Optimize; this.DisplayCurrentView(); Console.WriteLine("Optimization has been " + (OptimizationService.Instance.Optimize ? "Enabled." : "Disabled.")); break; } }