class AddRandomAsteroids(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", []) def test(self): self.game.add_random_asteroid(1) self.assertEqual(len(self.game.asteroids), 1)
def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [Asteroid(50, 50, 0, 0, 10, 100, 100)]) self.game.shots.append(Shot(self.game.player, 100, 100)) self.game.shots[0].x = 50 self.game.shots[0].y = 50 self.game.player.x = 0 self.game.player.y = 0
class AsteroidPlayerCollisionTrue(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [Asteroid(50, 50, 0, 0, 10, 100, 100)]) def test(self): self.game.check_collision() self.assertEqual(self.game.player.health, 2)
class UFOCreateTest(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(50, 50, 0, 0, 80, 100, 100)]) def test(self): self.game.create_ufo() self.assertEqual(len(self.game.ufo_list), 1)
class AsteroidShotCollisionTrue(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [Asteroid(50, 50, 0, 0, 80, 100, 100)]) self.game.shots.append(Shot(self.game.player, 100, 100)) def test(self): self.game.check_collision() self.assertEqual(len(self.game.shots), 0) self.assertEqual(len(self.game.asteroids), 3)
class ShotMoveInGame(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [Asteroid(50, 50, 0, 0, 10, 100, 100)]) self.game.shots.append(Shot(self.game.player, 100, 100)) self.X = self.game.shots[0].x def test(self): self.game.move() self.assertEqual(self.X + 6, self.game.shots[0].x)
class ChangeScoreboardTest1(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(50, 50, 0, 0, 80, 100, 100)]) def test(self): self.game.change_scoreboard('w.txt') self.assertEqual(self.game.scoreboard, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)])
class CheckUFOPlayerCollision(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(0, 0, 0, 0, 1, 100, 100)]) def test(self): self.game.create_ufo() self.game.player.x = self.game.ufo_list[0].x self.game.player.y = self.game.ufo_list[0].y self.game.check_collision() self.assertTrue(self.game.player.health == 2)
class UFOShotTest(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(50, 50, 0, 0, 80, 100, 100)]) def test(self): self.game.create_ufo() self.game.shots.append(self.game.ufo_list[0].shot(self.game.player)) self.assertEqual(len(self.game.shots), 1) self.game.ufo_try_shot() self.assertEqual(len(self.game.shots), 2)
class CreateBotuseTest(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(50, 50, 0, 0, 80, 100, 100)]) def test(self): self.game.create_bonus(self.game.asteroids[0]) self.assertEqual( len(self.game.hp_bonuses) + len(self.game.shield_bonuses) + len( self.game.rate_fire_bonuses), 1)
class SetPlayerDefaultPosition(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(50, 50, 0, 0, 80, 100, 100)]) def test(self): self.game.player.x = 12 self.game.player.y = 12 self.game.set_player_default_position() self.assertEqual((self.game.player.x, self.game.player.y), (50, 50))
class CheckEvents(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [Asteroid(50, 50, 0, 0, 10, 100, 100)]) def test(self): self.assertTrue(not self.game.check_events())
class AsteroidPlayerCollision(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [Asteroid(0, 0, 0, 0, 10, 100, 100)]) def test(self): self.assertTrue(not self.game.check_collision())
class CheckUFOPCollision(unittest.TestCase): def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(0, 0, 0, 0, 1, 100, 100)]) def test(self): self.game.create_ufo() self.game.shots.append(self.game.ufo_list[0].shot(self.game.player)) self.game.shots[0].x = self.game.ufo_list[0].x self.game.shots[0].y = self.game.ufo_list[0].y self.game.check_collision() self.assertEqual(len(self.game.ufo_list), 0) self.assertEqual(self.game.player.score, 2) self.assertEqual(len(self.game.shots), 0)
class CheckBotuseColisionTest(unittest.TestCase): def setUp(self): self.game = Game((1000, 1000), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(0, 0, 0, 0, 80, 100, 100)]) def test(self): self.game.hp_bonuses.append( HPBonus(self.game.player, 100, 100, (0, 0, 0))) self.game.shield_bonuses.append( ShieldBonus(self.game.player, 100, 100, (0, 0, 0))) self.game.rate_fire_bonuses.append( RateOfFireBonus(self.game.player, 100, 100, (0, 0, 0))) self.game.check_collision() self.assertEqual(self.game.player.health, 4) self.assertEqual(self.game.player.immortal_time, self.game.default_immortal_time * 2) self.assertEqual(self.game.player.refresh_speed, 2)
from asteroids.game import Game import config if __name__ == '__main__': print('Name:') name = input() scoreboard = list() with open("scoreboard.txt") as file: for i in range(5): line = file.readline() if line == "": break items = line.split() scoreboard.append((items[0], int(items[1]))) game = Game(config.Resolution, 1, config.Difficult, scoreboard, name) game.start_level()
from asteroids.game import Game, MainMenu if __name__ == '__main__': game = Game(MainMenu) game.setup() game.mainloop()
def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [Asteroid(0, 0, 0, 0, 10, 100, 100)])
def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [Asteroid(50, 50, 0, 0, 10, 100, 100)]) self.shot = Shot(self.game.player, 100, 100) self.X = self.shot.x
def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 1), ('w', 1), ('w', 1), ('w', 1), ('w', 1)], "s", [Asteroid(50, 50, 0, 0, 80, 100, 100)])
def setUp(self): self.game = Game((100, 100), 0, 1, [('w', 0)], "", [])