public Engine CreateEngine(int fieldWidth, int fieldHeight) { var shapeTypes = shapeFactory.GetShapeTypes(); var field = new Field { ActiveShape = null, Width = fieldWidth, Height = fieldHeight, Grid = new SpaceBox[fieldWidth, fieldHeight] }; for (int i = 0; i < fieldWidth; i++) { for (int j = 0; j < fieldHeight; j++) { field.Grid[i, j] = new SpaceBox { IsOpen = true, X = i, Y = j }; } } return(new Engine { field = field, ShapeTypes = shapeTypes, rowsCompleted = 0, speed = 0, random = new Random() }); }
public AddShapeViewModel(IShapeRepository shapeRepo, IShapeFactory shapeFactory) { _ShapeRepo = shapeRepo; _ShapeFactory = shapeFactory; ShapeTypesList = shapeFactory.GetShapeTypes().ToList(); SelectedShapeType = ShapeTypesList.First(); AddShapeCommand = new MvxCommand(AddShape); CancelCommand = new MvxCommand(Cancel); }
public void GetShapeTypes_ReturnsAllStandardTetrisShapes() { // Arrange // ╚╗ var leftBolt = new Shape { CenterX = 1, CenterY = 1, Boxes = new List <Box> { new Box { X = 0, Y = 0 }, new Box { X = 0, Y = 1 }, new Box { X = 1, Y = 1 }, new Box { X = 1, Y = 2 }, } }; // ╔╝ var rightBolt = new Shape { CenterX = 1, CenterY = 1, Boxes = new List <Box> { new Box { X = 1, Y = 0 }, new Box { X = 1, Y = 1 }, new Box { X = 0, Y = 1 }, new Box { X = 0, Y = 2 }, } }; // ║ // ╚═ var leftL = new Shape { CenterX = 1, CenterY = 1, Boxes = new List <Box> { new Box { X = 0, Y = 0 }, new Box { X = 0, Y = 1 }, new Box { X = 0, Y = 2 }, new Box { X = 1, Y = 2 }, } }; // ║ // ═╝ var rightL = new Shape { CenterX = 1, CenterY = 1, Boxes = new List <Box> { new Box { X = 1, Y = 0 }, new Box { X = 1, Y = 1 }, new Box { X = 1, Y = 2 }, new Box { X = 0, Y = 2 }, } }; // ╩ var T = new Shape { CenterX = 1, CenterY = 1, Boxes = new List <Box> { new Box { X = 0, Y = 1 }, new Box { X = 1, Y = 1 }, new Box { X = 1, Y = 0 }, new Box { X = 2, Y = 1 }, } }; // ╔═╗ // ╚═╝ var square = new Shape { CenterX = 1, CenterY = 1, Boxes = new List <Box> { new Box { X = 0, Y = 0 }, new Box { X = 1, Y = 0 }, new Box { X = 1, Y = 1 }, new Box { X = 0, Y = 1 } } }; // ║ // ║ var line = new Shape { CenterX = 0, CenterY = 0, Boxes = new List <Box> { new Box { X = 0, Y = 0 }, new Box { X = 0, Y = 1 }, new Box { X = 0, Y = 2 }, new Box { X = 0, Y = 3 }, } }; // Act var shapes = sut.GetShapeTypes(); // Assert Assert.That(shapes.Count, Is.EqualTo(7)); Assert.True(shapes.Any(s => s.Equals(leftBolt))); Assert.True(shapes.Any(s => s.Equals(rightBolt))); Assert.True(shapes.Any(s => s.Equals(leftL))); Assert.True(shapes.Any(s => s.Equals(rightL))); Assert.True(shapes.Any(s => s.Equals(T))); Assert.True(shapes.Any(s => s.Equals(square))); Assert.True(shapes.Any(s => s.Equals(line))); }