public GamePosition(Field field, TeamPosition firstTeamPosition, TeamPosition secondTeamPosition, BallPosition ballPosition)
        {
            Contract.Requires<ArgumentNullException>(firstTeamPosition != null);
            Contract.Requires<ArgumentNullException>(secondTeamPosition != null);

            _field = field;
            _firstTeamPosition = firstTeamPosition;
            _secondTeamPosition = secondTeamPosition;
            _ballPosition = ballPosition;
        }
        private void m_btnStart_Click(object sender, System.EventArgs e)
        {
            var field = new Field(100, 50, 0.12f);
            var firstTeamPosition = new TeamPosition(new Dictionary<Player, PlayerPosition>());
            var secondTeamPosition = new TeamPosition(new Dictionary<Player, PlayerPosition>());
            var ballPosition = new BallPosition();
            var gamePosition = new GamePosition(field, firstTeamPosition, secondTeamPosition, ballPosition);

            m_imgTopView.Image = new BitmapVisualizer(m_imgTopView.Width, m_imgTopView.Height).Draw(gamePosition);
        }
        public CoordinateConverter(int width, int height, Field field)
        {
            double indentWidth = 5.0;
            double indentHeight = 5.0;

            _kw = width / (field.Width + 2 * indentWidth);
            _kh = height / (field.Height + 2 * indentHeight);

            _wp = indentWidth * _kw;
            _hp = indentHeight * _kh;

            _w2 = (width - 2 * _wp) / 2;
            _h2 = (height - 2 * _hp) / 2;
        }
Exemple #4
0
        public Game(IGameRunner runner, IGameRunnerStateBuilder gameStateBuilder, Field field, Team firstTeam, Team secondTeam, Ball ball)
        {
            Contract.Requires<ArgumentNullException>(runner != null);
            Contract.Requires<ArgumentNullException>(gameStateBuilder != null);

            Contract.Requires<ArgumentNullException>(firstTeam != null);
            Contract.Requires<ArgumentNullException>(secondTeam != null);
            Contract.Requires<ArgumentNullException>(ball != null);

            _runner = runner;
            _gameStateBuilder = gameStateBuilder;
            _field = field;
            _firstTeam = firstTeam;
            _secondTeam = secondTeam;
            _ball = ball;
        }
        private void DrawField(Graphics ctx, Field field)
        {
            var converter = new CoordinateConverter(_width, _height, field);

            using (var lineBrush = new SolidBrush(Color.White))
            using (var fieldBrush = new SolidBrush(Color.Green))
            using (var linePen = new Pen(lineBrush, 2))
            {
                // Field.
                ctx.FillRectangle(fieldBrush, 0, 0, _width, _height);
                ctx.DrawRectangle(
                    linePen,
                    converter.ToXpx(-field.Width / 2),
                    converter.ToYpx(field.Height / 2),
                    converter.ToX(field.Width),
                    converter.ToY(field.Height));

                // Middle lain.
                ctx.DrawLine(
                    linePen,
                    converter.ToXpx(0),
                    converter.ToYpx(field.Height / 2),
                    converter.ToXpx(0),
                    converter.ToYpx(-field.Height / 2));

                // Center circle.
                ctx.DrawEllipse(
                    linePen,
                    converter.ToXpx(-9.15),
                    converter.ToYpx(9.15),
                    converter.ToX(18.3),
                    converter.ToY(18.3));

                // Center spot.
                ctx.FillEllipse(lineBrush,
                    converter.ToXpx(-0.3),
                    converter.ToYpx(0.3),
                    converter.ToX(0.6),
                    converter.ToY(0.6));

                // Penalty circles.
                ctx.DrawEllipse(linePen,
                    converter.ToXpx(-field.Width / 2 + 11 - 9.15),
                    converter.ToYpx(9.15),
                    converter.ToX(18.3),
                    converter.ToY(18.3));
                ctx.DrawEllipse(linePen,
                    converter.ToXpx(field.Width / 2 - 11 - 9.15),
                    converter.ToYpx(9.15),
                    converter.ToX(18.3),
                    converter.ToY(18.3));

                // Penalty areas.
                ctx.FillRectangle(
                    fieldBrush,
                    converter.ToXpx(-field.Width / 2),
                    converter.ToYpx(20.15),
                    converter.ToX(16.5),
                    converter.ToY(40.3));
                ctx.DrawRectangle(
                    linePen,
                    converter.ToXpx(-field.Width / 2),
                    converter.ToYpx(20.15),
                    converter.ToX(16.5),
                    converter.ToY(40.3));
                ctx.FillRectangle(
                    fieldBrush,
                    converter.ToXpx(field.Width / 2 - 16.5),
                    converter.ToYpx(20.15),
                    converter.ToX(16.5),
                    converter.ToY(40.3));
                ctx.DrawRectangle(
                    linePen,
                    converter.ToXpx(field.Width / 2 - 16.5),
                    converter.ToYpx(20.15),
                    converter.ToX(16.5),
                    converter.ToY(40.3));

                // Penalty points.
                ctx.FillEllipse(lineBrush,
                    converter.ToXpx(-field.Width / 2 + 11),
                    converter.ToYpx(0.3),
                    converter.ToX(0.6),
                    converter.ToY(0.6));
                ctx.FillEllipse(lineBrush,
                    converter.ToXpx(field.Width / 2 - 11),
                    converter.ToYpx(0.3),
                    converter.ToX(0.6),
                    converter.ToY(0.6));

                // Goal areas.
                ctx.DrawRectangle(
                    linePen,
                    converter.ToXpx(-field.Width / 2),
                    converter.ToYpx(8.25),
                    converter.ToX(5.5),
                    converter.ToY(16.5));
                ctx.DrawRectangle(
                    linePen,
                    converter.ToXpx(field.Width / 2 - 5.5),
                    converter.ToYpx(8.25),
                    converter.ToX(5.5),
                    converter.ToY(16.5));

                // Goals.
                ctx.DrawRectangle(
                    linePen,
                    converter.ToXpx(-field.Width / 2 - field.GoalWidth),
                    converter.ToYpx(field.GoalHeight / 2),
                    converter.ToX(field.GoalWidth),
                    converter.ToY(field.GoalHeight));
                ctx.DrawRectangle(
                    linePen,
                    converter.ToXpx(field.Width / 2),
                    converter.ToYpx(field.GoalHeight / 2),
                    converter.ToX(field.GoalWidth),
                    converter.ToY(field.GoalHeight));

                // Corners.
                ctx.DrawArc(linePen,
                    converter.ToXpx(-field.Width / 2 - 1),
                    converter.ToYpx(field.Height / 2 + 1),
                    converter.ToX(2),
                    converter.ToY(2),
                    0,
                    90);
                ctx.DrawArc(linePen,
                    converter.ToXpx(field.Width / 2 - 1),
                    converter.ToYpx(field.Height / 2 + 1),
                    converter.ToX(2),
                    converter.ToY(2),
                    90,
                    90);
                ctx.DrawArc(linePen,
                    converter.ToXpx(field.Width / 2 - 1),
                    converter.ToYpx(-field.Height / 2 + 1),
                    converter.ToX(2),
                    converter.ToY(2),
                    180,
                    90);
                ctx.DrawArc(linePen,
                    converter.ToXpx(-field.Width / 2 - 1),
                    converter.ToYpx(-field.Height / 2 + 1),
                    converter.ToX(2),
                    converter.ToY(2),
                    270,
                    90);
            }
        }