Esempio n. 1
0
        /// <summary>
        /// Method that start the main logic of the game.
        /// </summary>
        /// <param name="output">Output renderer</param>
        /// <param name="input">Iput provider</param>
        /// <param name="cmmandLogger">Command logger</param>
        public static void Start(IRenderer output, IInputProvider input, ILogger cmmandLogger)
        {
            output.ShowInfoMessage("Please ente your name: ");
            string playerName = input.GetPlayerName();

            output.ShowInfoMessage("Please enter a dimension for the board the standard is 9x9");
            int dimension = input.GetPlayFieldDimensions();

            ICell      playerCell = new Cell(new Position(dimension / 2, dimension / 2));
            IPlayField playField  = null;
            var        player     = new Player.Player(playerName, playerCell);

            try
            {
                var playFieldGenerator = new StandardPlayFieldGenerator(player.CurentCell.Position, dimension, dimension);
                playField = new PlayField.PlayField(playFieldGenerator, player.CurentCell.Position, dimension, dimension);
            }
            catch (ArgumentOutOfRangeException e)
            {
                output.ShowInfoMessage(e.Message);
            }

            ICommandFactory   commandFactory = new SimpleCommandFactory();
            IMementoCaretaker memory         = new MementoCaretaker(new List <IMemento>());
            IScoreLadder      ladder         = ScoreLadder.Instance;
            IGameEngine       gameEngine     = new StandardGameEngine(output, input, playField, commandFactory, cmmandLogger, player, memory, ladder);

            gameEngine.Initialize(RandomNumberGenerator.Instance);
            gameEngine.Start();
        }
Esempio n. 2
0
 public void SetUp()
 {
     _urlHolder   = new UrlHolder();
     _caretaker   = new MementoCaretaker <UrlHolderMemento>();
     _exampleDate = DateTime.Now;
     _exampleUrl  = "http://test.pl";
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            MementoCaretaker mc    = new MementoCaretaker();
            Chessman         chess = new Chessman("车", 1, 1);

            Display(chess);

            // 保存状态
            mc.Memento = chess.Save();
            chess.Y    = 4;
            Display(chess);

            // 保存状态
            mc.Memento = chess.Save();
            Display(chess);
            chess.X = 5;
            Display(chess);


            Console.WriteLine("---------- Sorry,俺悔棋了 ---------");

            // 恢复状态
            chess.Restore(mc.Memento);
            Display(chess);

            Console.ReadKey();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Game game = new Game();

            game.AddPlayer("Andreas", "Vind", 18, 3);
            game.AddPlayer("Jens", "Støt Andreas", 27, 7);
            game.AddPlayer("Joachim", "Slå", 23, 5);
            Console.WriteLine("Spil efter oprettelse.");
            game.PrintPlayers();
            MementoCaretaker mementoCaretaker = new MementoCaretaker();

            mementoCaretaker.AddMemento(game.Save());
            Console.WriteLine("Der gemmes en memento, så vi kan gå tilbage til dette stadie");
            Console.WriteLine("Nu ændres spilleren Jens");
            game.AlterTroops(2, -5);
            Console.WriteLine("Nu er tropper for jens ændret og der ser sådan her ud:");
            game.PrintPlayers();
            mementoCaretaker.AddMemento(game.Save());
            Console.WriteLine("Nu laves en memento til denne del.");
            Console.WriteLine("Nu kaldes den første memento tilbage.");
            game.RestoreState(mementoCaretaker.GetMementoAtIndex(0));
            Console.WriteLine("Nu er vi tilbage fra starten, og vi printer nu spillets data igen.");
            game.PrintPlayers();
        }
Esempio n. 5
0
        public void TestUrlHolderMementoCreateFromFile()
        {
            //arrange
            var caretakerWithFile = new MementoCaretaker <UrlHolderMemento>();

            //act
            _urlHolder.Put(_exampleUrl, _exampleDate);
            _caretaker.Memento        = _urlHolder.CreateMemento();
            caretakerWithFile.Memento = new UrlHolderMemento(UrlHolderMemento.ExportFileName);

            //assert
            Assert.AreEqual(_caretaker.Memento.UrlsWithDates.Count,
                            caretakerWithFile.Memento.UrlsWithDates.Count);
            Assert.AreEqual(_caretaker.Memento.UrlsWithDates[_exampleUrl],
                            caretakerWithFile.Memento.UrlsWithDates[_exampleUrl]);
        }
