public GamePosition Step(GamePosition currentPosition, GameAction gameAction)
        {
            var newFirstTeamPosition = GetNewTeamPosition(currentPosition.FirstTeamPosition, gameAction.FirstTeamAction);
            var newSecondTeamPosition = GetNewTeamPosition(currentPosition.SecondTeamPosition, gameAction.SecondTeamAction);
            var newBallPosition = GetNewBallPosition(currentPosition.BallPosition);

            return new GamePosition(currentPosition.Field, newFirstTeamPosition, newSecondTeamPosition, newBallPosition);
        }
Example #2
0
        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 Bitmap Draw(GamePosition position)
        {
            var bitmap = new Bitmap(_width, _height);

            using (Graphics ctx = Graphics.FromImage(bitmap))
            using (Pen firstTeamPen = new Pen(Color.Red))
            using (Pen secondTeamPen = new Pen(Color.Green))
            {
                // TODO: cache field
                DrawField(ctx, position.Field);

                DrawCommands(ctx, firstTeamPen, position.FirstTeamPosition);
                DrawCommands(ctx, secondTeamPen, position.FirstTeamPosition);
            }

            return bitmap;
        }
Example #4
0
        public void Run()
        {
            BallPosition ballPosition = InitBallPosition(_ball);
            TeamPosition firstTeamPosition = InitTeamPosition(_firstTeam);
            TeamPosition secondTeamPosition = InitTeamPosition(_secondTeam);
            GamePosition currentPosition = new GamePosition(_field, firstTeamPosition, secondTeamPosition, ballPosition);

            while (true)
            {
                IGameState gameState = _gameStateBuilder.BuildState(currentPosition);

                TeamAction firstTeamAction = BuildTeamAction(_firstTeam, gameState);
                TeamAction secondTeamAction = BuildTeamAction(_secondTeam, gameState);
                GameAction gameAction = new GameAction(firstTeamAction, secondTeamAction);

                GamePosition nextPosition = _runner.Step(currentPosition, gameAction);
                if (nextPosition == null)
                    break;

                currentPosition = nextPosition;
            }
        }