コード例 #1
0
        public void Darkelf_settlement_of_1()
        {
            Player player = new Player();

            player.AddSettlement("Margeritaville", Point2.Create(2, 2), Globals.Instance.RaceTypes[2]); // Dark Elf
            Globals.Instance.GameWorld.SetPlayer(player);

            Settlement settlement = Globals.Instance.GameWorld.GetPlayerSettlementOnCell(Point2.Create(2, 2));

            Assert.AreEqual(SettlementType.Hamlet, settlement.SettlementType, "SettlementType incorrect."); // Note: SettlementType could be de-hardcoded
            Assert.AreEqual("Margeritaville", settlement.Name, "Settlement Name incorrect.");
            Assert.AreEqual("Dark Elves", settlement.RaceName, "Settlement RaceName incorrect.");
            Assert.AreEqual(1, settlement.SettlementSize, "Settlement SettlementSize incorrect.");
            Assert.AreEqual(1000, settlement.Population, "Settlement Population incorrect.");
            Assert.AreEqual(110, settlement.GrowthRate, "Settlement GrowthRate incorrect.");

            Assert.AreEqual(1, settlement.SubsistenceFarmers, "Settlement SubsistenceFarmers incorrect.");
            Assert.AreEqual(0, settlement.AdditionalFarmers, "Settlement AdditionalFarmers incorrect.");
            Assert.AreEqual(0, settlement.TotalWorkers, "Settlement Workers incorrect.");
            Assert.AreEqual(0, settlement.TotalRebels, "Settlement Rebels incorrect.");

            Assert.AreEqual(1, settlement.FoodConsumption, "Settlement FoodConsumption incorrect.");
            Assert.AreEqual(1, settlement.FoodSurplus, "Settlement FoodSurplus incorrect.");
            Assert.AreEqual(0, settlement.Production, "Settlement Production incorrect.");
            //settlement.GoldUpkeep
            //settlement.GoldSurplus
            //settlement.Power
            //settlement.Research

            //settlement.Enchantments
            //settlement.Buildings
            //settlement.Surroundings
            //settlement.Units
            //settlement.Producing
        }
コード例 #2
0
        private static List <Cell> GetSettlementCells(Point2 location)
        {
            var cells = new List <Cell>
            {
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X - 1, location.Y - 2)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X, location.Y - 2)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X + 1, location.Y - 2)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X - 2, location.Y - 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X - 1, location.Y - 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X, location.Y - 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X + 1, location.Y - 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X + 2, location.Y - 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X - 2, location.Y)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X - 1, location.Y)),
                Globals.Instance.GameWorld.GetCell(location),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X + 1, location.Y)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X + 2, location.Y)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X - 2, location.Y + 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X - 1, location.Y + 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X, location.Y + 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X + 1, location.Y + 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X + 2, location.Y + 1)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X - 1, location.Y + 2)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X, location.Y + 2)),
                Globals.Instance.GameWorld.GetCell(Point2.Create(location.X + 1, location.Y + 2))
            };

            return(cells);
        }
コード例 #3
0
ファイル: PointTests.cs プロジェクト: gmoller/MapEditor
        public void InstantiationTest2()
        {
            Point2 point = Point2.Create(1, 1);

            Assert.AreEqual(1, point.X);
            Assert.AreEqual(1, point.Y);
        }
コード例 #4
0
        public void Unit_can_move_east_twice_in_one_turn()
        {
            Unit unit = CreateUnit(Point2.Empty);

            unit = MoveUnit(unit, CompassDirection.East, Point2.Create(1, 0));
            MoveUnit(unit, CompassDirection.East, Point2.Create(2, 0), 0.0f);
        }
コード例 #5
0
ファイル: GameMapView.cs プロジェクト: gmoller/Archmaester
 private void DrawRow(int rowIndex, SpriteBatch spriteBatch)
 {
     for (int colIndex = 0; colIndex < _gameWorld.NumberOfColumns; ++colIndex)
     {
         Point2 cellLocation = Point2.Create(colIndex, rowIndex);
         DrawColumn(cellLocation, spriteBatch);
     }
 }
