Beispiel #1
0
 public ScriptsConsoleVM(IPrimitiveDrawer primitive)
 {
     ViewState        = new ScriptsViewState(this);
     Controller       = new ScriptsController(this);
     executer         = new ScriptExetuter(primitive);
     executer.Output += OnExecuterOutput;
     this.primitive   = primitive;
 }
Beispiel #2
0
        public void SetUp()
        {
            stubLevel = MockRepository.GenerateStub<ILevel>();
            stubPlayer = MockRepository.GenerateStub<IPlayer>();
            stubPrimitiveDrawer = MockRepository.GenerateStub<IPrimitiveDrawer>();
            visibilityView = new VisibilityView(stubLevel, stubPlayer, stubPrimitiveDrawer);

            List<LevelPiece> pieces = new List<LevelPiece>();
            stubLevel.Stub(me => me.Pieces).Return(pieces);
        }
Beispiel #3
0
        private void primitiveDrawingButton_Click(object sender, EventArgs e)
        {
            var drawingButton = (Button)sender;

            var(drawingButtonText, newPrimitive, newPrimitiveDrawer) = GetPrimitiveContext(drawingButton, _primitivePoints);
            if (_primitivePoints != null)
            {
                drawingButton.Text = drawingButtonText;
                _primitive         = newPrimitive;
                _primitivePoints   = null;
                _primitiveDrawer.Draw(_canvasGraphics, _drawingPen, _primitive, _canvas);
                return;
            }

            _primitiveDrawer = newPrimitiveDrawer;
            _primitiveDrawer.ClearCanvas(_canvasGraphics, _canvas);
            drawingButton.Text = "Рисование";
            _primitive         = null;
            _primitivePoints   = new List <Point>();

            ///this is peace of shit code
            (string, Primitive, IPrimitiveDrawer) GetPrimitiveContext(Button drawingButton, List <Point> primitivePoints)
            {
                string           drawingButtonText  = null;
                Primitive        newPrimitive       = null;
                IPrimitiveDrawer newPrimitiveDrawer = null;

                if (drawingButton == polygonDrawingButton)
                {
                    if (primitivePoints != null)
                    {
                        drawingButtonText = "Многоугольник";
                        newPrimitive      = new Polygon(primitivePoints);
                    }
                    else
                    {
                        newPrimitiveDrawer = new PolygonDrawer();
                    }
                }
                else if (drawingButton == edgeDrawingButton)
                {
                    if (primitivePoints != null)
                    {
                        drawingButtonText = "Ребро";
                        newPrimitive      = new Edge(primitivePoints);
                    }
                    else
                    {
                        newPrimitiveDrawer = new EdgeDrawer();
                    }
                }
                else
                {
                    throw new ArgumentException();
                }

                return(drawingButtonText, newPrimitive, newPrimitiveDrawer);
            }

            ///this is peace of shit code
            (string, Primitive, IPrimitiveDrawer) GetPrimitiveContext2(Button drawingButton, List <Point> primitivePoints)
            {
                if (drawingButton != edgeDrawingButton && drawingButton != polygonDrawingButton)
                {
                    throw new ArgumentException();
                }
                var(drawingButtonText, newPrimitive, newPrimitiveDrawer) = primitivePoints != null
                    ? drawingButton == polygonDrawingButton
                        ? ("Многоугольник", new Polygon(primitivePoints), (IPrimitiveDrawer)null)
                        : ("Ребро", (Primitive) new Edge(primitivePoints), (IPrimitiveDrawer)null)
                    : drawingButton == polygonDrawingButton
                        ? ((string)null, (Primitive)null, (IPrimitiveDrawer) new PolygonDrawer())
                        : ((string)null, (Primitive)null, new EdgeDrawer());
                return(drawingButtonText, newPrimitive, newPrimitiveDrawer);
            }
        }
Beispiel #4
0
 public VisibilityView(ILevel level, IPlayer player, IPrimitiveDrawer primitiveDrawer)
 {
     _level = level;
     _player = player;
     _primitiveDrawer = primitiveDrawer;
 }
Beispiel #5
0
 public ScriptExetuter(IPrimitiveDrawer drawer)
 {
     this.drawer = drawer;
 }