本文整理汇总了Python中ship.Ship类的典型用法代码示例。如果您正苦于以下问题:Python Ship类的具体用法?Python Ship怎么用?Python Ship使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ship类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run_game
def run_game():
#Initialize pygame, settings and screen object
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
#Make the play button
play_button = Button(ai_settings, screen, "Play")
#Create a GameStats instance to store game statistics
stats = GameStats(ai_settings)
#Make a ship, a group of bullets, and a group of aliens
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
#Create the fleet of aliens
gf.create_fleet(ai_settings, screen, ship, aliens)
#Start the main loop of the game
while True:
gf.check_events(ai_settings, screen, stats, play_button, ship, aliens, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets, play_button)
开发者ID:starkey9000,项目名称:alien-invasion,代码行数:32,代码来源:alien_invasion.py
示例2: run_game
def run_game():
#Initialize pygame, settings, screen and screen object
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
#make ship
ship = Ship(ai_settings ,screen)
#Make a group to store bullets in
bullets = Group()
#Make an alien group
aliens = Group()
#Make play button
play_button = Button(ai_settings, screen, "Play")
#Create fleet of aliens
gf.create_fleet(ai_settings, screen, ship, aliens)
#Create instance to store game statistics and create scoreboard
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings, screen, stats)
#Start main loop for game
while True:
#Watch for keyboard/mouse events
gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
#Redraw the screen during each pass through the loop
gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
开发者ID:JT1991,项目名称:Code,代码行数:34,代码来源:alien_invasion.py
示例3: run_game
def run_game():
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# make a ship
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
alien = Alien(ai_settings, screen)
gf.create_fleet(ai_settings, screen, aliens)
while True:
gf.check_events(ai_settings, screen, ship, bullets)
ship.update()
gf.update_bullets(bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
bullets.update()
# Get rid of bullets that have disappeared.
for bullet in bullets.copy():
if bullet.rect.bottom <= 0:
bullets.remove(bullet)
print(len(bullets))
开发者ID:painandmemesery,项目名称:alien_invasion,代码行数:25,代码来源:alien+invasion.py
示例4: run_game
def run_game():
#Initializes the settings needed for pygame to run properly
pygame.init()
aiSettings = Settings()
#Display mode called 'screen' is made, with 1200 x 800 dimensions
#Screen is where the game elements are shown
screen = pygame.display.set_mode(
(aiSettings.screen_width,aiSettings.screen_height))
pygame.display.set_caption("Alien Invasion")
#Sets background colour
stats = GameStats(aiSettings)
#Makes a ship on screen
ship = Ship(aiSettings,screen)
#Bullets! - make a group called bullets
bullets = Group()
#Aliens are made
aliens = Group()
#Calls on the createFleet function
gf.createFleet(aiSettings, screen, ship, aliens)
while True:
gf.check_events(aiSettings,screen,ship,bullets)
if stats.game_active:
ship.update()
gf.updateBullets(aiSettings, screen, ship, aliens, bullets)
gf.updateAliens(aiSettings, stats, screen, ship, aliens, bullets)
gf.update_screen(aiSettings, screen, ship, aliens, bullets)
开发者ID:ndpark,项目名称:alienInvasion,代码行数:33,代码来源:alien_invasion.py
示例5: run_game
def run_game():
#初始化游戏并创建一个屏幕对象
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height) )
pygame.display.set_caption("Alien Invasion")
#创建Play按钮
play_button = Button(ai_settings,screen, "Play")
#创建一个用于存储游戏统计信息的实例,并创建计分牌
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings,screen,stats)
#创建一艘飞船
ship = Ship(ai_settings, screen)
#创建一个用于存储子弹的编组
bullets = Group()
#创建一个用于存储外星人的编组
aliens = Group()
#创建外星人群
gf.create_fleet(ai_settings,screen,ship,aliens)
#开始游戏的主循环
while True:
#监视键盘和鼠标事件
gf.check_events(ai_settings,screen,stats,sb, play_button,ship,aliens,bullets)
#根据移动标志调整飞船的位置
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings,screen,stats,sb,ship,aliens,bullets)
gf.update_aliens(ai_settings,stats,screen,sb,ship,aliens,bullets)#更新子弹后再更新外星人位置,因为稍后要检查子弹是否撞到外星人
#更新屏幕上的图像,并切换到新屏幕
gf.update_screen(ai_settings,screen,stats,sb,ship,aliens,bullets,play_button)
开发者ID:Rocky0429,项目名称:python_easy_projects,代码行数:35,代码来源:alien_invation.py
示例6: run_game
def run_game():
# Initialize pygame, settings and screen object.
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Snoopvasion")
# Create an instance to store game statistics.
stats = GameStats(ai_settings)
# Make a ship.
ship = Ship(ai_settings, screen)
# Make a group to store bullets in
bullets = Group()
aliens = Group()
# Create the fleet of aliens.
gf.create_fleet(ai_settings, screen, ship, aliens)
# Start the main loop for the game.
while True:
gf.check_events(ai_settings, screen, ship, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
开发者ID:nikolajlauridsen,项目名称:Snoopvasion,代码行数:31,代码来源:snoopvasion.py
示例7: run_game
def run_game():
# initialize game and create a screen object.
# initialize pygame, settings, and screen object>
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("alien ivasion")
# make a ship.
ship = Ship(ai_settings, screen)
# start the main loop for the game.
while True:
gf.check_events(ship)
ship.update()
gf.update_screen(ai_settings, screen, ship)
# redraw the screen during each pass through the loop.
screen.fill(ai_settings.bg_color)
ship.blitme()
# make the most recently drawn screen visible.
pygame.display.flip()
开发者ID:AlanArvizu739,项目名称:alienivasion,代码行数:26,代码来源:alien_invasion.py
示例8: populate_bg
def populate_bg(self, bg):
"""
Populate a battleground with random ships.
:param bg: the battleground to populate
"""
it = SHIP_LENS.__iter__()
ship_len = it.next()
while True:
#for ship_len in SHIP_LENS:
ship = Ship(ship_len)
direction = random.randint(0, 1) # 0 = vertical, 1 = horizontal
if direction == 0:
start_x = random.randint(0, NUM_SQUARES - 1)
start_y = random.randint(0, NUM_SQUARES - 1 - ship_len)
elif direction == 1:
start_x = random.randint(0, NUM_SQUARES - 1 - ship_len)
start_y = random.randint(0, NUM_SQUARES - 1)
squares = []
for i in xrange(ship_len):
if direction == 0:
squares.append(Square(start_x, start_y + i, SquareState.intact))
elif direction == 1:
squares.append(Square(start_x + i, start_y, SquareState.intact))
ship.squares = squares
if bg.check_intersect(ship):
continue
bg.add_ship(ship)
# Python's fucked up way to check if an iterator reached the end of a container
try:
ship_len = it.next()
except:
break
开发者ID:rakibuiu,项目名称:battleship-leap-python,代码行数:35,代码来源:main.py
示例9: run_game
def run_game():
#inits game and creates a screen object.
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
#Make the Play Button
play_button = Button(ai_settings, screen, "Play")
#Create an instance to store game stats and create a scoreboard
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings, screen, stats)
#make a ship
ship = Ship(ai_settings, screen)
#Make a group to store bullets in.
bullets = Group()
#make an alien.
aliens = Group()
#Creating a fleet of aliens
gf.create_fleet(ai_settings, screen, ship, aliens)
#Start the main loop for the game.
while True:
gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, screen, sb, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
开发者ID:ravenusmc,项目名称:AlienInvasion,代码行数:35,代码来源:game.py
示例10: run_game
def run_game():
"""运行游戏"""
# 初始化游戏并创建一个屏幕对象
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption(ai_settings.title)
ship = Ship(screen)
# 开始游戏的主循环
while True:
# 监视键盘和鼠标事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
screen.fill(ai_settings.bg_color)
ship.blitme()
# 让最近回执的屏幕可见
pygame.display.flip()
开发者ID:gitxw,项目名称:PythonStudy,代码行数:25,代码来源:alien_invasion.py
示例11: run_game
def run_game():
pygame.init()
ai_settings = Settings()
""" Screen settings and such"""
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
stats = GameStats(ai_settings)
bg_color = (230, 230, 230)
"""background screen color; grey"""
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
gf.create_fleet(ai_settings, screen, ship, aliens)
while True:
gf.check_events(ai_settings, screen, ship, bullets)
ship.update()
gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
for bullet in bullets.copy():
if bullet.rect.bottom <= 0:
bullets.remove(bullet)
print(len(bullets))
开发者ID:MasonWhite000,项目名称:AlienInvasion,代码行数:31,代码来源:Alien_Invasion.py
示例12: run_game
def run_game():
# 初始化游戏并创建一个屏幕对象
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# 创建一艘飞船
ship = Ship(ai_settings, screen)
# 创建一个用于存储子弹的编组
bullets = Group()
# 创建一个外星人编组
aliens = Group()
# 创建外星人群
gf.create_fleet(ai_settings, screen, aliens)
# 开始游戏的主循环
while True:
# 监视键盘和鼠标事件
gf.check_events(ai_settings, screen, ship, bullets)
ship.update()
gf.update_bullets(bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
开发者ID:gzzwinner,项目名称:alien_invasion,代码行数:27,代码来源:alien_invasion.py
示例13: run_game
def run_game():
"""初始化pygame、设置和屏幕对象"""
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# 创建button按钮
play_button = Button(ai_settings, screen, "Play")
# 创建存储游戏统计信息的实例,并创建记分牌
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings, screen, stats)
# 创建一艘飞船、一个子弹编组和一个外星人编组
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
# 创建外星人群
gf.create_fleet(ai_settings, screen, ship, aliens)
# 开始游戏主循环
while True:
gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
开发者ID:mg2723,项目名称:alien_invasion,代码行数:33,代码来源:主程序.py
示例14: run_game
def run_game():
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
play_button = Button(ai_settings, screen, "Play")
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings, screen, stats)
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
gf.create_fleet(ai_settings, screen, ship, aliens)
while True:
gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
bullets)
gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
bullets)
gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
开发者ID:pattyvader,项目名称:python,代码行数:28,代码来源:alien_invasion.py
示例15: run_game
def run_game():
# Initialise
pygame.init()
ai_settings=Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# Make the Play button.
play_button = Button(ai_settings, screen, "Play")
# Create an instance to store game statistics and create a scoreboard.
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings, screen, stats)
# Make a ship, a group of bullets and a group of aliens.
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
# Create the alien fleet
gf.create_fleet(ai_settings, screen, ship, aliens)
# main loop
while True:
gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
开发者ID:BenObiWan,项目名称:alien_invasion,代码行数:31,代码来源:alien_invasion.py
示例16: run_game
def run_game():
# Initialize game and create a screen object.
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width,ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# Make the play button.
play_button = Button(ai_settings,screen, "Play")
# Create an instance to store game stats and create a scoreboard
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings,screen,stats)
#Make a ship, a group of bullets, and a group of aliens.
ship = Ship(ai_settings,screen)
bullets = Group()
aliens = Group()
# Create a fleet of aliens
gf.create_fleet(ai_settings,screen,ship,aliens)
# Start the main loop for the game.
while True:
# Watch for keyboard and mouse events.
gf.check_events(ai_settings,screen,stats,sb,play_button,ship,aliens,bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings,screen,stats,sb,ship,aliens,bullets)
gf.update_aliens(ai_settings,screen,stats,sb,ship,aliens,bullets)
gf.update_screen(ai_settings,screen,stats,sb,ship,aliens,bullets,play_button)
开发者ID:xchendo,项目名称:Alien-Invasion,代码行数:33,代码来源:alien_invasion.py
示例17: run_game
def run_game():
# Initialising game, setting and screen objects
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
pygame.display.set_caption("Space War")
# Make a ship
ship = Ship(ai_settings,screen)
# Make Bullet (Group)
bullets = Group()
# Make Alien
# alien = Alien(ai_settings,screen)
aliens = Group()
# Create an instance to store game statistics.
stats = GameStats(ai_settings)
# Fleet of aliens
gf.create_fleet(ai_settings,screen,ship,aliens)
# Game loop
while True:
# Check for events
gf.check_events(ai_settings,screen,ship,bullets)
if stats.game_active:
# Updates
ship.update()
gf.update_bullets(ai_settings,screen,ship,aliens,bullets)
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
gf.update_screen(ai_settings,screen,ship,aliens,bullets)
开发者ID:harshitbhat,项目名称:Space-War,代码行数:35,代码来源:game.py
示例18: run_game
def run_game():
# Inicjalizacja pygame, ustawień i obiektu ekranu.
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Inwazja obcych")
# Utworzenie egzemplarza przeznaczonego do przechowywania
# danych statystycznych dotyczących gry.
stats = GameStats(ai_settings)
# Zdefiniowanie koloru tła.
bg_color = (230, 230, 230)
# Utworzenie statku, grupy pocisków oraz grupy obcych.
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
# Utworzenie floty obcych.
gf.create_fleet(ai_settings, screen, ship, aliens)
# Rozpoczęcie pętli głównej gry.
while True:
gf.check_events(ai_settings, screen, ship, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
开发者ID:gorczynski,项目名称:python-crash-course,代码行数:33,代码来源:alien_invasion.py
示例19: run_game
def run_game():
# Initialize pygame, settings, and screen object.
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# Make a ship, a group of bullets, and a group of aliens.
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
# Create the fleet of aliens.
gf.create_fleet(ai_settings, screen, aliens)
# Start the main loop for the game.
while True:
gf.check_events(ai_settings, screen, ship, bullets)
ship.update()
gf.update_bullets(bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
# Redraw the screen during each pass through the loop.
screen.fill(ai_settings.bg_color)
ship.blitme()
# Make the most recently drawn screen visible.
pygame.display.flip()
开发者ID:jonnybarca,项目名称:Alien_Invasion,代码行数:30,代码来源:Alien_Invasions+project.py
示例20: run_game
def run_game():
# Initialize pygame, settings, and screen object
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Mutha Fuckin' Alien Invasion")
# Set the background color.
# bg_color = (230,230,230)
# Make a ship, a group of bullets, and a group of aliens.
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
# Create the fleet of aliens
gf.create_fleet(ai_settings, screen, ship, aliens)
# # A group to store super bullets in.
# super_bullets = Group()
# Start the main loop for the game.
while True:
gf.check_events(ai_settings, screen, ship, aliens, bullets)
ship.update()
gf.update_bullets(bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
# Make the most recently drawn screen visible.
pygame.display.flip()
开发者ID:Walter223,项目名称:python_game,代码行数:32,代码来源:alien_invasion.py
注:本文中的ship.Ship类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论