当前位置: 首页>>代码示例>>Python>>正文


Python car.Car类代码示例

本文整理汇总了Python中car.Car的典型用法代码示例。如果您正苦于以下问题:Python Car类的具体用法?Python Car怎么用?Python Car使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Car类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update_position

def test_update_position():
    road = Road()
    car = Car(road, init_speed=10)
    car2 = Car(road, position=500)
    assert car.position == 0 and car.speed == 10
    car.update_position(car2)
    assert car.position == 0 + car.speed * car.s_per_step
开发者ID:jwaldrep,项目名称:traffic-simulation,代码行数:7,代码来源:test_car.py

示例2: TestCar

class TestCar(unittest.TestCase):

    def setUp(self):
        self.car = Car('VW', 'Passat', 150)
        self.crash_chance = 1.25
        self.laps = 5

    def test_car__str__(self):
        result = "VW Passat with max max speed 150"
        self.assertEqual(str(self.car), result)

    def test_car__int__(self):
        self.assertEqual(int(self.car), 100)

    def test_car_model(self):
        self.assertEqual(self.car.model, 'Passat')

    def test_car___exhaustion(self):
        # (max speed / depreciation) * laps * crash_chance
        exhaustion = (self.car.max_speed / self.car._depreciation) * self.crash_chance
        self.assertEqual(self.car._Car__exhaustion(self.crash_chance), exhaustion)

    def test_car___stamina(self):
        exhaustion = (self.car.max_speed / self.car._depreciation) * self.crash_chance
        self.assertEqual(self.car._Car__stamina(self.crash_chance), 100 - exhaustion)
开发者ID:jokuf,项目名称:Python-101,代码行数:25,代码来源:test_car.py

示例3: test_car_is_validating_position_with_road

def test_car_is_validating_position_with_road():
    # On init
    road = Road()
    car1 = Car(road, position=2000)
    assert car1.position == 0

    # In update_position
    car1 = Car(road, position=100, init_speed=10)
    car2 = Car(road, position=500)
    car1.position = 1000
    car1.update_position(car2)
    assert car1.position == 10

    # In brake_if_needed
    car1 = Car(road, position=1005, init_speed=10)
    car2 = Car(road, position=10)
    did_brake = car1.brake_if_needed(leading_car=car2)
    assert did_brake is True

    with mock.patch("random.random", return_value=1):
        car1 = Car(road, position=500, init_speed=10)
        car2 = Car(road, position=0)
        did_brake = car1.brake_if_needed(leading_car=car2)
        assert did_brake is False

    assert car1.distance_behind(car2) == 495
开发者ID:jwaldrep,项目名称:traffic-simulation,代码行数:26,代码来源:test_car.py

示例4: runGame

def runGame():
    # Initialize game, settings and screen object
    pygame.init()
    drSettings = Settings()
    screen = pygame.display.set_mode(
        (drSettings.screenWidth, drSettings.screenHeight))
    pygame.display.set_caption("Drag Race")
    totalTime = 0

    # Make the car
    car = Car(drSettings, screen)

    # Initialize the timer, gear text and speed
    hud = HeadUpDisplay(drSettings, screen, totalTime, car) 

    # Store the game statistics
    stats = GameStats()

    # Start the main loop for the game
    while True:
        # Check for keypresses
        gf.checkEvents(car, stats)

        # Update the game active state
        if not car.onScreen:
            stats.gameActive = False

        if stats.gameActive:
            # Update the position of the car and the hud
            car.update() 
            hud.update(stats.totalTime, car)
            stats.totalTime += drSettings.timeIncrement

        # Update the screen
        gf.updateScreen(drSettings, screen, car, hud)
开发者ID:AdamD2,项目名称:drag-race,代码行数:35,代码来源:dragRace.py

示例5: main

def main():
    # create an instance of a Car with an initial fuel value of 100
    car = Car(100)
    
    print("Let's drive!")
    print(car)
    print(MENU)
    choice = input("Enter your choice: ").lower()
    while choice != "q":
        if choice == "d":
            distanceToDrive = int(input("How many km do you wish to drive? "))
            distanceDriven = car.drive(distanceToDrive)
            print("The car drove " + str(distanceDriven) + "km", end="")
            if car.getFuel() == 0:
                print(" and ran out of fuel", end="")
            print(".")
        elif choice == "r":
            fuelToAdd = int(input("How many units of fuel do you want to add to the car? "))
            while fuelToAdd < 0:
                print("Fuel amount must be >= 0")
                fuelToAdd = int(input("How many units of fuel do you want to add to the car? "))
            car.addFuel(fuelToAdd)
            print("Added", fuelToAdd, "units of fuel.")
        else:
            print("Invalid choice")
        print()
        print(car)
        print(MENU)
        choice = input("Enter your choice: ").lower()
    print("\nGood bye!")
开发者ID:AlexCSilva,项目名称:CP1200Practicals2015,代码行数:30,代码来源:prac10Classes.py

示例6: sort_with_connect

