Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HangmanGame"/> class.
 /// Provides methods for running the game, ending the game and executing commands.
 /// </summary>
 public HangmanGame()
 {
     this.printer = new ConsolePrinter();
     this.context = new GameContext(SimpleRandomWordProvider.Instance, new Scoreboard(new ConsolePrinter(), new SelectionSorter(), new TextFileScoreboardDataManager<Dictionary<string, int>>()));
     this.commandFactory = new CommandFactory();
     this.gameSaver = new SaveLoadManager(this.printer, new XmlGameStateManager<SaveLoadManager>());
     this.commandExecutioner = new HangmanCommandInvoker();
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HangmanGame"/> class.
 /// Provides methods for running the game, ending the game and executing commands.
 /// </summary>
 /// <param name="printer">The object used to show messages.</param>
 /// <param name="sorter">The object used to sort scores.</param>
 /// <param name="scoresDataManager">The object from which scores are read and written in.</param>
 /// <param name="gameStateManager">The object used to save the current game state.</param>
 /// <param name="commandFactory">The object used to deal with commands needed.</param>
 /// <param name="commandExecutioner">The object used for the execution of commands.</param>
 /// <param name="wordProvider">The object that provides the word for the current game.</param>
 public HangmanGame(
     IPrinter printer,
     ISorter sorter,
     IDataManager<Dictionary<string, int>> scoresDataManager,
     IDataManager<SaveLoadManager> gameStateManager,
     CommandFactory commandFactory,
     ICommandInvoker commandExecutioner,
     IWordProvider wordProvider)
 {
     this.printer = printer;
     this.context = new GameContext(wordProvider, new Scoreboard(printer, sorter, scoresDataManager));
     this.commandFactory = new CommandFactory();
     this.gameSaver = new SaveLoadManager(this.printer, gameStateManager);
     this.commandExecutioner = new HangmanCommandInvoker();
 }
Пример #3
0
        /// <summary>
        /// Entry point of the game. 
        /// </summary>
        public static void Main()
        {
            var kernel = new StandardKernel();

            kernel.Bind<IPrinter>().To<ConsolePrinter>();
            kernel.Bind<IDataManager<Dictionary<string, int>>>().To<TextFileScoreboardDataManager<Dictionary<string, int>>>();
            kernel.Bind<IDataManager<SaveLoadManager>>().To<XmlGameStateManager<SaveLoadManager>>();
            kernel.Bind<ISorter>().To<SelectionSorter>();
            kernel.Bind<ICommandInvoker>().To<HangmanCommandInvoker>();

            var printer = kernel.Get<IPrinter>();
            var sorter = kernel.Get<ISorter>();
            var scoresDataManager = kernel.Get<IDataManager<Dictionary<string, int>>>();
            var gameStateManager = kernel.Get<IDataManager<SaveLoadManager>>();
            var commandFactory = new CommandFactory();
            var commandExecutioner = kernel.Get<ICommandInvoker>();
            var wordProvider = SimpleRandomWordProvider.Instance;

            var game = new HangmanGame(printer, sorter, scoresDataManager, gameStateManager, commandFactory, commandExecutioner, wordProvider);
            game.Run();
        }