Ejemplo n.º 1
0
        private void CreateGameField(int size)
        {
            int minesNumber = GenerateNumberOfMines(size);
            Field field = new Field(size, minesNumber);

            field.FillTheField();
            Console.WriteLine(field.PrintField());

            this.Field = field;
        }
Ejemplo n.º 2
0
        public void MakeATurn()
        {
            int minesNumber = GenerateNumberOfMines();
            Field field = new Field(this.GameField, minesNumber);

            field.FillTheField();
            field.PrintField();
            int turns = 0;
            while (minesNumber > 0)
            {
                int explodedMines = SetNextMinePosition(field.MatrixForField);
                minesNumber -= explodedMines;
                field.PrintField();
                //Console.WriteLine("Mines Blowed this round: {0}",explodedMines);
                turns++;
            }
            Console.WriteLine("Game over -> detonated mines: {0}", turns);
        }
Ejemplo n.º 3
0
        public void FillTheFieldTest()
        {
            Field field = new Field(5, 8);

            Random fixedRandomGen = new Random(8);

            Type type = typeof(Field);
            var fieldValue = type.GetField("randomGen", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(field, fixedRandomGen);

            field.FillTheField();

            int[,] expected = new int [,]{
                                            {0,5,0,3,0},
                                            {4,0,0,0,3},
                                            {0,0,5,0,0},
                                            {0,0,0,0,0},
                                            {2,5,5,0,0}
            };

            CollectionAssert.AreEqual(expected, field.MatrixForField);
        }
Ejemplo n.º 4
0
        public void PrintRegularTest()
        {
            Field field = new Field(5, 8);

            Random fixedRandomGen = new Random(8);

            Type type = typeof(Field);
            var fieldValue = type.GetField("randomGen", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(field, fixedRandomGen);

            field.FillTheField();

            string expected =
                "  0 1 2 3 4\r\n  ---------\r\n0|- 5 - 3 - \r\n1|4 - - - 3 \r\n2|- - 5 - - \r\n3|- - - - - \r\n4|2 5 5 - - \r\n";

            string actual = field.PrintField();

            Assert.AreEqual(expected, actual);
        }