コード例 #6
0
 internal static void SetCellVisibility(Point2 location, GameWorld gameWorld)
 {
     gameWorld.SetCellVisible(Point2.Create(location.X - 1, location.Y + 1)); // northwest
     gameWorld.SetCellVisible(Point2.Create(location.X, location.Y + 1));     // north
     gameWorld.SetCellVisible(Point2.Create(location.X + 1, location.Y + 1)); // northeast
     gameWorld.SetCellVisible(Point2.Create(location.X - 1, location.Y));     // west
     gameWorld.SetCellVisible(location);
     gameWorld.SetCellVisible(Point2.Create(location.X + 1, location.Y));     // east
     gameWorld.SetCellVisible(Point2.Create(location.X - 1, location.Y - 1)); // southwest
     gameWorld.SetCellVisible(Point2.Create(location.X, location.Y - 1));     // south
     gameWorld.SetCellVisible(Point2.Create(location.X + 1, location.Y - 1)); // southeast
 }
コード例 #7
0
        private Point2 ReadPoint(char cmd, bool allowcomma)
        {
            double x = ReadNumber(allowcomma);
            double y = ReadNumber(_allowComma);

            if (cmd >= 'a')
            {
                x += _lastPoint.X;
                y += _lastPoint.Y;
            }

            return(Point2.Create(x, y));
        }
コード例 #8
0
ファイル: Map.cs プロジェクト: gmoller/MapEditor
        public void DrawBoard(bool showGrid)
        {
            int x = 0;
            int y = 0;

            for (int rowIndex = 0; rowIndex < _gameWorld.GameBoard.NumberOfRows; ++rowIndex)
            {
                for (int colIndex = 0; colIndex < _gameWorld.GameBoard.NumberOfColumns; ++colIndex)
                {
                    var rectangle = new Rectangle(x + _drawingArea.X - _camera.VisibleRectangle.X, y + _drawingArea.Y - _camera.VisibleRectangle.Y, CellWidth, CellHeight);

                    Point2 p    = Point2.Create(colIndex, rowIndex);
                    Cell   cell = _gameWorld.GetCell(p);
                    if (_gameWorld.IsCellVisible(p))
                    {
                        Image image           = _images.GetTileImage(cell.TerrainTypeId);
                        var   sourceRectangle = new Rectangle(0, 0, image.Width, image.Height);
                        _graphicsBuffer.DrawImage(image, rectangle, sourceRectangle, GraphicsUnit.Pixel);
                    }
                    else
                    {
                        _graphicsBuffer.FillRectangle(rectangle, Color.Black);
                    }

                    if (showGrid)
                    {
                        _graphicsBuffer.DrawRectangle(rectangle, Color.DimGray);
                    }

                    x += CellWidth;
                }

                y += CellHeight;
                x  = 0;
            }

            // TODO: get below values from camera
            const int margin = 5;
            int       radius = CellWidth / 2;

            _graphicsBuffer.DrawCircle(new Point(0 * CellWidth + radius + margin, 0 * CellHeight + radius + margin), radius, Color.DeepPink);   // NW
            _graphicsBuffer.DrawCircle(new Point(31 * CellWidth + radius + margin, 0 * CellHeight + radius + margin), radius, Color.DeepPink);  // NE
            _graphicsBuffer.DrawCircle(new Point(16 * CellWidth + radius + margin, 14 * CellHeight + radius + margin), radius, Color.DeepPink); // Center
            _graphicsBuffer.DrawCircle(new Point(0 * CellWidth + radius + margin, 27 * CellHeight + radius + margin), radius, Color.DeepPink);  // SW
            _graphicsBuffer.DrawCircle(new Point(31 * CellWidth + radius + margin, 27 * CellHeight + radius + margin), radius, Color.DeepPink); // SE

            _graphicsBuffer.DrawRectangle(new Rectangle(_drawingArea.X, _drawingArea.Y, _drawingArea.Width - 1, _drawingArea.Height - 1), Color.Red);
            _graphicsBuffer.DrawRectangle(new Rectangle(_drawingArea.X + 1, _drawingArea.Y + 1, _drawingArea.Width - 3, _drawingArea.Height - 3), Color.Red);
            _graphicsBuffer.DrawRectangle(new Rectangle(_drawingArea.X + 2, _drawingArea.Y + 2, _drawingArea.Width - 4, _drawingArea.Height - 4), Color.Red);
        }