Esempio n. 6
0
        public void TestScoreCommandCorrect()
        {
            IPlayFieldGenerator pg      = new PlayFieldGenerator();
            IPlayField          playFld = new PlayField(pg, new Position(1, 1), 3, 3);

            playFld.InitializePlayFieldCells(RandomNumberGenerator.Instance);
            Mock <IRenderer>    mockRenderer   = new Mock <IRenderer>();
            IMementoCaretaker   mockMemento    = new MementoCaretaker(new List <IMemento>());
            Mock <IScoreLadder> mockScoreLader = new Mock <IScoreLadder>();
            IPlayer             player         = new Player("Test", new Cell(new Position(1, 1), Constants.StandardGamePlayerChar));

            ICommandContext cmdContext = new CommandContext(playFld, mockRenderer.Object, mockMemento, mockScoreLader.Object, player);

            ICommandFactory factory = new SimpleCommandFactory();
            ICommand        command = factory.CreateCommand("top");

            command.Execute(cmdContext);

            mockRenderer.Verify(x => x.ShowScoreLadder(It.IsAny <IScoreLadderContentProvider>()), Times.Once);
        }
        public Test()
        {
            InitializeComponent();
            switch (LanguageSetting)
            {
            case 0:
                QuestionIterator = new QuestionTestIterator(questions, new English());
                break;

            case 1:
                QuestionIterator = new QuestionTestIterator(questions, new Polish());
                break;
            }

            MementoCaretaker = new MementoCaretaker(QuestionIterator);

            QuestionGrid.Children.Add(QuestionIterator.GetGrid());

            TestProgressBar.Maximum = 44; //4 poziomy trudności po 11 pytań
        }
Esempio n. 8
0
        public void TestMoveRightCommandCorrect()
        {
            IPlayFieldGenerator pg      = new PlayFieldGenerator();
            IPlayField          playFld = new PlayField(pg, new Position(1, 1), 3, 3);

            playFld.InitializePlayFieldCells(RandomNumberGenerator.Instance);
            Mock <IRenderer>    mockRenderer   = new Mock <IRenderer>();
            IMementoCaretaker   mockMemento    = new MementoCaretaker(new List <IMemento>());
            Mock <IScoreLadder> mockScoreLader = new Mock <IScoreLadder>();
            IPlayer             player         = new Player("Test", new Cell(new Position(1, 1), Constants.StandardGamePlayerChar));

            ICommandContext cmdContext = new CommandContext(playFld, mockRenderer.Object, mockMemento, mockScoreLader.Object, player);

            ICommandFactory factory = new SimpleCommandFactory();
            ICommand        command = factory.CreateCommand("r");

            command.Execute(cmdContext);

            Assert.AreEqual(1, player.CurentCell.Position.Row);
            Assert.AreEqual(2, player.CurentCell.Position.Column);
        }
Esempio n. 9
0
        public static void SingleRedoDemo()
        {
            MementoCaretaker mc    = new MementoCaretaker();
            Chessman         chess = new Chessman("车", 1, 1);

            Display(chess);
            // 保存状态
            mc.Memento = chess.Save();
            chess.Y    = 4;
            Display(chess);
            // 保存状态
            mc.Memento = chess.Save();
            Display(chess);
            chess.X = 5;
            Display(chess);

            Console.WriteLine("---------- Sorry,俺悔棋了 ---------");

            // 恢复状态
            chess.Restore(mc.Memento);
            Display(chess);
        }
Esempio n. 10
0
        public Study()
        {
            InitializeComponent();
            switch (LanguageSetting)
            {
            case 0:
                QuestionIterator = new QuestionStudyIterator(questions, new English());
                StudyPageEnglish = this;
                break;

            case 1:
                QuestionIterator = new QuestionStudyIterator(questions, new Polish());
                StudyPagePolish  = this;
                break;
            }

            MementoCaretaker = new MementoCaretaker(QuestionIterator);



            QuestionGrid.Children.Add(QuestionIterator.GetGrid());
        }
 public UndoAll(MementoCaretaker mementoCaretaker)
 {
     this.mementoCaretaker = mementoCaretaker;
 }
Esempio n. 12
0
 public UndoSingle(MementoCaretaker mementoCaretaker)
 {
     this.mementoCaretaker = mementoCaretaker;
 }