def test_enemy_collision_with_brick(): GAME = Game(99, 100, 1) enemy = Enemy(GAME, 33, 31, 6) GAME.screen.gmap[30:33, 2:4] = 6 enemy.move() enemy.move() enemy.move() enemy.move() assert enemy.dir == 1
def test_mario_collision_with_ground(): GAME = Game(99, 100, 1) mario = GAME.player assert mario.collision(4) == (True, (mario.i + 1, mario.j - 1)) oldloc = mario.get_loc() mario.vertical() newloc = mario.get_loc() assert oldloc == newloc
def test_mario_collision_with_coin(): GAME = Game(0, 100, 1) mario = GAME.player GAME.screen.gmap[30:32, 6:8] = 9 mario.move(1) mario.move(1) mario.move(1) assert GAME.points > 0
def test_mario_resize_to_large(): GAME = Game(0, 100, 1) # Assert changes on resize GAME.player.resize(1) assert GAME.player.get_size() == (4, 3) assert GAME.player.maxj == 11 mario_exists_in_bounds(GAME)
def test_mario_move_right(): GAME = Game(99, 100, 1) mario = GAME.player oldloc = mario.get_loc() mario.move(1) newloc = mario.get_loc() assert oldloc[1] == newloc[1] - 1 mario_exists_in_bounds(GAME)
def run(self): while True: if len(self.game) > 1: print('game found') p0_id, p0_handler = self.game.popitem() p1_id, p1_handler = self.game.popitem() Game(p0_handler, p1_handler).start() time.sleep(1)
def test_mario_move_left(): GAME = Game(0, 100, 1) mario = GAME.player oldloc = mario.get_loc() mario.move(2) newloc = mario.get_loc() assert oldloc[1] == newloc[1] + 1 mario_exists_in_bounds(GAME)
def test_mario_collision_with_powerup(): GAME = Game(99, 100, 1) mario = GAME.player powerup = PowerUp(GAME, 31, 6) GAME.screen.position(powerup) mario.move(1) mario.move(1) mario.move(1) assert mario.get_size() == (4, 3)
def test_game_init_with_proper_params(): ''' Checks for proper initialization of Game ''' GAME = Game(0, 100, 1) # Check time allocated is correct assert GAME.etime - GAME.stime == 100 # Check for object inconsistencies assert GAME.screen.game == GAME assert len(GAME.codes) == 1007
def test_mario_jump(): GAME = Game(99, 100, 1) mario = GAME.player mario.move(3) # Check jump up assert mario.jstate == mario.maxj while mario.jstate > 0: pjstate = mario.jstate mario.vertical() if pjstate == 1: assert mario.jstate == -1 else: assert mario.jstate == pjstate - 1 mario_exists_in_bounds(GAME)
def test_mario_init_with_default_params(): ''' Check for proper initialization of Mario in default ''' GAME = Game(0, 100, 1) PLAYER_POS_I = GAME.player.i PLAYER_POS_J = GAME.player.j PLAYER_SIZE_I = GAME.player.get_size()[0] PLAYER_SIZE_J = GAME.player.get_size()[1] assert GAME.player.lives == 1 assert GAME.player.get_size() == (3, 3) mario_exists_in_bounds(GAME) test_mario_resize_to_large()
if LEVEL > 2 or LEVEL < 0: played_flag = False print('Choice out of bounds. Press any key to continue') KEYS.get_ch() sys.exit(0) # Start a new Game with level # the screen used is a property of the game object LIVES = configs.MAX_LIFE STATUS = 0 POINTS = 0 while LIVES > 0: GAME = Game(LEVEL, configs.STD_TIME, LIVES) # Level screen GAME.level_screen(LEVEL, LIVES, POINTS) KEYS.flush() KEYS.get_ch() # Game loop executes as time remains while GAME.get_t_remain() > 0: # FRAME stores the time remaining at the start of rendering # a frame, so as to calculate how long actually rendering it # took, and to maintain a framerate FRAME = GAME.get_t_remain() # repaint screen
print("Choose level you want to play:\n0\t1\t2") level = int(keys.getCh()) if level > 2 or level < 0: print('Choice out of bounds. Resetting to 0') level = 0 # Start a new Game with level # the screen used is a property of the game object lives = configs.MAX_LIFE status = 0 points = 0 while lives > 0: game = Game(level, configs.STD_TIME, lives) # Level screen game.levelScreen(level, lives, points) keys.flush() keys.getCh() # Game loop executes as time remains while game.getTRemain() > 0: # frame stores the time remaining at the start of rendering # a frame, so as to calculate how long actually rendering it # took, and to maintain a framerate frame = game.getTRemain() # repaint screen
label = self.font.render(str(self.initial_velocity), True, pg.Color("dodgerblue")) surface.blit(label, (10, 40)) label = self.font.render(str(self.time), True, pg.Color("dodgerblue")) surface.blit(label, (10, 80)) if not self.started: text = "Use mouse to launch satellite." title = self.font.render(text, True, pg.Color("dodgerblue")) title_rect = title.get_rect(center=self.screen_rect.center) surface.blit(title, title_rect) elif self.paused: title = self.font.render("PAUSED", True, pg.Color("dodgerblue")) title_rect = title.get_rect(center=self.screen_rect.center) surface.blit(title, title_rect) if __name__ == "__main__": pg.init() screen = pg.display.set_mode((1280, 720)) states = { "SPLASH": SplashScreen(), "GAMEPLAY": Gameplay(), "FINISHED": FinishScreen()} game = Game(screen, states, "SPLASH") game.run() pg.quit() sys.exit()