示例#1
0
        void Start()
        {
            instance       = this;
            sentResult     = false;
            timeText.text  = "X";
            speedText.text = "X";
            errorText.text = "";
            sentResult     = false;
            Time.timeScale = 1f;

            Track  track  = StartScreen.tracks [StartScreen.trackNumber];
            string script = StartScreen.script;

            isTrial = StartScreen.isTrial;
            timer   = 0;

            if (isTrial)
            {
                // generate car object
                stats = new RaceStats();
                TrialRacer racer = new TrialRacer(script, track, stats);
                racers = new Racer[] { racer };
            }
            else
            {
                int    noRacers     = StartScreen.noRacers;
                string secondscript = StartScreen.secondscript;
                racers = new Racer[noRacers * 2];
                for (int x = 0; x < noRacers * 2; x++)
                {
                    racers [x] = new Racer(x, x % 2 == 0 ? script : secondscript, track);
                }
            }
        }
示例#2
0
    public static bool IsOpponentInFront(RaceStats opponentCar, RaceStats thisCar)
    {
        bool opponentIsInFrontOnDifferentLap    = opponentCar.Laps > thisCar.Laps;
        bool opponentHasHigherCheckpointTarget  = opponentCar.TargetCheckpoint > thisCar.TargetCheckpoint;
        bool opponentIsCloserToCheckpointTarget = opponentCar.DistanceToTargetCheckpoint < thisCar.DistanceToTargetCheckpoint;

        bool opponentIsOnTheSameLap             = opponentCar.Laps == thisCar.Laps;
        bool opponentHasTheSameCheckpointTarget = opponentCar.Laps == thisCar.Laps;

        if (opponentIsInFrontOnDifferentLap)
        {
            return(true);
        }

        if (opponentIsOnTheSameLap)
        {
            if (opponentHasHigherCheckpointTarget)
            {
                return(true);
            }

            if (opponentHasTheSameCheckpointTarget)
            {
                if (opponentIsCloserToCheckpointTarget)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
示例#3
0
    public override void EnterAction(RaceStats _stats)
    {
        base.EnterAction (_stats);

        if(_stats.lastWaypoint == this){
            RaceManager.instance.CompletedLap(_stats.racerID);
            _stats.lastWaypoint = null;
        }
    }
示例#4
0
    private void UpdateRaceStats()
    {
        var raceStats = new RaceStats(
            _currentLap,
            _targetCheckpointNumber,
            _checkpointNodes.Count,
            _distanceToTargetCheckpoint);

        Lap = _currentLap;
        CheckpointTarget     = _targetCheckpointNumber;
        DistanceToCheckpoint = _distanceToTargetCheckpoint;

        RaceStats = raceStats;
    }
示例#5
0
        public RaceStats GetRaceStats()
        {
            var raceStats = new RaceStats
            {
                NumberEntrants             = GetRunners().Count(),
                NumberMaleEntrants         = GetRunners().Count(r => r.Gender == GenderEnum.Male),
                NumberFemaleEntrants       = GetRunners().Count(r => r.Gender == GenderEnum.Female),
                NumberFinishers            = GetFinishers().Count(),
                NumberMaleFinishers        = GetFinishers().Count(f => f.Gender == GenderEnum.Male),
                NumberFemaleFinishers      = GetFinishers().Count(f => f.Gender == GenderEnum.Female),
                NumberAffiliatedEntrants   = GetRunners().Count(r => !string.IsNullOrEmpty(r.Club.Trim())),
                NumberUnaffiliatedEntrants = GetRunners().Count(r => string.IsNullOrEmpty(r.Club.Trim())),
            };

            return(raceStats);
        }
示例#6
0
    public virtual void EnterAction(RaceStats _stats)
    {
        if(_stats != null){

            if(_stats.currentWaypoint == this){
                _stats.lastWaypoint = _stats.currentWaypoint;
                _stats.currentWaypoint = nextWaypoint;

                _stats.waypointScore ++;

                RaceManager.instance.RecalculateRankings();

            }
        }else{
            Debug.LogWarning("No RaceStats!");
        }
    }
示例#7
0
        public void ShouldBeBehindOpponentWhenOpponentHasPassedCheckerPriorToFirstLapAndDriverHasNot()
        {
            var opponentDriver = new RaceStats(
                ZERO_LAPS_ELAPSED_PASSED_CHECKER_FLAG,
                TARGET_CHECKPOINT_TWO,
                TOTAL_CHECKPOINTS,
                NEAR_TARGET_CHECKPOINT);

            var testDriver = new RaceStats(
                ZERO_LAPS_ELAPSED,
                TARGET_CHECKPOINT_TWO,
                TOTAL_CHECKPOINTS,
                NEAR_TARGET_CHECKPOINT);

            bool shouldBeTrue = RaceHelperFuntions.IsOpponentInFront(opponentDriver, testDriver);

            Assert.IsTrue(shouldBeTrue);
        }
示例#8
0
        public void ShouldBeInfrontOfOpponentOnFirstLap()
        {
            var opponentDriver = new RaceStats(
                ZERO_LAPS_ELAPSED,
                TARGET_CHECKPOINT_TWO,
                TOTAL_CHECKPOINTS,
                NEAR_TARGET_CHECKPOINT);

            var testDriver = new RaceStats(
                ZERO_LAPS_ELAPSED,
                TARGET_CHECKPOINT_TREE,
                TOTAL_CHECKPOINTS,
                NEAR_TARGET_CHECKPOINT);

            bool shouldBeFalse = RaceHelperFuntions.IsOpponentInFront(opponentDriver, testDriver);

            Assert.IsFalse(shouldBeFalse);
        }
示例#9
0
        public void ShouldInCorrectOrder()
        {
            var inFirstPositionDriver = new RaceStats(
                ZERO_LAPS_ELAPSED_PASSED_CHECKER_FLAG,
                TARGET_CHECKPOINT_TREE,
                TOTAL_CHECKPOINTS,
                FIRST_POSITION_DISTANCE_TO_CHECKPOINT);

            var inSecondPositionDriver = new RaceStats(
                ZERO_LAPS_ELAPSED_PASSED_CHECKER_FLAG,
                TARGET_CHECKPOINT_TWO,
                TOTAL_CHECKPOINTS,
                SECOND_POSITION_DISTANCE_TO_CHECKPOINT);

            var inThirdPositionDriver = new RaceStats(
                ZERO_LAPS_ELAPSED_PASSED_CHECKER_FLAG,
                TARGET_CHECKPOINT_TWO,
                TOTAL_CHECKPOINTS,
                THIRD_POSITION_DISTANCE_TO_CHECKPOINT);



            bool firstShouldBeInFrontOfSecond = RaceHelperFuntions.IsOpponentInFront(inFirstPositionDriver, inSecondPositionDriver);
            bool firstShouldBeInFrontOfThird  = RaceHelperFuntions.IsOpponentInFront(inFirstPositionDriver, inThirdPositionDriver);

            bool secondShouldBeInFrontOfThrid = RaceHelperFuntions.IsOpponentInFront(inSecondPositionDriver, inThirdPositionDriver);

            bool thirdShouldBeBehindFirst  = RaceHelperFuntions.IsOpponentInFront(inFirstPositionDriver, inThirdPositionDriver);
            bool thirdShouldBeBehindSecond = RaceHelperFuntions.IsOpponentInFront(inSecondPositionDriver, inThirdPositionDriver);

            Assert.IsTrue(firstShouldBeInFrontOfSecond);
            Assert.IsTrue(firstShouldBeInFrontOfThird);
            Assert.IsTrue(secondShouldBeInFrontOfThrid);

            Assert.IsTrue(thirdShouldBeBehindFirst);
            Assert.IsTrue(thirdShouldBeBehindSecond);
        }
示例#10
0
 public TrialRacer(string script, Track track, RaceStats stats) : base(-1, script, track)
 {
     this.stats = stats;
 }
示例#11
0
        public IHttpActionResult GetRaceStatus(int id)
        {
            RaceStats vehicle = _leaderboardService.GetRaceStats(id);

            return(OkOrNotFound(vehicle));
        }