示例#1
0
        public void Should_Not_Release_ParkingSpace_And_Return_Unavailable()
        {
            var parkingSpace = new ParkingSpace(ParkingSpaceType.Car);

            parkingSpace.Occupy(2);

            Assert.False(parkingSpace.IsAvailable());
        }
示例#2
0
        public void Should_Occupy_ParkingSpace_And_Then_Be_Not_Available()
        {
            var parkingSpace = new ParkingSpace(ParkingSpaceType.Car);

            parkingSpace.Occupy(2);

            Assert.False(parkingSpace.IsAvailable());
        }
示例#3
0
        public void Should_Release_ParkingSpace_And_Then_Be_Available()
        {
            var parkingSpace = new ParkingSpace(ParkingSpaceType.Car);

            parkingSpace.Occupy(2);
            parkingSpace.Release();

            Assert.True(parkingSpace.IsAvailable());
        }
示例#4
0
        public void Should_Calculate_Time_Spent_On_ParkingSpace()
        {
            var parkingSpace = new ParkingSpace(ParkingSpaceType.Car);

            parkingSpace.Occupy(2);
            Thread.Sleep(2000); //2seg
            parkingSpace.Release();

            var expected = (double)2000 / 60000; //ms to min

            Assert.Equal(expected.ToString("0.##"),
                         parkingSpace.CalculateTimeSpent().ToString("0.##"));
        }
示例#5
0
    void EndActiveTrip()
    {
        ActiveTrip.completed = true;
        TripInProgress       = false;
        controlledCar.GoToState(Car.CarState.waiting);

        switch (ActiveTrip.type)
        {
        case Trip.TripType.Park: {
            ParkingSpace s = ((ParkingSpotRoad)ActiveTrip.end).GetEmptySpace();
            //Reserve the parking space
            s.Occupy();
            parkedAt = s;
            state    = State.parked;

            controlledCar.Park(s);
            break;
        }

        case Trip.TripType.Charge: {
            PowerStationRoad s = world.FindNearestPoweredPowerstation(controlledCar.transform.position.ToVector2());
            if (s == null)
            {
                Debug.LogError("No power stations! Handle that.");
            }
            PowerStation ps = s.GetEmptyPoweredStation();
            //no empty station available
            //this is actually obsolete.
            if (ps == null)
            {
                Debug.LogError("All stations full (handled in coroutine.)!");
            }
            else
            {
                chargingAt = ps;
                ps.Occupy();
            }

            charging = true;
            state    = State.charging;

            controlledCar.Recharge(chargingAt);
            return;
        }

        case Trip.TripType.Cruise: {
            state = State.enRoute;
            break;
        }
        }

        //Create next journey
        CreateJourney();
        if (ActiveTrip == null)
        {
            Finished = true;
            Game.Instance.OnCarFinished(controlledCar);
            return;
        }
        SetWakeUp(ActiveTrip.departure);
    }