示例#1
0
        private void PeformsPaddleMove(Paddle paddle, IPongBotAbility ability, PongEnvironmentContext context)
        {
            var move = ability.MovePaddle(context);

            if (move == PaddleMoveDirection.Down)
            {
                if (paddle.Y + paddle.Height + 1 < TableSize.Height)
                {
                    paddle.Y += paddle.SpeedY;
                }
            }
            else if (move == PaddleMoveDirection.Up)
            {
                if (paddle.Y - 1 > 0)
                {
                    paddle.Y -= paddle.SpeedX;
                }
            }
        }
示例#2
0
        public override void InitializeRound(IWorldContext context)
        {
            var bots = context.GetBotsWithKindOfAbility <IPongBotAbility>();

            ResetBallPosition();

            m_leftPaddleBot                 = bots[0];
            m_leftPaddleBotAbility          = (IPongBotAbility)context.GetBotAbility <IPongBotAbility>(m_leftPaddleBot);
            m_leftPaddleContext             = new PongEnvironmentContext();
            m_leftPaddleContext.TableWidth  = TableSize.Width;
            m_leftPaddleContext.TableHeight = TableSize.Height;

            m_rightPaddleBot                 = bots[1];
            m_rightPaddleBotAbility          = (IPongBotAbility)context.GetBotAbility <IPongBotAbility>(m_rightPaddleBot);
            m_rightPaddleContext             = new PongEnvironmentContext();
            m_rightPaddleContext.TableWidth  = TableSize.Width;
            m_rightPaddleContext.TableHeight = TableSize.Height;

            LeftPaddle  = new Paddle(m_leftPaddleBot, 2, (TableSize.Height / 2) - (PaddleHeight / 2), PaddleWidth, PaddleHeight);
            RightPaddle = new Paddle(m_rightPaddleBot, TableSize.Width - LeftPaddle.Width - 2, LeftPaddle.Y, PaddleWidth, PaddleHeight);

            m_leftPaddleBotAbility.Initialize(m_leftPaddleContext);
            m_rightPaddleBotAbility.Initialize(m_rightPaddleContext);
        }