Example #1
0
        /// <summary>
        /// Configure and start bot client
        /// </summary>
        /// <returns></returns>
        public Startup ConfigureClient()
        {
#if DEBUG
            DiscordSocketConfig discordSocketConfig = new DiscordSocketConfig
            {
                ConnectionTimeout = 5000,
                DefaultRetryMode  = RetryMode.AlwaysRetry,
                HandlerTimeout    = 1000,
                LogLevel          = LogSeverity.Debug
            };

            CommandServiceConfig commandServiceConfig = new CommandServiceConfig
            {
                DefaultRunMode        = RunMode.Async,
                CaseSensitiveCommands = false,
                LogLevel = LogSeverity.Debug
            };
#else
            DiscordSocketConfig config = new DiscordSocketConfig
            {
                ConnectionTimeout = 1000,
                DefaultRetryMode  = RetryMode.AlwaysRetry,
                HandlerTimeout    = 1000,
                LogLevel          = LogSeverity.Info
            };

            CommandServiceConfig commandServiceConfig = new CommandServiceConfig
            {
                DefaultRunMode        = RunMode.Async,
                CaseSensitiveCommands = false,
                LogLevel = LogSeverity.Info
            };
#endif

            Bot             client          = new Bot(discordSocketConfig);
            CommandOperator commandOperator = new CommandOperator(client, commandServiceConfig);

            commandOperator.CommandExecuted += Dispatcher.Dispatch;
            commandOperator.Log             += Logger.Log;
            client.Log += Logger.Log;

            client.MessageReceived += commandOperator.OnClientMessageReceivedAsync;
            client.InitAsync(Configuration.Get("Bot:Token")).Wait();

            commandOperator.LoadModulesAsync().Wait();

            Container.Add(client);
            Container.Add(commandOperator);

            return(this);
        }
        /// <summary>
        /// Start Game logic
        /// </summary>
        public void Start()
        {
            // Initialize the two basic objects needed for user interactions
            this.InputProvider = this.inputProvider ?? new ConsoleInputProvider();
            this.OutputRenderer = this.outputRenderer ?? new ConsoleRenderer();

            // Render initial UI
            this.OutputRenderer.RenderWelcomeScreen(string.Join(string.Empty, RenderersConstants.GameTitle));
            this.OutputRenderer.RenderNewPlayerCreationRequest();

            // Create the active player
            var player = new Player(this.InputProvider.ReceiveInputLine());

            // Render console menu handler and execute logic for requesting board settings
            // TODO: Refactor menu handler logic
            int[] cursorPosition = this.OutputRenderer.GetCursor();
            var menuItems = new List<IGameMode>()
            {
                new BeginnerMode(),
                new IntermediateMode(),
                new ExpertMode()
            };

            var menuHandler = new ConsoleMenuHandler(this.inputProvider, this.outputRenderer, menuItems, cursorPosition[0] + 1, cursorPosition[1]);

            menuHandler.ShowSelections();

            BoardSettings boardSettings = menuHandler.RequestUserSelection();
            this.OutputRenderer.ClearScreen();
            this.OutputRenderer.SetCursor(visible: true);
            //// End of menu handler logic

            var board = new Board(boardSettings, new List<IBoardObserver>());
            var scoreboard = new Scoreboard();
            var contentFactory = new ContentFactory();
            var initializationStrategy = new StandardGameInitializationStrategy(contentFactory);
            var boardOperator = new CommandOperator(board, scoreboard);
            var engine = new StandardOnePlayerMinesweeperEngine(board, this.inputProvider, this.outputRenderer, boardOperator, scoreboard, player);

            engine.Initialize(initializationStrategy);
            board.Subscribe(engine);
            engine.Run();
        }
        /// <summary>
        /// Start Game logic
        /// </summary>
        public void Start(Grid root)
        {
            // Initialize the two basic objects needed for user interactions
            this.InputProvider = this.inputProvider ?? new WpfInputProvider();
            this.OutputRenderer = this.outputRenderer ?? new WpfRenderer(root);

            string testPlayerName = "John";

            // Create the active player
            var player = new Player(testPlayerName);

            BoardSettings testBoardSettings = new EasyBoardSettings();

            var board = new Board(testBoardSettings, new List<IBoardObserver>());
            var scoreboard = new Scoreboard();
            var contentFactory = new ContentFactory();
            var initializationStrategy = new StandardGameInitializationStrategy(contentFactory);
            var boardOperator = new CommandOperator(board, scoreboard);
            var engine = new StandardOnePlayerMinesweeperEngine(board, this.inputProvider, this.outputRenderer, boardOperator, scoreboard, player);

            engine.Initialize(initializationStrategy);
            board.Subscribe(engine);
            engine.Run();
        }