コード例 #9
0
        public void Unit_can_move_east()
        {
            var movementProcessor = new MovementProcessor();

            INewLocationCalculator newLocationCalculator = NewLocationCalculatorFactory.GetNewLocationCalculator(CompassDirection.East);

            Stopwatch       sw       = Stopwatch.StartNew();
            ProcessResponse response = movementProcessor.Process(new ProcessRequest(Point2.Empty, 2.0f), newLocationCalculator);

            sw.Stop();
            Console.WriteLine($"Time taken: {sw.ElapsedMilliseconds} ms");

            Unit unit = Unit.Create(0, response.NewLocation, response.NewMovementPoints);

            Assert.AreEqual(Point2.Create(1, 0), unit.Location, "Location incorrect.");
            Assert.AreEqual(1.0f, unit.MovementPoints, "MovementPoints incorrect.");
        }
コード例 #10
0
        public void Unit_can_move_east_in_parallel()
        {
            var movementProcessor = new MovementProcessor();

            INewLocationCalculator newLocationCalculator = NewLocationCalculatorFactory.GetNewLocationCalculator(CompassDirection.East);

            ProcessRequest[] requests = { new ProcessRequest(Point2.Empty, 2.0f) };

            Stopwatch sw = Stopwatch.StartNew();

            ProcessResponse[] response = movementProcessor.Process(requests, newLocationCalculator);
            sw.Stop();
            Console.WriteLine($"Time taken: {sw.ElapsedMilliseconds} ms");

            Assert.AreEqual(Point2.Create(1, 0), response[0].NewLocation, "NewLocation incorrect.");
            Assert.AreEqual(1.0f, response[0].NewMovementPoints, "NewMovementPoints incorrect.");
        }
