def setUp(self): self.unicorn = player.Player("Unicorn", [ card.Card(4), card.Card(52), card.Card(17), card.Card(20), card.Card(35) ]) self.consultant = player.Player("Consultant", [ card.Card(42), card.Card(13), card.Card(37), card.Card(5), card.Card(9) ]) self.lovelace = player.Player("Ada Lovelace", [ card.Card(29), card.Card(28), card.Card(39), card.Card(27), card.Card(30) ]) self.hopper = player.Player("Grace Hopper", [ card.Card(24), card.Card(11), card.Card(50), card.Card(51), card.Card(38) ])
def test_winner(game_instance: game.Game) -> None: """ Test the final winner. """ # Round 1 with mock.patch("random.choice", lambda seq: "Paper"): # Reload game module reload(game) # Instantiate a new player and game human = player.Player("Madalin") new_game = game.Game(human) new_game.player.choice = "Rock" computer_choice = new_game.computer_choice result = new_game.winner() assert result == "Computer won!" reload(game) # Round 2 with mock.patch("random.choice", lambda seq: "Human"): # Reload game module reload(game) # Instantiate a new player and game human = player.Player("Madalin") new_game = game.Game(human) new_game.player.choice = "Human" computer_choice = new_game.computer_choice result = new_game.winner() assert result == "Nobody won. It is a draw!" reload(game) # Round 3 with mock.patch("random.choice", lambda seq: "Tree"): # Reload game module reload(game) # Instantiate a new player and game human = player.Player("Madalin") new_game = game.Game(human) new_game.player.choice = "Human" computer_choice = new_game.computer_choice result = new_game.winner() assert result == "Madalin won!" # Final Score assert new_game.player.score > new_game.computer_score reload(game)
def main(): # Pygame window setup pygame.init() pygame.display.set_caption('Pytanks') game_system = game.Game() default_player = player.Player("Player 1") default_player.set_colour((65, 105, 225)) test_ai = player.Player("AI - Sentry") test_ai.set_colour((255, 0, 0)) game_system.add_player(default_player) game_system.add_player(test_ai) game_system.load_map('default.json') game_system.assign_tanks() game_system.start()
def __init__(self, playerNames): """Domyślne ustawienia klasy Args: players (int): Ilość wszystkich graczy """ self.width = consts.BOARD_WIDTH self.height = consts.BOARD_HEIGHT self.tiles = np.zeros((self.width, self.height), dtype=int) initPos = playerInitialPositions[len(playerNames)] self.players = [ player.Player(name, initPos[i][0], initPos[i][1]) for i, name in enumerate(playerNames) ] self.create_board() self.board_history = [] for x in range(self.width): for y in range(self.height): move = '@' + str(x) + '*' + str(y) + '*' + \ str(self.tiles[x, y]) + '*!' self.board_history.append(move) self.board_history.append('#')
def player_fixture() -> player.Player: """ Player setup """ human_player = player.Player("Madalin Popa") human_player.choice = "Rock" return human_player
def hidden_map(): # Door pending # 0 1 2 3 4 # 0 # # . # # # 1 # # b # # b=hidden banana trap # 2 . + @ % . +=hidden door, and %=hidden corridor # 3 # # ^ # # ^=hidden bear trap # 4 # # . # # new_map = gamemap.GameMap(width=6, height=6, fill_tile=tiles.wall) floors = [(2, 0), (2, 1), (0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (2, 3), (2, 4)] for x, y in floors: new_map.tiles[x, y] = tiles.floor # Create a player at 5, 5 new_player = player.Player() new_map.place(new_player, 2, 2) new_map.player = new_player # Create bear trap at 2, 3 new_trap = factory.make("bear trap") new_map.place(new_trap, 2, 3) return new_map
def main(): play = player.Player() done = False current_room = room.Room(True, False, False, False, "You are in a room.", []) while not done: done = command.read_cmd(input("> ").split(" "), current_room, play)
def test_dungeon(): # Create a dungeon with 1 floor and add the Player to it. plyr = player.Player() e = SimpleNamespace(game_map='testmap', player=plyr) d = dungeon.Dungeon(engine=e, test_map=toolkit.stair_map) d.generate_floor() d.current_map.place(plyr, 0, 0) d.current_map.player = plyr return d
def test_computer_choice(game_instance: game.Game) -> None: """ Test computer choice. """ with mock.patch("random.choice", lambda seq: seq[0]): reload(game) human = player.Player("Madalin") new_game = game.Game(human) assert new_game.computer_choice == "Gun" reload(game)
def game_instance() -> game.Game: """ Game setup """ # Define player human_player = player.Player("Madalin Popa") # Create a game instance game_instance = game.Game(human_player) return game_instance
def test_dungeon(): # Create a dungeon with 3 floors and adds the player to the floor 2 for easy testing situations. plyr = player.Player() e = SimpleNamespace(game_map='testmap', player=plyr) d = dungeon.Dungeon(engine=e, test_map=toolkit.stair_map) d.generate_floor() # Floor 2 d.generate_floor() # Floor 3 d.place_entity(plyr, 2, 0, 0) # Put the player on level 2 d.current_map.player = plyr # We'll set this manually assert d.dlevel == 2 return d
def test_map(): # Door pending # 0 1 2 3 4 5 # 0 # # . . . . # 1 # # . . . . # 2 . + . . . . # 3 # # . . # . # 4 # # . . # o # 5 # # x . . @ new_map = gamemap.GameMap(width=6, height=6, fill_tile=tiles.floor) walls = [ (0, 0), (1, 0), (0, 1), (1, 1), (0, 3), (1, 3), (4, 3), (0, 4), (1, 4), (4, 4), (0, 5), (1, 5), ] for x, y in walls: new_map.tiles[x, y] = tiles.wall # Create a player at 5, 5 new_player = player.Player() new_map.place(new_player, 5, 5) new_map.player = new_player # Give the player items for testing dagger = factory.make("dagger") new_player.inventory.add_inv_item(dagger) leather_armor = factory.make("leather vest") new_player.inventory.add_inv_item(leather_armor) health_vial = factory.make("healing vial") new_player.inventory.add_inv_item(health_vial) # Create a grid bug at 2, 5 factory.spawn("grid bug", new_map, 2, 5) # Create a spider drone at 5, 4 factory.spawn("henchman", new_map, 5, 4) return new_map
def __init__(self): # Gui Instance self.gui = gui.Gui() # Player Instance self.player = player.Player(self.gui, self.gui.player_img) # Obstacle Instances inside players List for _ in range(8): self.player.obstacles.append( obstacle.Obstacle(self.gui, self.gui.obstacle_img)) # Mainloop self.gui.root.mainloop()
def main(): """ Control flow for the game. :return: None. """ game_board = board.Board() p1 = player.Player() comp = ai.AI() run = True clock = pygame.time.Clock() winner = None # who won the game? while run: clock.tick(60) # if all the ships of the player or of the AI have been hit, end the game. if game_board.player_hit_ships == 20 or game_board.ai_hit_ships == 20: # declare the winner and end the game if game_board.player_hit_ships == 1: game_board.fullscreen_message("AI has won!") winner = "AI" else: game_board.fullscreen_message("Player has won!") winner = game_board.info.username time.sleep(3) run = False break # process each event. for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if event.type == pygame.MOUSEBUTTONDOWN: pos = event.pos valid = register_click(game_board, pos, p1) if valid: time.sleep(0.5) # slight delay before AI makes a move comp_move = comp.make_move() game_board.register_ai_hit(comp_move) # display the top scores game_board.info.end_game(game_board.player_hit_ships, game_board.ai_hit_ships, winner) # end the game pygame.quit()
def __init__(self, players): """Domyślne ustawienia klasy Args: players (int): Ilość wszystkich graczy """ self.width = const.BOARD_WIDTH self.height = const.BOARD_HEIGHT self.tiles = np.zeros((self.width, self.height), dtype=int) self.players = players self.player_1 = player.Player('Gracz 1', 1, 1) self.create_board() self.board_history = [] for x in range(self.width): for y in range(self.height): move = '@' + str(x) + '*' + str(y) + '*' + str( self.tiles[x, y]) + '*!' self.board_history.append(move) self.board_history.append('#')
def __init__(self): ''' Sets up the window. Defines each location, the character, character direction, character's current location, and dialogue of the trainers. ''' self.window = pygame.display.set_mode((WIDTH, HEIGHT)) self.locs = { "hinman college":\ location.Location(pygame.image.load('art/environment/hinman_college.png'),\ pygame.image.load('art/environment/hinman_college_mask.png').convert_alpha(),\ pygame.image.load('art/environment/hinman_college_loadzones.png'),\ 'sound/music/death.ogg',-1900,-1200,3000,3000), "success center":\ location.Location(pygame.image.load('art/environment/success_center.png'),\ pygame.image.load('art/environment/success_center_mask.png').convert_alpha(),\ pygame.image.load('art/environment/success_center_loadzones.png'),\ 'sound/music/reslife.ogg',0,0,640,480), "hughes":\ location.Location(pygame.image.load('art/environment/hughes.png'),\ pygame.image.load('art/environment/hughes_mask.png').convert_alpha(),\ pygame.image.load('art/environment/hughes_loadzones.png'),\ 'sound/music/reslife.ogg',0,0,2000,500), "cleveland":\ location.Location(pygame.image.load('art/environment/cleveland.png'),\ pygame.image.load('art/environment/cleveland_mask.png').convert_alpha(),\ pygame.image.load('art/environment/cleveland_loadzones.png'),\ 'sound/music/reslife.ogg',0,0,2000,500), "lehman":\ location.Location(pygame.image.load('art/environment/lehman.png'),\ pygame.image.load('art/environment/lehman_mask.png').convert_alpha(),\ pygame.image.load('art/environment/lehman_loadzones.png'),\ 'sound/music/reslife.ogg',0,0,2000,500), "roosevelt":\ location.Location(pygame.image.load('art/environment/roosevelt.png'),\ pygame.image.load('art/environment/roosevelt_mask.png').convert_alpha(),\ pygame.image.load('art/environment/roosevelt_loadzones.png'),\ 'sound/music/reslife.ogg',0,0,2000,500), "smith":\ location.Location(pygame.image.load('art/environment/smith.png'),\ pygame.image.load('art/environment/smith_mask.png').convert_alpha(),\ pygame.image.load('art/environment/smith_loadzones.png'),\ 'sound/music/reslife.ogg',0,0,2000,500) } char = { "forward":\ (pygame.image.load('art/sprites/player/FS.png'),\ pygame.image.load('art/sprites/player/FL.png'),\ pygame.image.load('art/sprites/player/FS.png'),\ pygame.image.load('art/sprites/player/FR.png')), "backward":\ (pygame.image.load('art/sprites/player/BS.png'),\ pygame.image.load('art/sprites/player/BL.png'),\ pygame.image.load('art/sprites/player/BS.png'),\ pygame.image.load('art/sprites/player/BR.png')), "left":\ (pygame.image.load('art/sprites/player/LS.png'),\ pygame.image.load('art/sprites/player/LL.png'),\ pygame.image.load('art/sprites/player/LS.png'),\ pygame.image.load('art/sprites/player/LR.png')), "right":\ (pygame.image.load('art/sprites/player/RS.png'),\ pygame.image.load('art/sprites/player/RL.png'),\ pygame.image.load('art/sprites/player/RS.png'),\ pygame.image.load('art/sprites/player/RR.png')) } pmask = pygame.image.load( 'art/sprites/player/mask.png').convert_alpha() pmask = pygame.mask.from_surface(pmask) self.current_loc = "success center" self.player = player.Player(char, 230, 250, pmask) self.dialogues = None self.trainers = { "Al Vos": trainer.Trainer(\ "Al Vos",None,pygame.image.load('art/character_portraits/al_vos.png'),\ "Hello, I'm Al Vos! Welcome to Hinman college! This campus inhabits various types of wild hinmanmon that you will likely encounter."+\ "There are many trainers who will help you on your journey. Good luck and have fun battling!",()), #SMITH HALL "President Alex and Owen": trainer.Trainer(\ "President Alex and Owen",None,pygame.image.load('art/character_portraits/smith_president.png'),\ "Alex: We got no hinmanmon here." + " " + "Owen: But, we got some FR E SH A VOCA DO.",()), "Academic VP Nancy and Katie": trainer.Trainer(\ "Academic VP Nancy and Katie",None,pygame.image.load('art/character_portraits/smith_academic.png'),\ "If we weren't friends with all the legendary hinmanmon, we would've caught them all.",()), "Service VP Melanie": trainer.Trainer(\ "Service VP Melanie",None,pygame.image.load('art/character_portraits/smith_service.png'),\ "I'll have you know, I accidentally beat the elite four and it only took me 1000 tries.",()), "Social VP Isaac and Abby": trainer.Trainer(\ "Social VP Isaac and Abby",None,pygame.image.load('art/character_portraits/smith_social.png'),\ "If you want to catch a hinmanmon, just don't critical hit.",()), "Sam Atkin": trainer.Trainer(\ "Sam Atkin",None,pygame.image.load('art/character_portraits/sam.png'),\ "Don't look at me too long. It's super effective.",()), "PR Gabi and Shayna": trainer.Trainer(\ "PR Gabi and Shayna",None,pygame.image.load('art/character_portraits/smith_pr.png'),\ "Let's go ride my magikarpet.",()), #ROOSEVELT HALL "President Colleen and Lexi": trainer.Trainer(\ "President Colleen and Lexi",None,pygame.image.load('art/character_portraits/roosevelt_president.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Academic VP Phariha": trainer.Trainer(\ "Academic VP Phariha",None,pygame.image.load('art/character_portraits/roosevelt_academic.png'),\ "On my way to steal yo hinmanmon.",()), "Service VP Rebecca": trainer.Trainer(\ "Service VP Rebecca",None,pygame.image.load('art/character_portraits/roosevelt_service.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Social VP Victoria": trainer.Trainer(\ "Social VP Victoria",None,pygame.image.load('art/character_portraits/roosevelt_social.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Financial VP Dyanna": trainer.Trainer(\ "Financial VP Dyanna",None,pygame.image.load('art/character_portraits/roosevelt_financial.png'),\ "The quick brown fox jumps over the lazy dog.",()), "PR Shanté": trainer.Trainer(\ "PR Shanté",None,pygame.image.load('art/character_portraits/roosevelt_pr.png'),\ "The quick brown fox jumps over the lazy dog.",()), #LEHMAN HALL "President Jenn and Sophia": trainer.Trainer(\ "President Jenn and Sophia",None,pygame.image.load('art/character_portraits/lehman_president.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Academic VP Merry": trainer.Trainer(\ "Academic VP Merry",None,pygame.image.load('art/character_portraits/lehman_academic.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Service VP Brandon": trainer.Trainer(\ "Service VP Brandon",None,pygame.image.load('art/character_portraits/lehman_service.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Social VP Joe": trainer.Trainer(\ "Social VP Joe",None,pygame.image.load('art/character_portraits/lehman_social.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Financial VP Megan": trainer.Trainer(\ "Financial VP Megan",None,pygame.image.load('art/character_portraits/lehman_financial.png'),\ "The quick brown fox jumps over the lazy dog.",()), "PR Colleen": trainer.Trainer(\ "PR Colleen",None,pygame.image.load('art/character_portraits/lehman_pr.png'),\ "The quick brown fox jumps over the lazy dog.",()), #HUGHES HALL "President Will": trainer.Trainer(\ "President Will",None,pygame.image.load('art/character_portraits/hughes_president.png'),\ "You can't spell THICC without HCC.",()), "Academic VP Briea and Hannah": trainer.Trainer(\ "Academic VP Briea and Hannah",None,pygame.image.load('art/character_portraits/hughes_academic.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Service VP Lizzie and Marvin": trainer.Trainer(\ "Service VP Lizzie and Marvin",None,pygame.image.load('art/character_portraits/hughes_service.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Social VP Dora and Hannah": trainer.Trainer(\ "Social VP Dora and Hannah",None,pygame.image.load('art/character_portraits/hughes_social.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Financial VP Ryan": trainer.Trainer(\ "Financial VP Ryan",None,pygame.image.load('art/character_portraits/hughes_financial.png'),\ "The quick brown fox jumps over the lazy dog.",()), "PR Brenna": trainer.Trainer(\ "PR Brenna",None,pygame.image.load('art/character_portraits/hughes_pr.png'),\ "The quick brown fox jumps over the lazy dog.",()), #CLEVELAND HALL "President Daniel": trainer.Trainer(\ "President Daniel",None,pygame.image.load('art/character_portraits/cleveland_president.png'),\ ".",()), "Academic VP Will": trainer.Trainer(\ "Academic VP Will",None,pygame.image.load('art/character_portraits/cleveland_academic.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Service VP Julia": trainer.Trainer(\ "Service VP Julia",None,pygame.image.load('art/character_portraits/cleveland_service.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Social VP Jake": trainer.Trainer(\ "Social VP Jake",None,pygame.image.load('art/character_portraits/cleveland_social.png'),\ "The quick brown fox jumps over the lazy dog.",()), "Financial VP Brian": trainer.Trainer(\ "Financial VP Brian",None,pygame.image.load('art/character_portraits/cleveland_financial.png'),\ "The quick brown fox jumps over the lazy dog.",()), "PR Jacob and Kass": trainer.Trainer(\ "PR Jacob and Kass",None,pygame.image.load('art/character_portraits/cleveland_pr.png'),\ "The quick brown fox jumps over the lazy dog.",()), }
def __init__(self): self.player = player.Player() self.reset()
def __init__(self): print('World class instantiated') # Enable or disable debugging debug = True # Set background color base.setBackgroundColor(0.1, 0.1, 0.1, 1) base.camLens.setNearFar(5.5, 500) #base.camLens.setFov(45) base.camLens.setAspectRatio(1.7778) # Main game node self.mainNode = render.attachNewNode('mainNode') # Enable automatic shaders on everything (allows glow map, gloss maps, shadows etc.) self.mainNode.setShaderAuto() # Create the main traverser base.cTrav = CollisionTraverser() # Fluid move prevents quantum tunnelling. base.cTrav.setRespectPrevTransform(True) # Initialize global AI self.initAI() # Instantiate other classes self.scenarioHandler = scenario.ScenarioHandler() self.DDAHandler = dda.DDA(self) self.stateHandler = states.StateHandler() self.mapHandler = map.Map(self) self.player = player.Player(self) #self.gui = gui.GUI() self.hud = hud.HUD(self.player) # Add keyboard commands self.accept('escape', self.endGame) self.accept('pause', self.pauseGame) self.accept('p', self.pauseGame) #------------------------------------------------------------------------------------ # Start of debugging implementation if debug: #self.accept('shift-o', self.gui.toggleOverlayFrame) self.accept('shift-1', self.damagePlayer) self.accept('shift-2', self.killEnemy) self.accept('shift-3', self.zoomOut) self.accept('shift-4', self.outputTime) self.accept('shift-5', self.addEnemy) self.accept('shift-6', self.levelPlayerUp) self.accept('shift-7', self.healPlayer) self.accept('shift-8', self.showAllCollisions) self.accept('shift-9', self.printStats) self.accept('shift-0', self.showFPS) self.showCollisions = False
import sys import pygame from src import constants as C from src import player as P from src import helper_functions as hf from src import Laser as L from src import hor_lazer as H if __name__ == '__main__': pygame.init() #game init main_screen = pygame.display.set_mode(C.SCREEN_SIZE) #screen size. game_over = False player = P.Player(main_screen) laser = L.Laser(main_screen, player) laser2 = L.Laser(main_screen, player) laser3 = L.Laser(main_screen, player) hlaser = H.HorizontalLaser(main_screen, player) hlaser2 = H.HorizontalLaser(main_screen, player) hlaser3 = H.HorizontalLaser(main_screen, player) laser_list =[] for i in range(0, C.VERTICAL_LASER): new_laser = L.Laser(main_screen, player) laser_list.append(new_laser) for i in range(0, C.HORIZONTAL_LASER): new_laser = H.HorizontalLaser(main_screen, player) laser_list.append(new_laser) clock = pygame.time.Clock() pygame.key.set_repeat(50, 50) while not game_over:
def test_player(): return player.Player()
import unittest.mock import src.player as player import src.load as load import os testy = player.Player("Gary McTest", 7, "Both", "Male", False) class Test_persistance(unittest.TestCase): def test_save_load(self): # arrange filepath = "temp.csv" expected_name = "Gary Mctest" expected_age = 7 expected_foot = "Both" expected_gender = "Male" expected_player = False test_list = [] test_list.append(testy) # act load.save_player(test_list, filepath) actual_output = load.load_players(filepath) # assert self.assertEqual(expected_name, actual_output[0].name) self.assertEqual(expected_age, actual_output[0].age) self.assertEqual(expected_foot, actual_output[0].foot) self.assertEqual(expected_gender, actual_output[0].gender) self.assertEqual(expected_player, actual_output[0].player_status) os.remove(filepath)
def collect_players(self): for i in range(1, self.num_players + 1): player_name = input("Enter player " + str(i) + " name: ") p = player.Player(player_name) self.players.append(p)
def main(): """test bullets model""" print("####### testing bullets model######") test_bullet = bt.Bullet(9,8) print("=====Standard Initialization Test=====") assert test_bullet.rect.x == 9 assert test_bullet.rect.y == 8 print("=====Pass=====") print("=====Standard Function Test=====") test_bullet.update() assert test_bullet.rect.x == 9 + 13 assert test_bullet.rect.y == 8 print("=====Pass=====") print("######## bullets test complete#######\n") """ test enemy model""" print("####### testing enemy model######") test_enemy = em.Enemy() print("=====Standard Initialization Test=====") assert test_enemy.rect.x == em.screen_width assert test_enemy.rect.y < em.screen_height print("=====Pass=====") print("=====Standard Function Test=====") test_enemy.update() assert test_enemy.rect.x == 700 - 2 assert test_enemy.rect.y <= 400 + 3 print("=====Pass=====") print("######## enemy test complete#######\n") """test GameMenu model""" print("####### testing GameMenu model######") test_menu = GM.GameMenu(pygame.display.set_mode((700, 400), 0, 32),('Start', 'Quit'),{'Start': print("start")}) print("=====Standard Initialization Test=====") assert test_menu.mouse_is_visible == True assert test_menu.cur_item == None print("=====Pass=====") print("=====Standard Function Test=====") test_menu.set_mouse_visibility() assert pygame.mouse.set_visible(True) test_menu.set_keyboard_selection(pygame.K_UP) assert test_menu.cur_item == 0 print("=====Pass=====") print("######## GameMenu test complete#######\n") """test MenuItem model""" print("####### testing MenuItem model######") test_menuitem = MI.MenuItem("\u6211", None, 30, WHITE) print("=====Standard Initialization Test=====") assert test_menuitem.text == "\u6211" assert test_menuitem.font_size == 30 assert test_menuitem.font_color == WHITE print("=====Pass=====") print("=====Standard Function Test=====") assert test_menuitem.is_mouse_selection((2,3)) test_menuitem.set_position(0,0) assert test_menuitem.pos_x == 0 assert test_menuitem.pos_y == 0 test_menuitem.set_font_color((0,0,0)) assert test_menuitem.font_color == (0,0,0) print("=====Pass=====") print("######## MenuItem test complete#######\n") """ test initialization of the help menu""" print("####### testing HelpMenu model######") print("=====Standard Initialization Test=====") test_menu = HM.HelpMenu() print("=====Pass=====") print("######## HelpMenu test complete#######\n") """test player model""" print("####### testing player model######") test_player = pl.Player() print("=====Standard Initialization Test=====") assert test_player.rect.x == 0 assert test_player.rect.y == 200 assert test_player.x_speed == 0 assert test_player.y_speed == 0 print("=====Pass=====") print("=====Standard Function Test=====") test_player.update() assert test_player.rect.x == 0 assert test_player.rect.y == 200 print("=====Pass=====") print("######## player test complete#######\n") """test rocks model""" print("####### testing player model######") test_rock = rk.Rock() print("=====Standard Initialization Test=====") assert test_rock.rect.x == 700 assert test_rock.rect.y < 400 print("=====Pass=====") print("=====Standard Function Test=====") test_rock.update() assert test_rock.rect.x == 700 - 6 print("=====Pass=====") print("######## rocks test complete#######\n") pygame.quit()
def mainloop(): cardUID = 0 deck = [] love1card = Love1Card.Love1Card() for i in range(7): deck.append((love1card,cardUID)) cardUID += 1 colette = Card.Card() for i in range(3): deck.append((colette,cardUID)) cardUID += 1 shuffle(deck) print "Game START" print deck""" game = game.Game() players = player.Player(game) def mainloop(): game.setup_game(None, players) while game.running: game.update() mainloop()
def __init__(self): """ Initiate the Controller. """ pygame.init() # Create the window self.screen = pygame.display.set_mode((screen_width,screen_height)) self.bg_image = pygame.image.load("assets\\bg.png").convert() pygame.display.set_caption("Space Shooter 2") # Font self.font = pygame.font.SysFont("font",20) # Music self.bgm = pygame.mixer.music.load("assets\monkeys.wav") pygame.mixer.music.play(1) self.bullet_sound = pygame.mixer.Sound("assets\laser5.ogg") # Sprite lists self.enemy_list = pygame.sprite.Group() self.bullet_list = pygame.sprite.Group() self.rock_list = pygame.sprite.Group() # Create the player self.player = player.Player() # initiate the time self.start_time = time.time() self.pass_time = 0 self.last_time = 0 #initiate the score self.hit_score = 0 self.total_score = 0 self.score_data = scoreData.ScoreData() self.clock = pygame.time.Clock() done = False # main loop while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True elif event.type == pygame.KEYDOWN: # shoot if event.key == pygame.K_SPACE: bullet_x = self.player.rect.x + self.player.image.get_width() bullet_y = self.player.rect.y + 8 self.bullet_list.add(bullets.Bullet(bullet_x, bullet_y)) self.bullet_sound.play() # move the plane if event.key == pygame.K_LEFT: self.player.x_speed = -5 if event.key == pygame.K_RIGHT: self.player.x_speed = 5 if event.key == pygame.K_UP: self.player.y_speed = -5 if event.key == pygame.K_DOWN: self.player.y_speed = 5 elif event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: self.player.x_speed = 0 if event.key == pygame.K_UP or event.key == pygame.K_DOWN: self.player.y_speed = 0 # set the difficulty self.pass_time = time.time() - self.start_time self.enemy_speed = self.pass_time ** 0.4 + 3 self.rock_speed = self.pass_time ** 0.4 + 6 # create rocks and enemies if self.pass_time < 30: if time.time() - self.last_time > 0.75: self.enemy_list.add(enemies.Enemy(self.enemy_speed)) self.rock_list.add(rocks.Rock(self.rock_speed)) self.last_time = time.time() elif self.pass_time < 50: if time.time() - self.last_time > 0.5: self.enemy_list.add(enemies.Enemy(self.enemy_speed)) self.rock_list.add(rocks.Rock(self.rock_speed)) self.last_time = time.time() elif self.pass_time < 75: if time.time() - self.last_time > 0.25: self.enemy_list.add(enemies.Enemy(self.enemy_speed)) self.rock_list.add(rocks.Rock(self.rock_speed)) self.last_time = time.time() #--- Game Logic collide_list1 = pygame.sprite.spritecollideany(self.player, self.enemy_list) collide_list2 = pygame.sprite.spritecollideany(self.player, self.rock_list) if collide_list1 or collide_list2: pygame.display.set_caption("GAME OVER") self.font = pygame.font.SysFont("font",30) self.game_over = self.font.render("Game Over", True, WHITE) self.your_score = self.font.render("Your Score: " + str(self.total_score), True, WHITE) self.highest_score = self.font.render("Highest Score: " + str(self.score_data.best), True, WHITE) self.text_rect = self.game_over.get_rect() self.text_x = self.screen.get_width() / 2 - self.text_rect.width / 2 self.text_y = self.screen.get_height() / 2 - self.text_rect.height / 2 self.screen.blit(self.bg_image,(0,0)) self.screen.blit(self.game_over, [self.text_x, self.text_y-20]) self.screen.blit(self.your_score, [self.text_x, self.text_y+20]) self.screen.blit(self.highest_score, [self.text_x, self.text_y+50]) pygame.display.flip() time.sleep(3) done = True # update classes self.all_sprites_list= pygame.sprite.Group((self.player,)+tuple(self.enemy_list)+tuple(self.rock_list)+tuple(self.bullet_list)) self.all_sprites_list.update() for bullet in self.bullet_list: hit_enemy_list = pygame.sprite.spritecollide(bullet, self.enemy_list, True) for enemy in hit_enemy_list: self.hit_score += 2 self.bullet_list.remove(bullet) self.all_sprites_list.remove(bullet) hit_rock_list = pygame.sprite.spritecollide(bullet, self.rock_list, False) for rock in hit_rock_list: self.bullet_list.remove(bullet) self.all_sprites_list.remove(bullet) if bullet.rect.x > screen_width: self.bullet_list.remove(bullet) self.all_sprites_list.remove(bullet) # score self.total_score = int(self.hit_score + self.pass_time) if self.total_score > self.score_data.best: self.score_data.best = self.total_score self.score_data.update() self.score = self.font.render("Score: "+ str(self.total_score), True, WHITE) self.best_score = self.font.render("Best: "+ str(self.score_data.best), True, WHITE) # redraw the screen self.screen.blit(self.bg_image,(0,0)) self.screen.blit(self.score, (screen_width - 100, 5)) self.screen.blit(self.best_score, (screen_width - 100, 20)) self.all_sprites_list.draw(self.screen) pygame.display.flip() self.clock.tick(60)
def quik_d(): plyr = player.Player() e = SimpleNamespace(game_map='testmap', player=plyr) return dungeon.Dungeon(engine=e, test_map=toolkit.stair_map)
def test_generate_map__sets_new_maps_engine_ref(): e = SimpleNamespace(game_map='testmap', player=player.Player()) d = dungeon.Dungeon(engine=e, test_map=toolkit.stair_map) result = d.generate_floor() assert result.engine == e
def test_is_player__player_returns_True(): e = player.Player() assert e.is_player()
def test_player(): p = player.Player() p.parent = None # Gotta set this... return p