public void TestMineControllerSetsGameFieldCorrectly()
 {
     var gameField = new GameField(5);
     var mineController = new MineController(gameField);
     Assert.IsNotNull(mineController.GameField);
     Assert.IsTrue(mineController.GameField == gameField);
 }
Example #2
0
        public void Run()
        {
            this.output.RenderText("Welcome to \"Battle Field\" game.\nEnter battle field size: n = ");
            int size = this.input.ReadInteger();

            while (size == -1 || size < Constants.MinFieldSize || size > Constants.MaxFieldSize)
            {
                this.output.RenderText("The field size is invalid. It must be a number between 1 and 10. ");
                size = this.input.ReadInteger();
            }

            this.gameField = new GameField(size);
            this.mineController = new MineController(this.gameField);
            int mines = this.PlaceMines(size);
            while (mines > 0)
            {
                this.output.Clear();
                ShowLastHit();
                this.output.Render(gameField);
                do
                {
                    this.output.RenderText("Please enter coordinates: ");
                    this.lastPosition = this.input.ReadPosition();
                }
                while (!IsValidPosition());
                score++;
                bool isMineHit = IsMineHit();
                if (isMineHit)
                {
                    string mineHitOnField = gameField[this.lastPosition.X, this.lastPosition.Y].ToString();
                    int mineHit = int.Parse(mineHitOnField);
                    var currentMine = mineFactory.CreateMine((MineType)mineHit);
                    mineController.SetMine(currentMine);
                    mineController.SetHitPosition(this.lastPosition);

                    // Explode mine
                    int minesTakenOut = mineController.ExplodeMine();
                    mines -= minesTakenOut;
                }
            }
        }
 public void TestMineControllerIsCreatedCorrectly()
 {
     var mineController = new MineController(new GameField(5));
     Assert.IsNotNull(mineController);
     Assert.IsInstanceOfType(mineController, typeof(MineController));
 }