コード例 #11
0
ファイル: GameBoard.cs プロジェクト: gmoller/Archmaester
        private Cell GetNeighboringCell(Point2 cellLocation, CompassDirection direction)
        {
            Point2 p;

            switch (direction)
            {
            case CompassDirection.North:
                p = Point2.Create(cellLocation.X, cellLocation.Y - 1);
                break;

            case CompassDirection.NorthEast:
                p = Point2.Create(cellLocation.X + 1, cellLocation.Y - 1);
                break;

            case CompassDirection.East:
                p = Point2.Create(cellLocation.X + 1, cellLocation.Y);
                break;

            case CompassDirection.SouthEast:
                p = Point2.Create(cellLocation.X + 1, cellLocation.Y + 1);
                break;

            case CompassDirection.South:
                p = Point2.Create(cellLocation.X, cellLocation.Y + 1);
                break;

            case CompassDirection.SouthWest:
                p = Point2.Create(cellLocation.X - 1, cellLocation.Y + 1);
                break;

            case CompassDirection.West:
                p = Point2.Create(cellLocation.X - 1, cellLocation.Y);
                break;

            case CompassDirection.NorthWest:
                p = Point2.Create(cellLocation.X - 1, cellLocation.Y - 1);
                break;

            default:
                p = Point2.Null;
                break;
            }

            return(GetCell(p));
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: gmoller/MapEditor
        private void Form1_Load(object sender, EventArgs e)
        {
            // Load stuff
            List <TerrainType> terrainTypes = TerrainTypesLoader.GetTerrainTypes();

            _texts = new List <string>();
            foreach (TerrainType terrainType in terrainTypes)
            {
                string text = $"{terrainType.Id} - {terrainType.Name}";
                _texts.Add(text);
            }

            _images = new Images();

            // Create gameboard
            //int[,] terrain = MapLoader.Load("Map.txt");
            int[,] terrain = MapGenerator.Generate(COLUMNS, ROWS);
            GameBoard testMap = GameBoard.Create(1, terrain, ALL_VISIBLE);

            Globals.Instance.GameWorld.SetGameBoard(testMap);

            var player = new Player();

            player.UnitMoved += Player_UnitMoved;
            player.TurnEnded += Player_TurnEnded;
            player.AddSettlement("Margeritaville", Point2.Create(1, 1), Globals.Instance.RaceTypes[0]);
            player.AddUnit(4, Point2.Create(0, 0)); // cavalry
            player.AddUnit(0, Point2.Create(0, 1)); // cavalry
            player.StartTurn();

            var player2 = new Player2();

            player2.UnitMoved += Player2_UnitMoved;
            player2.AddUnit(0, Point2.Create(1, 0)); // 50,30
            player2.AddUnit(0, Point2.Create(2, 0));

            Globals.Instance.GameWorld.SetPlayer(player);
            Globals.Instance.GameWorld.SetPlayer2(player2);

            // Start timer
            timer1.Interval = 1;
            timer1.Start();
        }
コード例 #13
0
ファイル: GameBoard.cs プロジェクト: gmoller/Archmaester
        public List <Point2> GetCellNeighbors(Point2 location)
        {
            var    neighbors = new List <Point2>();
            Point2 a         = Point2.Create(location.X, location.Y + 1); // north
            Point2 b         = Point2.Create(location.X - 1, location.Y); // west
            Point2 c         = Point2.Create(location.X, location.Y - 1); // south
            Point2 d         = Point2.Create(location.X + 1, location.Y); // east

            var dic = new Dictionary <int, Point2[]>
            {
                { 1, new[] { a, b, c, d } },
                { 2, new[] { a, b, d, c } },
                { 3, new[] { a, c, b, d } },
                { 4, new[] { a, c, d, b } },
                { 5, new[] { a, d, b, c } },
                { 6, new[] { a, d, c, b } },
                { 7, new[] { b, a, c, d } },
                { 8, new[] { b, a, d, c } },
                { 9, new[] { b, c, a, d } },
                { 10, new[] { b, c, d, a } },
                { 11, new[] { b, d, a, c } },
                { 12, new[] { b, d, c, a } },
                { 13, new[] { c, a, b, d } },
                { 14, new[] { c, a, d, b } },
                { 15, new[] { c, b, a, d } },
                { 16, new[] { c, b, d, a } },
                { 17, new[] { c, d, a, b } },
                { 18, new[] { c, d, b, a } },
                { 19, new[] { d, a, b, c } },
                { 20, new[] { d, a, c, b } },
                { 21, new[] { d, b, a, c } },
                { 22, new[] { d, b, c, a } },
                { 23, new[] { d, c, a, b } },
                { 24, new[] { d, c, b, a } }
            };

            int i = _random.Next(1, 25); // get a number between 1 and 24

            Point2[] points = dic[i];
            AddCellsIfItsOnBoard(neighbors, points);

            return(neighbors);
        }
コード例 #14
0
ファイル: Tests.cs プロジェクト: gmoller/MapEditor
        public void One_turn()
        {
            List <Unit> units = CreateUnits(Point2.Create(0, 1));

            // move each unit east twice
            foreach (Unit unit in units)
            {
                //Unit unit2 = unit.Move(_movementProcessor, CompassDirection.East);
                //Unit unit3 = unit2.Move(_movementProcessor, CompassDirection.East);

                //Assert.AreEqual(Point2.Create(2, 1), unit3.Location, "Location incorrect.");
                //Assert.AreEqual(0, unit3.MovementPoints, "MovementPoints incorrect.");
            }

            // end turn and they all have their movement points reset
            foreach (Unit unit in units)
            {
                Unit unit2 = unit.StartNewTurn();

                Assert.AreEqual(2.0f, unit2.MovementPoints, "MovementPoints incorrect.");
            }
        }
コード例 #15
0
        public override void Initialize()
        {
            // setup players
            var humanPlayer = new PlayerHuman();

            // setup map/board
            Globals.Instance.GameWorld.Intialize(200, 160, humanPlayer, null);

            //humanPlayer.UnitMoved += Player_UnitMoved;
            //humanPlayer.TurnEnded += Player_TurnEnded;
            //humanPlayer.AddSettlement("Margeritaville", Point2.Create(1, 1), Globals.Instance.RaceTypes[0]);
            humanPlayer.AddUnit(4, Point2.Create(2, 2)); // cavalry
            humanPlayer.AddUnit(0, Point2.Create(0, 1)); // spearman
            humanPlayer.StartTurn();

            _hud = new Hud(Game);
            _hud.Initialize();
            _gameMapView = new GameMapView(Globals.Instance.GameWorld, new Rectangle(0, 0, Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height), _hud);
            _unitsView   = new UnitsView(Globals.Instance.GameWorld);

            Globals.Instance.GameWorld.StartTurnForHumanPlayer();
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: gmoller/MapEditor
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Point?worldCell = GetWorldCell(e.Location);

                if (worldCell != null)
                {
                    Point2 location = Point2.Create(worldCell.Value.X, worldCell.Value.Y);
                    if (Globals.Instance.GameWorld.IsPlayerSettlementOnCell(location))
                    {
                        Settlement settlement     = Globals.Instance.GameWorld.GetPlayerSettlementOnCell(location);
                        var        settlementForm = new SettlementForm();
                        settlementForm.SetData(settlement);
                        settlementForm.ShowDialog();
                    }
                    else
                    {
                        _mapWindow.CenterOnCell(worldCell.GetValueOrDefault());
                    }
                }
            }
        }
