public Engine(Field field) { this.field = field; this.detonator = new Detonator(field); this.renderer = new Renderer(field); this.userInterface = new UserInterface(field); }
private void CreateGameField(int size) { int minesNumber = GenerateNumberOfMines(size); Field field = new Field(size, minesNumber); field.FillTheField(); Console.WriteLine(field.PrintField()); this.Field = field; }
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); }
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); }
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(); }
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); }
public FieldGenerator(Field field, Random random) { this.field = field; this.random = random; }
public Detonator(Field field) { this.field = field; }
public void MatrixPropertyPutMatrixWithBiggerDimensionsTest() { Field field = new Field(4, 4); field.MatrixForField = new int[12, 12]; }
public void MatrixPropertyNullTest() { Field field = new Field(4, 4); field.MatrixForField = null; }
public void MatrixPropertyNotSquareMatrixTest() { Field field = new Field(4, 4); field.MatrixForField = new int [3,4]; }
public void ConstructorTestWithBiggerSizeThanTheMaxAllowed() { Field field = new Field(11, 4); }
public void ConstructorRegularTest() { Field field = new Field(4, 4); }
public UserInterface(Field field) { this.field = field; }
public Renderer(Field field) { this.field = field; this.cellSize = Field.MaxSize.ToString().Length + 2 * this.cellPadding.Length; }