class ShipTestCase(unittest.TestCase): def setUp(self): self.ship = Ship(10.4, 15.5) def test_crew(self): self.assertIsInstance(self.ship.crew, int, msg='Crew can only be a number') self.assertLessEqual(self.ship.crew, 100000, msg='Crew cant exeed 100000') def test_draft(self): self.assertIsInstance(self.ship.draft, float, msg='Draft can either be a number or a delcimal') self.assertLessEqual(self.ship.draft, 100, msg='Draft cant exeed 100') def test_correct_results(self): self.ship.draft = 40 self.ship.crew = 10 self.assertEqual('Loot', self.ship.is_worth_it(), msg='Wrong results generated') def test_wrong_results(self): self.ship.draft = 30 self.ship.crew = 10 self.assertEqual('Do not loot', self.ship.is_worth_it(), msg='Wrong results generated')
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") play_button = Button(ai_settings, screen, "Play") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) # Draw the game elements ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() # alien = Alien(ai_settings, screen) gi.create_fleet(ai_settings, screen, ship, aliens) # Start the main loop for the game while True: gc.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gr.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) gr.update_aliens(ai_settings, stats, screen, sb, ship, aliens, bullets) gr.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def prep_ships(self): """Show how many ships are left""" self.ships = Group() for ship_number in range(self.stats.ships_left): ship = Ship(self.ai_settings, self.screen) ship.rect.x = 10 + ship_number * ship.rect.width ship.rect.y = 10 self.ships.add(ship)
def run_game(): """Initialize game and create a screen object""" pygame.init() game_settings = GameSettings() screen = pygame.display.set_mode( (game_settings.screen_width, game_settings.screen_height)) pygame.display.set_caption("Alien Invasion") # Create an instance to store game statistics and scoreboard stats = GameStats(game_settings) sb = Scoreboard(game_settings, screen, stats) # Make the Play button play_button = Button(screen, 'Play') # Make a ship ship = Ship(game_settings, screen) # Make an alien aliens = Group() # Make a group to store bullets in bullets = Group() # Create the fleet of aliens gf.create_fleet(game_settings, screen, ship, aliens) # Watch for keyboard and mouse events while True: gf.check_events(game_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(game_settings, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(game_settings, screen, stats, sb, ship, aliens, bullets) gf.update_screen(game_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def setUp(self): self.ship = Ship(10.4, 15.5)
from app.ship import Ship from app.mission import Mission # run ship draftt = float(input('Whats the draft? ')) creww = int(input('How many crew? ')) titanic = Ship(draftt, creww) print(titanic.is_worth_it()) # run mission # bulletNo = int(input('How many bullets do you have? ')) # mission = Mission(bulletNo) # mission.goToWar() # print (mission.getStatusToString())