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


Python Car.accelerate方法代码示例

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


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

示例1: test_check_distance_between_cars

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
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,代码行数:9,代码来源:car_test.py

示例2: test_car_slows_if_over_desired_speed

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
def test_car_slows_if_over_desired_speed():
    road = Road()
    car1 = Car(road, init_speed=100, desired_speed=30)
    car2 = Car(road, position=900)
    with mock.patch("random.random", return_value=1):
        # disable random braking
        car1.brake_if_needed(leading_car=car2)
    assert car1.speed == 30

    with mock.patch("random.random", return_value=0.05):
        # force random braking
        car1.brake_if_needed(leading_car=car2)
    assert car1.speed == 28

    car1.speed = 100
    car1.accelerate()
    assert car1.speed == 30
开发者ID:jwaldrep,项目名称:traffic-simulation,代码行数:19,代码来源:test_car.py

示例3: test_car_above_34

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
def test_car_above_34():
    my_car = Car()
    my_car.speed = 34
    my_car.accelerate()
    assert my_car.speed == 34
开发者ID:tshealy,项目名称:traffic-simulation,代码行数:7,代码来源:test_car.py

示例4: test_car_accelerate

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
def test_car_accelerate():
    my_car = Car()
    my_car.accelerate()
    assert my_car.speed == 2
开发者ID:tshealy,项目名称:traffic-simulation,代码行数:6,代码来源:test_car.py

示例5: test_car_accelerate

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
def test_car_accelerate():
    road = Road()
    car = Car(road)
    assert car.speed == 15
    car.accelerate()
    assert car.speed == 17
开发者ID:jwaldrep,项目名称:traffic-simulation,代码行数:8,代码来源:test_car.py

示例6: test_accelerate

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
def test_accelerate():
    car1 = Car(0)
    car2 = Car(50)
    car1.accelerate(car2)
    assert car1.acceleration == 2
    assert car1.velocity == 2
开发者ID:andrewmusicant,项目名称:road-rage,代码行数:8,代码来源:car_test.py

示例7: test_car_accelerates

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
def test_car_accelerates():
    car = Car()
    car.accelerate()
    assert car.speed == 2
开发者ID:jdhiggins,项目名称:traffic-simulation,代码行数:6,代码来源:car_test.py

示例8: test_car_can_not_go_faster_than_34

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
def test_car_can_not_go_faster_than_34():
    car = Car()
    car.speed = 33
    car.accelerate()
    assert car.speed == 34
开发者ID:jdhiggins,项目名称:traffic-simulation,代码行数:7,代码来源:car_test.py

示例9: system

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import accelerate [as 别名]
class GUI:
	"""works with the computer coordinate system (0/0 top left)"""

	def __init__ (self, width, heigth):
		self.width = width
		self.heigth = heigth
		self.windows = pygame.display.set_mode((width,heigth))
		pygame.display.set_caption("Neuro Junk 2012/13")
		self.outerPoly = [(110,215),(230,100),(400,150),(560,105),(650,180),(685,270),(710,400),(615,500),(510,545),(365,540),(315,480),(255,490),(185,540),(125,521),(90,420)]
		self.innerPoly = [(160,215),(230,150),(400,200),(540,155),(600,210),(625,275),(650,380),(600,440),(510,500),(370,480),(380,420),(260,430),(185,500),(150,480)]
		self.car = Car(1400,0.0,35.0,25.0,0.0,130.0,(120,215),0.0, 38.0, 90.0,(15,15),self.innerPoly, self.outerPoly) 
		#mass,acceleration,maxAcc,maxBreakingForce,currentSpeed,maxSpeed,pos,currentLock, maxLock, orientation, length, width
		self.colors = {'black':(0,0,0),'white':(255,255,255),'pink':(255,0,255)}
		self.screen = pygame.display.get_surface()
		self.drawStartUp()

	def drawStartUp(self):
		self.screen.fill(self.colors['white'])
		self.carRect = pygame.draw.rect(self.screen, self.colors['pink'], pygame.Rect(self.car.convertRealPositionToPc()[0], self.car.convertRealPositionToPc()[1], self.car.convertSizeFromMetersToPixel()[0], self.car.convertSizeFromMetersToPixel()[1]))#drawing the car
		#print "Start:"
		#print "pcx: " + str(self.car.convertRealPositionToPc()[0])
		#print "pcy: " + str(self.car.convertRealPositionToPc()[1])
		pygame.draw.polygon(self.screen, self.colors['black'], self.outerPoly,2)
		pygame.draw.polygon(self.screen, self.colors['black'], self.innerPoly,2)
		self.update()
		self.run()
		
	def update(self):
		self.screen.fill(self.colors['white'])
		pygame.draw.polygon(self.screen, self.colors['black'], self.outerPoly,2)
		pygame.draw.polygon(self.screen, self.colors['black'], self.innerPoly,2)
		self.carRect = pygame.draw.rect(self.screen, self.colors['pink'],pygame.Rect(self.car.convertRealPositionToPc()[0], self.car.convertRealPositionToPc()[1], self.car.convertSizeFromMetersToPixel()[0], self.car.convertSizeFromMetersToPixel()[1]))
		pygame.display.update()

	def drawLines(self,lines):
		for mt in lines:
			pygame.draw.line(self.screen, self.colors['black'], mt[0], mt[1],5)
		pygame.display.update()

	def displayInfo(self):
		pygame.font.init()
		font = pygame.font.SysFont("Ubuntu",15)
		test = font.render("Speed: " + str(self.car.currSpeed),1,(255,0,0))
		self.screen.blit(test, (100,100))
		

	def input(self,events):
		for event in events:
			if event.type == QUIT:
				sys.exit(0)
			elif event.type == KEYDOWN and event.key == 113: #Q
				sys.exit(0)
			elif event.type == KEYDOWN and event.key == 273: #Arrow_UP
				self.car.accelerate(1.0)
				#print self.car.currSpeed
			elif event.type == KEYUP and event.key == 273:
				self.car.accelerate(0.0)
			elif event.type == KEYDOWN and event.key == 274: #Arrow_Down
				self.car.retarding(1.0)
			elif event.type == KEYUP and event.key == 274:
				self.car.retarding(0.0)
			elif event.type == KEYDOWN and event.key == 275: #Arrow_right
				self.car.stiring(-0.25)
			elif event.type == KEYUP and event.key == 275:
				self.car.stiring(0.0)
			elif event.type == KEYDOWN and event.key == 276: #Arrow_left
				self.car.stiring(0.25)
			elif event.type == KEYUP and event.key == 276:
				self.car.stiring(0.0)
			elif event.type == KEYDOWN and event.key == K_SPACE:
				self.car.currSpeed = 0.0
				self.car.acceleration = 0.0
			else:
				pass

	def run(self):
		lines = []
		while True:
			self.input(pygame.event.get())
			mt = self.car.nextPos(0.01)
			self.update()
			#print "mt: " + str(mt)
			#lines.append(mt)
			#self.drawLines(lines)
			time.sleep(0.01)
开发者ID:barzuln,项目名称:junkie,代码行数:87,代码来源:gui.py


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