コード例 #17
0
        public void Unit_can_move_east()
        {
            Unit unit = CreateUnit(Point2.Create(1, 1));

            MoveUnit(unit, CompassDirection.East, Point2.Create(2, 1));
        }
コード例 #18
0
ファイル: WpfArc.cs プロジェクト: nagyistge/Core2D
        /// <summary>
        ///
        /// </summary>
        /// <param name="arc"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static WpfArc FromXArc(IArc arc, double dx, double dy)
        {
            var    p1      = Point2.Create(arc.Point1.X + dx, arc.Point1.Y + dy);
            var    p2      = Point2.Create(arc.Point2.X + dx, arc.Point2.Y + dy);
            var    p3      = Point2.Create(arc.Point3.X + dx, arc.Point3.Y + dy);
            var    p4      = Point2.Create(arc.Point4.X + dx, arc.Point4.Y + dy);
            var    rect    = Rect2.Create(p1, p2);
            var    center  = Point2.Create(rect.X + rect.Width / 2.0, rect.Y + rect.Height / 2.0);
            double offsetX = center.X - rect.X;
            double offsetY = center.Y - rect.Y;

            double minLenght = Max(offsetX, offsetY);

            double length1 = center.Distance(p3);
            double p3x     = p3.X + (p3.X - center.X) / length1 * minLenght;
            double p3y     = p3.Y + (p3.Y - center.Y) / length1 * minLenght;

            double length2 = center.Distance(p4);
            double p4x     = p4.X + (p4.X - center.X) / length2 * minLenght;
            double p4y     = p4.Y + (p4.Y - center.Y) / length2 * minLenght;

            p3.X = p3x;
            p3.Y = p3y;
            p4.X = p4x;
            p4.Y = p4y;

            var    p3i = MathHelpers.FindEllipseSegmentIntersections(rect, center, p3, true);
            var    p4i = MathHelpers.FindEllipseSegmentIntersections(rect, center, p4, true);
            Point2 start;
            Point2 end;

            if (p3i.Count == 1)
            {
                start = p3i.FirstOrDefault();
            }
            else
            {
                start = Point2.Create(p3.X, p3.Y);
            }

            if (p4i.Count == 1)
            {
                end = p4i.FirstOrDefault();
            }
            else
            {
                end = Point2.Create(p4.X, p4.Y);
            }

            double angle      = MathHelpers.AngleLineSegments(center, start, center, end);
            bool   isLargeArc = angle > 180.0;

            double helperLenght = 60.0;

            double lengthStart = center.Distance(start);
            double p3hx        = start.X + (start.X - center.X) / lengthStart * helperLenght;
            double p3hy        = start.Y + (start.Y - center.Y) / lengthStart * helperLenght;

            double lengthEnd = center.Distance(end);
            double p4hx      = end.X + (end.X - center.X) / lengthEnd * helperLenght;
            double p4hy      = end.Y + (end.Y - center.Y) / lengthEnd * helperLenght;

            p3.X = p3hx;
            p3.Y = p3hy;
            p4.X = p4hx;
            p4.Y = p4hy;

            return(new WpfArc()
            {
                P1 = p1,
                P2 = p2,
                P3 = p3,
                P4 = p4,
                Rect = rect,
                Center = center,
                Start = start,
                End = end,
                Radius = Size2.Create(offsetX, offsetY),
                IsLargeArc = isLargeArc,
                Angle = angle
            });
        }
