Ejemplo n.º 1
0
        public Engine(Field field)
        {
            this.field = field;

            this.detonator = new Detonator(field);
            this.renderer = new Renderer(field);
            this.userInterface = new UserInterface(field);
        }
Ejemplo n.º 2
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.º 3
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.º 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);
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            #if !DEBUG
            int size = 9;
            #else
            int size = UserInterface.ReadSize();
            #endif

            Console.WriteLine("Welcome to \"Battle Field\" game.");

            field = new Field(size, size);
            var generator = new FieldGenerator(field, new Random(0));
            generator.Generate();

            Engine engine = new Engine(field);

            engine.OnGameOver += (obj, numberOfMoves) =>
                Console.WriteLine("You finished in {0} moves.", numberOfMoves);

            engine.Run();
        }
Ejemplo n.º 6
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.º 7
0
 public FieldGenerator(Field field, Random random)
 {
     this.field = field;
     this.random = random;
 }
Ejemplo n.º 8
0
 public Detonator(Field field)
 {
     this.field = field;
 }
Ejemplo n.º 9
0
 public void MatrixPropertyPutMatrixWithBiggerDimensionsTest()
 {
     Field field = new Field(4, 4);
     field.MatrixForField = new int[12, 12];
 }
Ejemplo n.º 10
0
 public void MatrixPropertyNullTest()
 {
     Field field = new Field(4, 4);
     field.MatrixForField = null;
 }
Ejemplo n.º 11
0
 public void MatrixPropertyNotSquareMatrixTest()
 {
     Field field = new Field(4, 4);
     field.MatrixForField = new int [3,4];
 }
Ejemplo n.º 12
0
 public void ConstructorTestWithBiggerSizeThanTheMaxAllowed()
 {
     Field field = new Field(11, 4);
 }
Ejemplo n.º 13
0
 public void ConstructorRegularTest()
 {
     Field field = new Field(4, 4);
 }
Ejemplo n.º 14
0
 public UserInterface(Field field)
 {
     this.field = field;
 }
Ejemplo n.º 15
0
        public Renderer(Field field)
        {
            this.field = field;

            this.cellSize = Field.MaxSize.ToString().Length + 2 * this.cellPadding.Length;
        }