A SoccerPitch is the main game object. It owns instances of two soccer teams, two goals, the playing area, the ball etc. This is the root class for all the game updates and renders etc
        public SoccerTeam(SoccerGoal homeGoal, SoccerGoal opponentsGoal, SoccerPitch pitch, SoccerTeamColor color)
        {
            _homeGoal = homeGoal;
            _opponentsGoal = opponentsGoal;
            _pitch = pitch;
            _color = color;

            _opposingTeam = null;
            _distSqToBallOfClosestPlayer = 0.0;
            _supportingPlayer = null;
            _controllingPlayer = null;
            _playerClosestToBall = null;

            _stateMachine = new StateMachine<SoccerTeam>(this);

            _stateMachine.CurrentState = DefendingState.Instance;
            _stateMachine.PreviousState = DefendingState.Instance;
            _stateMachine.GlobalState = null;

            //create the players and goalkeeper
            CreatePlayers();

            //set default steering behaviors
            foreach (PlayerBase player in _players)
            {
                player.SteeringBehaviors.Seperation = true;
            }

            _supportSpotCalculator = new SupportSpotCalculator(ParameterManager.Instance.NumSupportSpotsX, ParameterManager.Instance.NumSupportSpotsY, this);
        }
        private void gameLoop()
        {
            _soccerPitch = new SoccerPitch(pictureBox1.ClientRectangle.Width, pictureBox1.ClientRectangle.Height);

            _simulationStarted = true;

            PrecisionTimer timer = new PrecisionTimer(ParameterManager.Instance.FrameRate);

            while (!_stopEvent.WaitOne(0, true))
            {
                if (timer.ReadyForNextFrame() && !_simulationPaused)
                {
                    _soccerPitch.Update();
                }

                pictureBox1.Invalidate();
                Thread.Sleep(1);
            }

            _soccerPitch       = null;
            _simulationStarted = false;

            // a final call to repaint our current state
            pictureBox1.Invalidate();
        }
Beispiel #3
0
        public SoccerTeam(SoccerGoal homeGoal, SoccerGoal opponentsGoal, SoccerPitch pitch, SoccerTeamColor color)
        {
            _homeGoal      = homeGoal;
            _opponentsGoal = opponentsGoal;
            _pitch         = pitch;
            _color         = color;

            _opposingTeam = null;
            _distSqToBallOfClosestPlayer = 0.0;
            _supportingPlayer            = null;
            _controllingPlayer           = null;
            _playerClosestToBall         = null;

            _stateMachine = new StateMachine <SoccerTeam>(this);

            _stateMachine.CurrentState  = DefendingState.Instance;
            _stateMachine.PreviousState = DefendingState.Instance;
            _stateMachine.GlobalState   = null;

            //create the players and goalkeeper
            CreatePlayers();

            //set default steering behaviors
            foreach (PlayerBase player in _players)
            {
                player.SteeringBehaviors.Seperation = true;
            }

            _supportSpotCalculator = new SupportSpotCalculator(ParameterManager.Instance.NumSupportSpotsX, ParameterManager.Instance.NumSupportSpotsY, this);
        }
        private void gameLoop()
        {
            _soccerPitch = new SoccerPitch(pictureBox1.ClientRectangle.Width, pictureBox1.ClientRectangle.Height);

            _simulationStarted = true;

            PrecisionTimer timer = new PrecisionTimer(ParameterManager.Instance.FrameRate);
            while (!_stopEvent.WaitOne(0, true))
            {
                if (timer.ReadyForNextFrame() && !_simulationPaused)
                {
                    _soccerPitch.Update();
                }

                pictureBox1.Invalidate();
                Thread.Sleep(1);
            }

            _soccerPitch = null;
            _simulationStarted = false;

            // a final call to repaint our current state
            pictureBox1.Invalidate();
        }