コード例 #19
0
 public Point2 Calculate(Point2 location)
 {
     return(Point2.Create(location.X - 1, location.Y - 1));
 }
コード例 #20
0
 private Point2 Reflect()
 {
     return(Point2.Create(2 * _lastPoint.X - _secondLastPoint.X, 2 * _lastPoint.Y - _secondLastPoint.Y));
 }
コード例 #21
0
        /// <summary>
        /// Parse a SVG path geometry string.
        /// </summary>
        /// <param name="context">The geometry context.</param>
        /// <param name="pathString">The path geometry string</param>
        /// <param name="startIndex">The string start index.</param>
        public void Parse(XGeometryContext context, string pathString, int startIndex)
        {
            _context         = context;
            _pathString      = pathString;
            _pathLength      = pathString.Length;
            _curIndex        = startIndex;
            _secondLastPoint = Point2.Create(0, 0);
            _lastPoint       = Point2.Create(0, 0);
            _lastStart       = Point2.Create(0, 0);
            _figureStarted   = false;
            bool first    = true;
            char last_cmd = ' ';

            while (ReadToken())
            {
                char cmd = _token;

                if (first)
                {
                    if ((cmd != 'M') && (cmd != 'm'))
                    {
                        InvalidToken();
                    }

                    first = false;
                }

                switch (cmd)
                {
                case 'm':
                case 'M':
                    _lastPoint = ReadPoint(cmd, !_allowComma);

                    _context.BeginFigure(XPoint.FromPoint2(_lastPoint), _isFilled, !_isClosed);
                    _figureStarted = true;
                    _lastStart     = _lastPoint;
                    last_cmd       = 'M';

                    while (IsNumber(_allowComma))
                    {
                        _lastPoint = ReadPoint(cmd, !_allowComma);
                        _context.LineTo(XPoint.FromPoint2(_lastPoint), _isStroked, !_isSmoothJoin);
                        last_cmd = 'L';
                    }
                    break;

                case 'l':
                case 'L':
                case 'h':
                case 'H':
                case 'v':
                case 'V':
                    EnsureFigure();

                    do
                    {
                        switch (cmd)
                        {
                        case 'l':
                            _lastPoint = ReadPoint(cmd, !_allowComma);
                            break;

                        case 'L':
                            _lastPoint = ReadPoint(cmd, !_allowComma);
                            break;

                        case 'h':
                            _lastPoint.X += ReadNumber(!_allowComma);
                            break;

                        case 'H':
                            _lastPoint.X = ReadNumber(!_allowComma);
                            break;

                        case 'v':
                            _lastPoint.Y += ReadNumber(!_allowComma);
                            break;

                        case 'V':
                            _lastPoint.Y = ReadNumber(!_allowComma);
                            break;
                        }

                        _context.LineTo(XPoint.FromPoint2(_lastPoint), _isStroked, !_isSmoothJoin);
                    }while (IsNumber(_allowComma));

                    last_cmd = 'L';
                    break;

                case 'c':
                case 'C':
                case 's':
                case 'S':
                    EnsureFigure();

                    do
                    {
                        Point2 p;

                        if ((cmd == 's') || (cmd == 'S'))
                        {
                            if (last_cmd == 'C')
                            {
                                p = Reflect();
                            }
                            else
                            {
                                p = _lastPoint;
                            }

                            _secondLastPoint = ReadPoint(cmd, !_allowComma);
                        }
                        else
                        {
                            p = ReadPoint(cmd, !_allowComma);

                            _secondLastPoint = ReadPoint(cmd, _allowComma);
                        }

                        _lastPoint = ReadPoint(cmd, _allowComma);
                        _context.CubicBezierTo(
                            XPoint.FromPoint2(p),
                            XPoint.FromPoint2(_secondLastPoint),
                            XPoint.FromPoint2(_lastPoint),
                            _isStroked,
                            !_isSmoothJoin);

                        last_cmd = 'C';
                    }while (IsNumber(_allowComma));

                    break;

                case 'q':
                case 'Q':
                case 't':
                case 'T':
                    EnsureFigure();

                    do
                    {
                        if ((cmd == 't') || (cmd == 'T'))
                        {
                            if (last_cmd == 'Q')
                            {
                                _secondLastPoint = Reflect();
                            }
                            else
                            {
                                _secondLastPoint = _lastPoint;
                            }

                            _lastPoint = ReadPoint(cmd, !_allowComma);
                        }
                        else
                        {
                            _secondLastPoint = ReadPoint(cmd, !_allowComma);
                            _lastPoint       = ReadPoint(cmd, _allowComma);
                        }

                        _context.QuadraticBezierTo(
                            XPoint.FromPoint2(_secondLastPoint),
                            XPoint.FromPoint2(_lastPoint),
                            _isStroked,
                            !_isSmoothJoin);

                        last_cmd = 'Q';
                    }while (IsNumber(_allowComma));

                    break;

                case 'a':
                case 'A':
                    EnsureFigure();

                    do
                    {
                        double w        = ReadNumber(!_allowComma);
                        double h        = ReadNumber(_allowComma);
                        double rotation = ReadNumber(_allowComma);
                        bool   large    = ReadBool();
                        bool   sweep    = ReadBool();

                        _lastPoint = ReadPoint(cmd, _allowComma);

                        _context.ArcTo(
                            XPoint.FromPoint2(_lastPoint),
                            XPathSize.Create(w, h),
                            rotation,
                            large,
                            sweep ? XSweepDirection.Clockwise : XSweepDirection.Counterclockwise,
                            _isStroked,
                            !_isSmoothJoin);
                    }while (IsNumber(_allowComma));

                    last_cmd = 'A';
                    break;

                case 'z':
                case 'Z':
                    EnsureFigure();
                    _context.SetClosedState(_isClosed);

                    _figureStarted = false;
                    last_cmd       = 'Z';
                    _lastPoint     = _lastStart;
                    break;

                default:
                    InvalidToken();
                    break;
                }
            }
        }
コード例 #22
0
        public void Unit_can_move_south()
        {
            Unit unit = CreateUnit(Point2.Create(1, 1));

            MoveUnit(unit, CompassDirection.South, Point2.Create(1, 2));
        }
コード例 #23
0
        public void Unit_can_not_move_west()
        {
            Unit unit = CreateUnit(Point2.Create(0, 0));

            MoveUnit(unit, CompassDirection.West, Point2.Create(0, 0), 2.0f);
        }
コード例 #24
0
        public void Unit_can_move_northwest()
        {
            Unit unit = CreateUnit(Point2.Create(1, 1));

            MoveUnit(unit, CompassDirection.NorthWest, Point2.Create(0, 0));
        }