public override Shape Construct(ShapeFactory shapeFactory) { var rootShape = shapeFactory.CreateComposite(); rootShape.Add(shapeFactory.CreateRectangle(10, 30, 5, 4)); rootShape.Add(shapeFactory.CreateCircle(10, 3, 13)); rootShape.Add(shapeFactory.CreateComposite( shapeFactory.CreateRectangle(12, 14, 2, 2), shapeFactory.CreateCircle(15, 18, 2) )); return(rootShape); }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); Scene.Engine.AddLogic(new GravityPointField(new Vector2D(500, 500), 1000, new Lifespan())); Light light = new Light(); light.Position.X = 000; light.Position.Y = 000; light.Position.Z = 0100; Body lightBody = new Body(new PhysicsState(), ShapeFactory.CreateCircle(15, 20), 40, new Coefficients(0, 1), new Lifespan()); BodyGraphic lightGraphic = new BodyGraphic(lightBody); lightGraphic.DrawProperties.Add(new Color3Property(1, 1, 1)); Scene.AddGraphic(lightGraphic); lightBody.PositionChanged += delegate(object sender, EventArgs e) { light.Position = lightBody.State.Position.Linear.ToVector3D(100); }; IShape shape = ShapeFactory.CreateSprite( Cache <SurfacePolygons> .GetItem("Monkey.png"), Cache <Surface> .GetItem("MonkeyNormal.bmp"), false, true, 3, 8, 16, light); DemoHelper.AddGrid(DemoInfo, shape, 40, new BoundingRectangle(40, 40, 900, 900), 100, 100); }
public void CreateCircle(double x, double y, double radius) { var center = new Point(x, y); if (radius < 0) { Assert.Catch <InvalidShapeArgumentException>(() => { _shapeFactory.CreateCircle(center, radius); }); } else { var shape = _shapeFactory.CreateCircle(center, radius); Assert.AreEqual(shape.Center, center); Assert.AreEqual(shape.Radius, radius); } }
public void GetAreaTest() { var center = new Point(0, 1); var shape = _shapeFactory.CreateCircle(center, 2); var area = shape.GetArea(); Assert.AreEqual(area, Math.PI * 4); }
public override Shape Construct(ShapeFactory shapeFactory) { string line = Console.ReadLine(); var shape = shapeFactory.CreateComposite(); while (line != string.Empty) { var parts = line.Split(' '); if (parts[0] == "circle") { var x = double.Parse(parts[1]); var y = double.Parse(parts[2]); var r = double.Parse(parts[3]); shape.Add(shapeFactory.CreateCircle(x, y, r)); } else if (parts[0] == "rectangle") { var x = double.Parse(parts[1]); var y = double.Parse(parts[2]); var w = double.Parse(parts[3]); var h = double.Parse(parts[4]); shape.Add(shapeFactory.CreateRectangle(x, y, w, h)); } else if (parts[0] == "complex") { shape.Add(this.Construct(shapeFactory)); } line = Console.ReadLine(); } return(shape); }