示例#1
0
        public void TestIfBombWithSizeFiveExplodesAsExpectedWhenTheBombIsNearTheBottompLeftFieldCorner()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();
            Playfield testField = Playfield.Instance;
            testField.SetFieldSize(6);
            testField.InitializeEmptyField();
            testField[1, 5] = new BombCell(5);

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            enginePrivateInstance.Invoke("HandleExplosion", testField[1, 5]);
            Playfield engineField = (Playfield)enginePrivateInstance.GetFieldOrProperty("playField");
            BombCell bomb = new BombCell(5);
            bomb.X = 4;
            bomb.Y = 4;
            engineField[1, 5] = bomb;

            enginePrivateInstance.Invoke("ChangeCurrentCell", 1, 5);
            enginePrivateInstance.Invoke("HandleExplosion", engineField[1, 5]);

            Assert.AreEqual(engineField[2, 5].CellType == CellType.BlownCell, true, "Expected that the cell on coordinates 2,5 is CellType.BlownCell. Received {0} ", engineField.ToString());
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Renderer" /> class.
        /// </summary>
        /// <param name="engine">The engine object to be attached to this object instance.</param>
        protected Renderer(Engine engine)
        {
            if (engine == null)
            {
                throw new ArgumentNullException("Null Engine provided.");
            }

            if (engine.PlayField != null)
            {
                this.engine = engine;
                this.cellViews = this.CreateCellViews(engine.PlayField);

                this.DrawAll();
            }

            // Register event handlers.
            this.Engine.CurrentCellChanged += this.OnCurrentCellChangedHandler;
            this.Engine.CellsInRegionChanged += this.OnCellsInRegionChangedHandler;
            this.Engine.PlayfieldChanged += this.OnPlayfieldChangedHandler;
            this.Engine.CellsInRegionRedefined += this.OnCellsInRegionRedefinedHandler;
            this.Engine.CellRedefined += this.OnCellRedefinedHandler;
            this.Engine.CellChanged += this.OnCellChangedHandler;
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsoleRenderer" /> class.
 /// </summary>
 /// <param name="engine">The engine object to be attached to this object instance.</param>
 public ConsoleRenderer(Engine engine)
     : base(engine)
 {
     Console.CursorVisible = false;
 }
示例#4
0
        public void TestOnCurrentCellChangedDontRiseEvent()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();
            Playfield testField = Playfield.Instance;
            testField.SetFieldSize(6);
            testField.InitializeEmptyField();

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            enginePrivateInstance.Invoke("OnCurrentCellChanged", new CellEventArgs(new EmptyCell()));
        }
示例#5
0
        public void TestIfPointerChangesItsCoordinateWithPlusOneOnChangeCurrentCell()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            enginePrivateInstance.Invoke("ChangeCurrentCell", 1, 1);
            var pointer = enginePrivateInstance.GetFieldOrProperty("Pointer");
            PrivateObject enginePointer = new PrivateObject(pointer);
            int currentPointerX = (int)enginePointer.GetFieldOrProperty("X");
            int currentPointerY = (int)enginePointer.GetFieldOrProperty("Y");
            bool isCurrentCellAtX1AndY1 = (currentPointerX == 1 && currentPointerY == 1);

            Assert.AreEqual(isCurrentCellAtX1AndY1, true, "Expected that current cell is on coordinate 1,1. Received x={0} y={1}", currentPointerX, currentPointerY);
        }
示例#6
0
        public void TestIfOnSaveLoadButtonPressedReturnsTrue()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();
            Playfield testField = Playfield.Instance;
            testField.SetFieldSize(6);
            testField.InitializeEmptyField();

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            var output = enginePrivateInstance.Invoke("OnSaveLoadButtonPressed", ConsoleKey.F5);

            Assert.IsTrue((bool)output, "When save key is pressed should return true");

            output = enginePrivateInstance.Invoke("OnSaveLoadButtonPressed", ConsoleKey.F6);

            Assert.IsTrue((bool)output, "When load button is pressed should return true");
        }
示例#7
0
        public void TestIfOnDirectionKeyPressedReturnsTrue()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();
            Playfield testField = Playfield.Instance;
            testField.SetFieldSize(6);
            testField.InitializeEmptyField();

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            var output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.UpArrow);

            Assert.IsTrue((bool)output, "When left key arrow is pressed should return true");

            output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.LeftArrow);

            Assert.IsTrue((bool)output, "When left key arrow is pressed should return true");

            output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.RightArrow);

            Assert.IsTrue((bool)output, "When left key arrow is pressed should return true");

            output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.DownArrow);

            Assert.IsTrue((bool)output, "When left key arrow is pressed should return true");

            output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.E);

            Assert.IsFalse((bool)output, "When left key arrow is pressed should return true");
        }
示例#8
0
        public void TestIfHandleExplosionHandleAllCases()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();
            Playfield testField = Playfield.Instance;
            testField.SetFieldSize(6);
            testField.InitializeEmptyField();

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            enginePrivateInstance.Invoke("HandleExplosion", new BombCell(1));
            enginePrivateInstance.Invoke("HandleExplosion", new BombCell(2));
            enginePrivateInstance.Invoke("HandleExplosion", new BombCell(3));
            enginePrivateInstance.Invoke("HandleExplosion", new BombCell(4));
        }
示例#9
0
        public void TestIfEngineStop()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);

            enginePrivateInstance.Invoke("Stop");
        }
示例#10
0
        public void TestIfEngineHasCurrentCellWithCoordinates00WhenInitialized()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            var currentCell = enginePrivateInstance.GetFieldOrProperty("CurrentCell");
            PrivateObject engineCurrentCell = new PrivateObject(currentCell);
            int currentCellX = (int)engineCurrentCell.GetFieldOrProperty("X");
            int currentCellY = (int)engineCurrentCell.GetFieldOrProperty("Y");
            bool isCurrentCellAtX0AndY0 = (currentCellX == 0 && currentCellY == 0);

            Assert.AreEqual(isCurrentCellAtX0AndY0, true, "Expected that current cell is on coordinate 0,0. Received x={0} y={1}", currentCellX, currentCellY);
        }
示例#11
0
        public void TestIfEngineHandlesQuitGameCommandOnStartScreen()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsQuitGameChosen = true;
            Engine gameEngine = new Engine();
            PrivateObject obj = new PrivateObject(gameEngine);
            var isRunning = obj.GetFieldOrProperty("isRunning");
            var retVal = obj.Invoke("HandleUserChoise");

            Assert.AreEqual(isRunning, true, "Set user choice to quit game. Expected isRunning property true. Received false");
        }