def sort_with_connect(fname):
    """Sort the atoms: gather the same atoms, and atoms in same
    molecules according to connectivity (.mdf). This is very good 
    for generating gromacs input files, and organize the atoms into 
    a well defined order.
    """
    mdffile = "%s.mdf" % fname
    carfile = "%s.car" % fname
    mdf = Mdf(mdffile)
    car = Car(carfile)
    a = car.parser()
    Li = []
    Ge = []
    P = []
    atom_names = mdf.atom_names
    for i in range(len(mdf.atoms)):
        if mdf.atoms[i].element == "Li":
            Li.append(i)
        elif mdf.atoms[i].element == "Ge":
            Ge.append(i)
            for j in mdf.atoms[i].connect:
                Ge.append(atom_names.index(j))
        elif mdf.atoms[i].element == "P":
            P.append(i)
            for j in mdf.atoms[i].connect:
                P.append(__get_index(atom_names, j))
    seq_new = Li + Ge + P
    a.sortNdx(seq_new)
    toPdb(a)
开发者ID:karthipitt,项目名称:simpy,代码行数:29,代码来源:e_2_car.py

示例7: limo

def limo():
    limo=Car(100,"limo")
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
    print(limo)
开发者ID:alvinyeonata,项目名称:CP1404,代码行数:7,代码来源:usedcars.py

示例8: test_check_distance_between_cars

def test_check_distance_between_cars():
    car1 = Car(0)
    car2 = Car(9)
    car1.accelerate(car2)
    assert car1.velocity == 2
    car1.accelerate(car2)
    assert car1.velocity == 0
开发者ID:andrewmusicant,项目名称:road-rage,代码行数:7,代码来源:car_test.py

示例9: main

def main():
    limo = Car(100,  "abc")
    limo.add_fuel(20)
    print("fuel = ", limo.fuel)
    limo.drive(115)
    print("odometer = ", limo.odometer)
    print(limo)
开发者ID:rohitchahal,项目名称:classes,代码行数:7,代码来源:modifiedcars.py

示例10: test

def test():

    #connection = DBConnection()
    #connection.connectToDB()

    localdbConnection = SQLLite("Resources/WideAwakeCoordinates.db")
    localdbConnection.establishConnection()

    car = Car()

    while(car.next()):
        if(car.ABS):
            try:
                #Should eventually change query to something else
                date = datetime.datetime.now()
                print(type(car.long[1]))
                #inserts a testuserID, testcarID, weather_condition, coordinates as a timestamp and the current date and time. This is a temporary query and may be subject to change
                queryToDB = "(INSERT INTO Coordinates(Latitude, longitude, timestamp) VALUES ( + n\
                %s, %s, %s )) "
                (car.lat[0] ,car.long[0] , date.strftime( "%m/%d/%y/%H/%M/%S"))
                localdbConnection.executeInsertStatement(queryToDB)
                print("Complete query")
            except Exception as e:
                print(str(e))
                raise e
开发者ID:kristhaj,项目名称:WideAwake,代码行数:25,代码来源:ABStest.py

示例11: main

def main():
    limo = Car("limo", 180)
    limo.add_fuel(30)
    limo.drive(115)

    print("limo odometer", limo.odometer)
    print("limo fuel:", limo.fuel)
    print("{}, fuel={}, odometer={}".format(limo.name, limo.fuel, limo.odometer))
开发者ID:MatthewChilcott,项目名称:1404_pracs,代码行数:8,代码来源:usedcars.py

示例12: test_accel_and_decel_are_mutually_exclusive

def test_accel_and_decel_are_mutually_exclusive():
    road = Road()
    for _ in range(100):
        with mock.patch("random.random", return_value=1):
            car1 = Car(road, position=200, init_speed=10)
            car2 = Car(road, position=400)
            car1.step_speed(car2)
            assert car1.speed == 12 or car1.speed == 8
开发者ID:jwaldrep,项目名称:traffic-simulation,代码行数:8,代码来源:test_car.py

示例13: test_brake_if_needed

def test_brake_if_needed():
    # Stop if collision imminent
    road = Road()
    car1 = Car(road, position=200, init_speed=20)
    car2 = Car(road, position=210)
    with mock.patch("random.random", return_value=1):
        did_brake = car1.brake_if_needed(leading_car=car2)
    assert did_brake is True
    assert car1.speed == 5
开发者ID:jwaldrep,项目名称:traffic-simulation,代码行数:9,代码来源:test_car.py

示例14: __init__

	def __init__(self):
		super(MirrorMan, self).__init__('Mirror Man', MirrorMan.PURPLE)
		self.gameover = False
		self.win = False
		self.player = Player((random.randint(50,750), 10))
		self.car = Car(0, 125, 'yellow')
		self.car2 = Car(800, 225, 'red')
		self.car3 = Car(-100, 325, 'yellow')
		self.car4 = Car(900, 425, 'red')
开发者ID:Teevarapat,项目名称:Mirror-Man-,代码行数:9,代码来源:main.py

示例15: test_check_position_good

def test_check_position_good():
    test_car = Car(1)
    test_car.speed = 5
    test_car_two = Car(30)
    assert test_car.car_coordinates[-1] == 5
    assert test_car.speed == 5
    test_car.check_position(test_car_two)
    assert test_car.car_coordinates[-1] == 5
    assert test_car.speed == 5
开发者ID:gregajohnston,项目名称:traffic-simulation,代码行数:9,代码来源:tests.py


注:本文中的car.Car类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。