Example #1
0
 public ConsoleMenu(
     int minBoardWidth,
     int minBoardHeight,
     int maxBoardWidth,
     int maxBoardHeight,
     Func <List <string> > loadDbSession
     ) : base(
         minBoardWidth,
         minBoardHeight,
         maxBoardWidth,
         maxBoardHeight,
         loadDbSession
         )
 {
     Menu.AddMenuItem(new MenuItem("Start Game", "Starts game", onSelectedCallback: StartGame));
     Menu.AddMenuItem(new MenuItem("Save game", "Save game to json", onSelectedCallback: SaveGame));
     LoadGameItem = new MenuItem("Load game", "Load game from file", onSelectedCallback: LoadGameSelected);
     Menu.AddMenuItem(LoadGameItem);
     SetSizeItem = new MenuItem($"Set board size [{BoardWidth} x {BoardHeight}]",
                                $"Set width and height of the board. Currently {BoardWidth} x {BoardHeight}");
     BoardWidthItem = new MenuItem($"Set width [{BoardWidth}]",
                                   $"Sets the width of board. Currently {BoardWidth}", onSelectedCallback: SetBoardWidth);
     BoardHeightIem = new MenuItem($"Set height [{BoardHeight}]",
                                   $"Sets height of board. Currently {BoardHeight}", onSelectedCallback: SetBoardHeight);
     SetSizeItem.AddChildItem(BoardWidthItem);
     SetSizeItem.AddChildItem(BoardHeightIem);
     Menu.AddMenuItem(SetSizeItem);
     TouchModeItem = new MenuItem($"Set touch mode [{Configuration.TouchMode.ToString()}]",
                                  "Set whether ships can touch or not");
     TouchModeItem.AddChildItem(new MenuItem(TouchMode.NoTouch.ToString(), "Boats cannot touch each other",
                                             onSelectedCallback: () => SetTouchMode(TouchMode.NoTouch)));
     TouchModeItem.AddChildItem(new MenuItem(TouchMode.CornersTouch.ToString(),
                                             "Boats can touch each other with corners",
                                             onSelectedCallback: () => SetTouchMode(TouchMode.CornersTouch)));
     TouchModeItem.AddChildItem(new MenuItem(TouchMode.AllTouch.ToString(), "Boats can touch each other",
                                             onSelectedCallback: () => SetTouchMode(TouchMode.AllTouch)));
     Menu.AddMenuItem(TouchModeItem);
     ShipCountItem = new MenuItem("Set ship counts", "Set amount of each ship for game");
     ShipCountItem.OnHoverCallback = GenerateShipCounts;
     Menu.AddMenuItem(ShipCountItem);
     BackToBackMovesOnHitItem =
         new MenuItem($"Toggle new move on hit [{(Configuration.BackToBackMovesOnHit ? "YES" : "NO")}]",
                      "Toggle if you get new move upon hitting enemy ship", onSelectedCallback: OnToggleBackToBackMoves);
     Menu.AddMenuItem(BackToBackMovesOnHitItem);
     Menu.AddMenuItem(new MenuItem("Exit", "Exit the application", onSelectedCallback: Exit));
     Menu.RecalculateSpacings();
 }