class TestItem(TestCase): def setUp(self): self.item = Item("name") def tearDown(self): self.item = None def test_item_id_is_int(self): self.assertIsInstance(self.item.id, int) def test_item_name_is_str(self): self.assertIsInstance(self.item.name, str) def test_update_item_without_name(self): self.assertTrue(self.item.update(None), "Item must have a name") def test_update_item_with_invalid_name(self): self.assertTrue(self.item.update(["name"]), "Item name must be a string") def test_update_item(self): self.item.update("new name") self.assertEqual(self.item.name, "new name", msg="Method update should update the items name")
def delete_item(item_id): """Method to handle creating a bucket""" try: token = get_token() if isinstance(token, int): item = Item() response = item.delete_item(item_id) return response else: return invalid_token() except KeyError: return invalid_keys()
def __init__(self): self.kick = Item('skill', 'kick', 'Удар ногой', 'Отмашистый удар ногой', attack=5, cost=10) self.beat = Item('skill', 'beat', 'Удар кулаком', 'Не сильный удар', attack=3, cost=5)
def test_get_items_in_bucket(self): """Should check if bucket items are well fetched""" date_added = strftime("%Y-%m-%d", gmtime()) bucket_name = 'travel' item1 = Item('Kampala', date_added) item2 = Item('Nairobi', date_added) self.user.create_bucket(self.bucket) self.user.add_item(bucket_name, item1) self.user.add_item(bucket_name, item2) items = self.user.get_items(bucket_name) self.assertIsInstance(items, list) self.assertEqual(len(items), 2)
def __init__(self): self.fireball = Item('spell', 'fireball', 'Файербол', 'Просто огненный шар', attack=5, cost=10) self.heal = Item('spell', 'heal', 'Лечение малое', 'Лечит небольшие раны', heal=5, cost=7)
def get_items(bucket_id): """Method to handle getting all items in a bucket""" try: user_id = get_token() if isinstance(user_id, int): item = Item() response = item.get_items(bucket_id) return response else: return invalid_token() except KeyError: return invalid_keys()
def add_item(bucket_id): """Method to handle creating a bucket""" request.get_json(force=True) try: user_id = get_token() if isinstance(user_id, int): item_name = request.json['item'] item = Item() response = item.add_item(user_id, bucket_id, item_name) return response else: return invalid_token() except KeyError: return invalid_keys()
def add_item(self, item_name): """ Creates a new Item object and appends it to list of items in this shoppinglist :arg item_name: The name of the new item to be created :return id of the new Item if it has been created successfully, otherwise returns the error message generated """ if item_name is None or len(item_name) < 1: return "Item must have a name" if not isinstance(item_name, str): return "Item name must be a string" for item in self.items: if item.name.lower() == item_name.lower(): return 'Item `' + item_name + '` already added' # Create a new item new_item = Item(item_name) self.items.append(new_item)
def add_an_item(self, name): """ Add an item to a collection. """ if self.current_collection is not None: item = Item(name, collection=self.current_collection) self.db.add_item(item)
def __init__(self): self.kick = Item('skill', 'kick', 'Удар ногой', 'Отмашистый удар ногой', attack=5, cost=10) self.beat = Item('skill', 'beat', 'Удар кулаком', 'Не сильный удар', attack=3, cost=5) self.remana = Item('skill', 'remana', 'Медитация', 'Восстанавливает ману', remana=5, cost=7)
def create_item(bucket_name): """ Creates a bucket :param bucket_name: """ if 'id' not in session: return redirect(url_for('sign_in')) item_name = request.form['item-name'] date_added = strftime("%Y-%m-%d", gmtime()) new_item = Item(item_name, date_added) global current_user current_user.add_item(bucket_name, new_item) return redirect(url_for('single_bucket', bucket_name=bucket_name))
def __init__(self, map_file): self.music = Music() self.map_file = pytmx.load_pygame(map_file) # IDEA: is needed. Player here or in main class? self.player = Player() self.background_tiles = pygame.sprite.Group() self.collision_tiles = pygame.sprite.Group() self.items = pygame.sprite.Group() self.items.add(Item(3, 32, 32)) self.items.add(Item(1, 300, 320)) self.items.add(Item(0, 64, 64)) self.items.add(Item(0, 400, 400)) # Load tiles for x, y, image in self.map_file.layers[0].tiles(): self.background_tiles.add(Tile(x*self.map_file.tilewidth, y*self.map_file.tileheight, image)) for x, y, image in self.map_file.layers[1].tiles(): self.collision_tiles.add(Tile(x*self.map_file.tilewidth, y*self.map_file.tileheight, image))
def unitKey(self): key1 = False key2 = False for o in self.items: if o.title == "key_1": key1 = True elif o.title == "key_2": key2 = True if key2 and key1: items = [] for o in self.items: if o.title != "key_1" and o.title != "key_2": items.append(o) self.items = items self.add_item( Item("key_unit", "key", pygame.image.load("img/klucz.png").convert_alpha(), 0, 0)) self.itemsSize()
def __init__(self): #head self.init_cap = Item('head', 'init_cap', 'Кепка', 'Простая кепка', def_pass=1) #right_hand self.init_sword = Item('right_hand', 'init_sword', 'Меч', 'Ржавый меч', attack=3) #left_hand self.init_sheild = Item('left_hand', 'init_sheild', 'Щит', 'Прохудившийся щит', def_act=1) #cheast self.init_brp = Item('cheast', 'init_brp', 'Кольчуга', 'Ржавая кольчуга', def_pass=1) #pants self.init_pants = Item('pants', 'init_pants', 'Штаны', 'Просто штаны') #boots self.init_boots = Item('boots', 'init_boots', 'Ботинки', 'Старые ботинки', agility=1)
def setUp(self): self.item = Item("name")
def main(): run = True FPS = 60 level = 0 boss_spawned = False lives = 5 main_font = pygame.font.SysFont("comicsans", 50) stats_font = pygame.font.SysFont("comicsans", 30) lost_font = pygame.font.SysFont("comicsans", 60) player_items = [] dropped_items = [] enemies = [] dificulty = 4 wave_length = dificulty enemy_vel = 1 level_to_boss = 4 killed_bosses = 0 player_vel = 5 laser_vel = 5 player = Player(300, 630) player_damage = player.damage clock = pygame.time.Clock() lost = False lost_count = 0 won = False def redraw_window(): nonlocal player_vel nonlocal player_damage WIN.blit(BG, (0, 0)) # draw text lives_label = main_font.render(f"Lives: {lives}", 1, (255, 255, 255)) level_label = main_font.render(f"Level: {level}", 1, (255, 255, 255)) speed_label = stats_font.render(f"Speed: {player_vel-4}", 1, (255, 255, 255)) damage_label = stats_font.render(f"Damage: {player_damage}", 1, (255, 255, 255)) WIN.blit(lives_label, (10, 10)) # Displaying lives WIN.blit( level_label, (WIDTH - level_label.get_width() - 10, 10)) # Displaying level WIN.blit(damage_label, (WIDTH - level_label.get_width() + 10, HEIGHT - speed_label.get_height())) # Displaying player damage WIN.blit(speed_label, (WIDTH - speed_label.get_width() - 10, HEIGHT - speed_label.get_height() * 2)) # Displaying player speed for item in player_items: item.draw(WIN) for item in dropped_items: item.draw(WIN) if collide(item, player): dropped_items.remove(item) item.y = HEIGHT - item.img.get_height() / 2 - len( player_items) * 40 - 5 item.x = 3 if item.bonus != 'damage': item.width, item.height = 70, 70 else: item.width, item.height = 90, 90 if item.bonus == 'speed': player_vel += 1 elif item.bonus == 'damage': player_damage += 5 player_items.append(item) for enemy in enemies: # Drawing all enemies if enemy.health > 0 and enemy.type != 'boss': enemy.draw(WIN) enemy.healthbar(WIN) elif enemy.type == 'boss': enemy.draw(WIN) else: enemies.remove(enemy) player.draw(WIN) # Drawig player player.damage = player_damage if lost: # If layer lost lost_label = lost_font.render("You Lost!", 1, (255, 255, 255)) WIN.blit(lost_label, (WIDTH / 2 - lost_label.get_width() / 2, 350)) if won: # If plyer won won_label = lost_font.render("You Won!", 1, (255, 255, 255)) WIN.blit(won_label, (WIDTH / 2 - won_label.get_width() / 2, 350)) player.final_scene() pygame.display.update() while run: clock.tick(FPS) redraw_window() if lives <= 0 or player.health <= 0: # That means that player lost lost = True lost_count += 1 if killed_bosses == 3: # That means that player won won = True lost_count += 1 if lost: if lost_count > FPS * 3: run = False else: continue if won: if player.final_off_screen: run = False if len( enemies ) == 0 and level < level_to_boss and not boss_spawned and not won: # If player killed all enemies level += 1 wave_length += int(wave_length / 2) for i in range(wave_length): # Adding new enemies enemy = Enemy(random.randrange(50, WIDTH - 100), random.randrange(-1300, -100), random.choice(["red", "blue", "green"]), 10 + level * 4) enemies.append(enemy) elif level == level_to_boss and not boss_spawned: # If it is the boss level enemies = [] # Removing all enemies enemies.append( Boss(WIDTH / 2 - 130, -350, killed_bosses, 500 * (killed_bosses + 1))) # Spawning boss boss_spawned = True for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() break keys = pygame.key.get_pressed() if keys[pygame.K_a] and player.x - player_vel > 0 and not won: # left player.x -= player_vel if keys[pygame.K_d] and player.x + player_vel + player.get_width( ) < WIDTH and not won: # right player.x += player_vel if keys[pygame.K_w] and player.y - player_vel > 0 and not won: # up player.y -= player_vel if keys[pygame.K_s] and player.y + player_vel + player.get_height( ) + 15 < HEIGHT and not won: # down player.y += player_vel if keys[pygame.K_SPACE] and not won: # shoot player.shoot() for enemy in enemies[:]: enemy.move(enemy_vel) enemy.move_lasers(laser_vel, player) if random.randrange(0, 4 * 60) == 1 and enemy.health > 0: enemy.shoot() if collide(enemy, player): # If enemy colliding with player if enemy.type == 'boss': player.health -= 0.3 else: player.health -= 10 enemies.remove(enemy) elif enemy.y + enemy.get_height() > HEIGHT and enemy.type != 'boss': lives -= 1 enemies.remove(enemy) elif enemy.type == 'boss' and enemy.killed: enemies = [] if killed_bosses < 2: new_item = Item(enemy.x, enemy.y, killed_bosses) dropped_items.append(new_item) boss_spawned = False level_to_boss += dificulty killed_bosses += 1 player.move_lasers(-laser_vel, enemies)
def create_items(self): """Create master Item List.""" return [Item("Potion", "potion", "Heals 50 HP", 50), Item("Hi-Potion", "potion", "Heals 100 HP", 100), Item("Super Potion", "potion", "Heals 500 HP", 500)]
def update(self, time_delta, objects, enemies=None): p_s = pygame.mixer.Sound('sounds/foot.ogg') p_s.set_volume(0.1) self.last_damage += 1 if self.direction == 0: self.set_sprite(Player.player_sprite_right[0]) else: self.set_sprite(Player.player_sprite_left[0]) keys = pygame.key.get_pressed() old_x = self.get_x() old_y = self.get_y() horizontal_direction = 0 if keys[K_d]: self.direction = 0 horizontal_direction += 1 self.set_sprite(Player.player_sprite_right[self.index // 10]) self.index += 1 if self.index > 20: self.index = 0 if keys[K_a]: self.direction = 1 horizontal_direction -= 1 self.set_sprite(Player.player_sprite_left[self.index // 10]) self.index += 1 if self.index > 20: self.index = 0 self.set_x(self._x + self.speed * (time_delta / 1000) * horizontal_direction) for obj in pygame.sprite.spritecollide(self, objects, dokill=False): inventory = Inventory.get_instance() if obj.type == 'rocket': self.hp = -1 elif obj.type == 'rock': if not obj.push( self.speed * (time_delta / 1000) * horizontal_direction, 0, objects): self.set_x(old_x) break elif obj.type == 'rainbow1': if not obj.push( self.speed * (time_delta / 1000) * horizontal_direction, 0, objects): self.set_x(old_x) break elif obj.type == 'rainbow2': if not obj.push( self.speed * (time_delta / 1000) * horizontal_direction, 0, objects): self.set_x(old_x) break elif obj.type == 'key': item = Item( "key_{}".format(obj.part), "key_{}".format(obj.part), pygame.image.load('img/key_{}.png'.format(obj.part)), 0, 0) inventory.add_item(item) if inventory.check_engine(): pass obj.cary = True if obj.part in (1, 2): inventory.unitKey() obj.kill() elif obj.type == 'door' and inventory.checkKey(): obj.sound = obj.sound.play() obj.kill() elif obj.type == 'item': inventory.add_item(obj) obj.kill() elif obj.type in ('ghost', 'monster', 'saw'): self.take_damage() elif not obj.type == "background" and obj.type != 'button': self.set_x(old_x) break vertical_direction = 0 if keys[K_s]: vertical_direction -= 1 if self.direction == 0: self.set_sprite(Player.player_sprite_right[self.index // 10]) self.index += 1 if self.index > 20: self.index = 0 if self.direction == 1: self.set_sprite(Player.player_sprite_left[self.index // 10]) self.index += 1 if self.index > 20: self.index = 0 if keys[K_w]: vertical_direction += 1 old_y = self.get_y() if self.direction == 0: self.set_sprite(Player.player_sprite_right[self.index // 10]) self.index += 1 if self.index > 20: self.index = 0 if self.direction == 1: self.set_sprite(Player.player_sprite_left[self.index // 10]) self.index += 1 if self.index > 20: self.index = 0 self.set_y(self._y - self.speed * (time_delta / 1000) * vertical_direction) inventory = Inventory.get_instance() for obj in pygame.sprite.spritecollide(self, objects, dokill=False): if obj.type == 'rocket': self.hp = -1 elif obj.type == 'rock': if not obj.push( 0, self.speed * (time_delta / 1000) * -vertical_direction, objects): self.set_y(old_y) break elif obj.type == 'rainbow1': if not obj.push( 0, self.speed * (time_delta / 1000) * -vertical_direction, objects): self.set_y(old_y) break elif obj.type == 'rainbow2': if not obj.push( 0, self.speed * (time_delta / 1000) * -vertical_direction, objects): self.set_y(old_y) elif obj.type == 'key': item = Item( "key_{}".format(obj.part), "key_{}".format(obj.part), pygame.image.load('img/key_{}.png'.format(obj.part)), 0, 0) inventory.add_item(item) if inventory.check_engine(): pass obj.cary = True inventory.unitKey() obj.kill() elif obj.type == 'item': inventory.add_item(obj) obj.kill() elif obj.type == 'door' and inventory.checkKey(): obj.sound = obj.sound.play() obj.kill() elif obj.type in ('ghost', 'monster', 'saw'): self.take_damage() elif not obj.type == "background" and obj.type != 'button': self.set_y(old_y) break if enemies is not None: for obj in pygame.sprite.spritecollide(self, enemies, dokill=False): if obj.type == 'arrow': if obj.horizontal_direction != 0 or obj.vertical_direction != 0: self.take_damage() item = Item("arrow", "arrow", pygame.image.load('img/strzala_prawo.png'), 0, 0) inventory.add_item(item) obj.cary = True obj.kill()
def main(): pygame.init() # generate windows game # configure windows size # Title Game and Icone pygame.display.set_icon(ICONE) pygame.display.set_caption("Nadir, Save mac_gyver !!") screen = pygame.display.set_mode((450, 450)) #Loading screen welcome screen.blit(BLACK_GROUND, (0, 0)) screen.blit(WELCOME, (-2, 35)) #+++++++++++The Main Loop+++++++## MAIN_LOOP = True while MAIN_LOOP: #refresh the screen pygame.display.flip() #++++++++The Welcome LOOP+++++++++## WELCOME_LOOP = True while WELCOME_LOOP: #LOOP Speed Limit pygame.time.Clock().tick(30) for event in pygame.event.get(): #Quit the program if event.type == QUIT: print("See you next time !") MAIN_LOOP = False WELCOME_LOOP = False GAME_LOOP = False #Quit Welcome loop to enter in game loop if event.type == KEYDOWN and event.key == K_RETURN: #######WELCOME TO THE GAME########## ###SOUNDTRACK.stop() screen.blit(BACKGROUND, (0, 0)) pygame.display.flip() time.sleep(1) WELCOME_LOOP = False GAME_LOOP = True #Load the game's map FILE = "ressource/lab.txt" print("Menu terminé, passage au jeu.") if FILE != "": #We make sure that the file really exists and is not empty #load the background screen.blit(BACKGROUND, (30, 30)) #generate the labyrinth labyrinthe = Labyrinthe(FILE) labyrinthe.generate() labyrinthe.display(screen) # Pour le moment on met les items de côté. #Get the items in the labyrinthe seringue = Item("seringue", SERINGUE, labyrinthe) seringue.locate_item() seringue.pin_items() ether = Item("ether", ETHER, labyrinthe) ether.locate_item() ether.pin_items() tube = Item("tube", TUBE, labyrinthe) tube.locate_item() tube.pin_items() #Add arrived icon ARRIVED = pygame.image.load( "ressource/arrived.JPG").convert_alpha() screen.blit(ARRIVED, (390, 420)) #Add mac_gyver in the Labyrinth with his position mac_gyver = Human(labyrinthe) screen.blit(MACGYVER_IMAGE, (0, 0)) #++++++++GAME_LOOP++++++++++++++++++# #Initialyse at every game_loop an empty list to put the elements inside TOOLS = [] while GAME_LOOP: pygame.time.Clock().tick(30) for event in pygame.event.get(): #Quit the program if event.type == QUIT: print("See you next time !") MAIN_LOOP = False GAME_LOOP = False elif event.type == KEYDOWN: #Quit the game and go back Home if event.key == K_ESCAPE: GAME_LOOP = False #create event to move player elif event.key == K_RIGHT: mac_gyver.move("right") elif event.key == K_LEFT: mac_gyver.move("left") elif event.key == K_UP: mac_gyver.move("up") elif event.key == K_DOWN: mac_gyver.move("down") #Display the game board screen.blit(BACKGROUND, (0, 0)) labyrinthe.display(screen) screen.blit(MACGYVER_IMAGE, (mac_gyver.x, mac_gyver.y)) pygame.display.flip() #Add conditionnal display of Element #tube.display_item(screen, mac_gyver, TOOLS) #seringue.display_item(screen, mac_gyver, TOOLS) #ether.display_item(screen, mac_gyver, TOOLS) if labyrinthe.grid[mac_gyver.sprite_x][mac_gyver.sprite_y] == "a": #The player wins if he collects the tree items if mac_gyver.inventory < 3: #+++++DISPLAY GAME OVER++++# screen.blit(GAMEOVER, (150 + 30, 150 + 30)) pygame.display.flip() time.sleep(2) #+++++++++++++++++++++++++++++# print("You loose") GAME_LOOP = False #+++++++++++++++++++++++++++++# if mac_gyver.inventory == 3: #+++++DISPLAY YOU WIN+++++++++# screen.blit(WIN, (100 + 30, 150 + 30)) pygame.display.flip() time.sleep(2) #+++++++++++++++++++++++++++++# print("You win!") GAME_LOOP = False
def setUp(self): self.collection1 = Collection('Avatar') self.item1 = Item('Aang')
def get_objects(self) -> list: game_state = GameState.get_instance() """Return all objects in current room""" if self.rooms[self._y][self._x] is None: self.load_room(self._x, self._y) # TODO: refactor :) objects = [] for y, row in enumerate(self.rooms[self._y][self._x]): for x, tile in enumerate(row): if tile == '#': objects.append(Wall(x * 16, y * 16)) elif tile == '$': objects.append(Teleport(x * 16, y * 16)) elif tile == '{': objects.append(Door(x * 16, y * 16)) elif tile == '}': objects.append(Door(x * 16, y * 16, 'right')) elif tile == ']': objects.append(Door(x * 16, y * 16, 'up')) elif tile == '[': objects.append(Door(x * 16, y * 16, 'down')) elif tile == 'r': objects.append(Rock(x * 16 + 1, y * 16 + 1)) elif tile == 'k': inventory = Inventory.get_instance() if not inventory.checkKey(): objects.append(Key(x * 16, y * 16, 1)) elif tile == 'l': objects.append(Key(x * 16, y * 16, 2)) elif tile == 'g': objects.append(Ghost(x * 16, y * 16)) elif tile == 'b': objects.append(Button(x * 16, y * 16)) elif tile == 't': objects.append(Trellis(x * 16, y * 16)) elif tile == 'e': objects.append( Wall( x * 16, y * 16, pygame.image.load('img/dungeon_wall_broken.png'). convert_alpha())) elif tile == 'j': objects.append( Wall( x * 16, y * 16, pygame.image.load('img/dungeon_spiders_web.png'). convert_alpha())) elif tile == 'a': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/dungeon_bones.png').convert_alpha())) elif tile == 'c': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/dungeon_skull.png').convert_alpha())) elif tile == 'h': objects.append( Background( x * 16, y * 16, pygame.image.load( 'img/candy_rainbow_wall.png').convert_alpha())) elif tile == 'm': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/candy_wall.png').convert_alpha())) elif tile == 'd': objects.append( Monster(x * 16, y * 16, 20, 'sounds/demon.ogg', 'img/demon_0.png', 'demon', 5)) elif tile == 'n': objects.append( Monster(x * 16, y * 16, 15, 'sounds/demon.ogg', 'img/candy_mob_0.png', 'candy_mob', 0)) elif tile == 'o': objects.append( Monster(x * 16, y * 16, 20, 'sounds/demon.ogg', 'img/rainbow_mob_0.png', 'rainbow_mob', 2)) elif tile == 'z': objects.append( Background( x * 16, y * 16, pygame.image.load('img/dungeon_background2.png'). convert_alpha())) elif tile == 'p': objects.append( Trellis( x * 16, y * 16, pygame.image.load( 'img/krata2.png').convert_alpha())) elif tile == 'q': objects.append( Background( x * 16, y * 16, pygame.image.load('img/candy_rainbow_wall2.png'). convert_alpha())) elif tile == 'x': objects.append(Rainbow_1(x * 16, y * 16)) elif tile == '&': objects.append(Rainbow_2(x * 16, y * 16)) elif tile == 's': objects.append(Key(x * 16, y * 16, 3)) elif tile == 'u': objects.append(Key(x * 16, y * 16, 4)) elif tile == '+': objects.append(Button_rainbow1(x * 16, y * 16)) elif tile == '-': objects.append(Button_rainbow2(x * 16, y * 16)) elif tile == 'f': objects.append(Background(x * 16, y * 16)) elif tile == 'v': objects.append(Saw(x * 16, y * 16)) objects.append( Background( x * 16, y * 16, pygame.image.load( 'img/saw_track.png').convert_alpha())) elif tile == '|': objects.append(Saw(x * 16, y * 16, False)) objects.append( Background( x * 16, y * 16, pygame.image.load( 'img/saw_track_v.png').convert_alpha())) elif tile == '=': objects.append( Item( "hp_potion", "hp_potion", pygame.image.load( 'img/hp_potion.png').convert_alpha(), x * 16, y * 16)) elif tile == 'y': objects.append( Monster(x * 16, y * 16, 12, 'sounds/demon.ogg', 'img/dr_pehape_0.png', 'dr_pehape', 0, 4, False)) game_state.sound = pygame.mixer.Sound('sounds/boss_t.ogg') elif tile == '*': objects.append( Background( x * 16, y * 16, pygame.image.load( 'img/saw_track.png').convert_alpha())) elif tile == '@': objects.append( Background( x * 16, y * 16, pygame.image.load( 'img/saw_track_v.png').convert_alpha())) elif tile == '`': objects.append(Resp(x * 16, y * 16)) elif tile == ',': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/rocket_piece1.png').convert_alpha(), "rocket")) elif tile == '<': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/rocket_piece2.png').convert_alpha(), "rocket")) elif tile == '.': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/rocket_piece3.png').convert_alpha(), "rocket")) elif tile == '>': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/rocket_piece4.png').convert_alpha(), "rocket")) elif tile == ';': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/rocket_piece5.png').convert_alpha(), "rocket")) elif tile == ':': objects.append( Wall( x * 16, y * 16, pygame.image.load( 'img/rocket_piece6.png').convert_alpha(), "rocket")) elif tile == '?': objects.append(Trellis_rainbow1(x * 16, y * 16)) elif tile == '/': objects.append(Trellis_rainbow2(x * 16, y * 16)) return objects
def setUp(self): date_added = strftime("%Y-%m-%d", gmtime()) self.user = User('*****@*****.**', 'password', 'Patrick') self.bucket = Bucket('travel', 'cities', 2) self.item = Item('Kampala', date_added)
def setUp(self): date_added = strftime("%Y-%m-%d", gmtime()) self.activity = Item('Try chinese food', date_added)
from classes.player import Player, bcolors from classes.weapon import Weapon from classes.spell import Spell from classes.item import Item pj1 = Player("Rhogar", 12, 45, 18, 16, 13, 14, 9, 7, 16) pj2 = Player("Berto", 30, 30, 12, 12, 10, 18, 10, 10, 10) sword = Weapon(6, "Sword", 1) healingSpell = Spell(12, 7, 5) fireball = Spell(6, 1, 12) advantager = Item(1, 'common', 1) advantager.use(pj1, pj2) def menu(): print("Acciones") print("1. Usar espada") print("2. Curar") print("3. Usar bola de fuego") print("Elije una acción:", end="") return input() while (pj1.hp > 0 and pj2.hp > 0): '''Turno jugador''' action = menu() print(action) if (int(action) == 1): if (pj1.hit(pj2.armor)): dmg = sword.attack() pj2.hp -= dmg
def _make_item(self, row): """ Create an item object using a row from a result set. """ return Item(row['item_name'], row['item_id'], self._make_collection(row))
def game(screen): """Load levels""" global welcome, lost, game_sound game_state = GameState.get_instance() inventory = Inventory.get_instance() inventory_board = pygame.Surface(screen.get_size()) item = Item("arrow", "arrow", pygame.image.load('img/strzala_prawo.png'), 0, 0) item2 = Item("arrow", "arrow", pygame.image.load('img/strzala_prawo.png'), 0, 0) item3 = Item("arrow", "arrow", pygame.image.load('img/strzala_prawo.png'), 0, 0) Inventory.get_instance().add_item(item) Inventory.get_instance().add_item(item2) Inventory.get_instance().add_item(item3) game_state.reset() room_manager.set_lvl(lvl) """Sound""" game_menu.sound.stop() if (room_manager.get_lvl() == 1): print('test') game_sound = pygame.mixer.Sound('sounds/LOCHY-theme.ogg') game_sound.play(-1) game_sound.set_volume(0.15) board = pygame.Surface((640, 640)) run = True counter = 0 while run: counter += 1 board, welcome_2 = calculate_scale(screen.get_size(), board, welcome, force=True) board.blit(welcome_2, (0, 0)) screen.fill((0, 0, 0)) screen.blit(board, ((screen.get_size()[0] - board.get_size()[0])/2, 0)) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.KEYDOWN and counter > 300: run = False player = Player.get_instance() player.set_x(128) player.set_y(128) show_s = True resett = True while(not game_state.exit): objects_list = room_manager.get_objects() old_room_obj = room(screen, board, objects_list, inventory, inventory_board) player = Player.get_instance() if player.get_y() < 0: room_manager.move_up() elif player.get_y() + player._height > 16 * 16: room_manager.move_down() elif player.get_x() < 0: room_manager.move_left() elif player.get_x() + player._width > 16 * 16: room_manager.move_right() if old_room_obj is not None: play_room_animation(old_room_obj, room_manager.get_objects(), board, inventory, inventory_board) GameObject.clear_objects_list() if game_state.next_lvl: game_state.next_lvl = False room_manager.set_lvl(room_manager.get_lvl() + 1) if (room_manager.get_lvl() == 2 and resett): resett = False game_sound.stop() game_sound = pygame.mixer.Sound('sounds/hepi-theme-final.ogg') game_sound.play(-1) game_sound.set_volume(0.95) run = True counter = 0 while run and show_s and room_manager.get_lvl() == 2: counter += 1 board, lost3 = calculate_scale(screen.get_size(), board, lost2, force=True) board.blit(lost3, (0, 0)) screen.fill((0, 0, 0)) screen.blit(board, ((screen.get_size()[0] - board.get_size()[0])/2, 0)) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.KEYDOWN and counter > 300: run = False show_s = False run = True counter = 0 while run: counter += 1 if Player.get_instance().hp == 0: board, lost_2 = calculate_scale(screen.get_size(), board, lost, force=True) else: board, lost_2 = calculate_scale(screen.get_size(), board, win, force=True) board.blit(lost_2, (0, 0)) screen.fill((0, 0, 0)) screen.blit(board, ((screen.get_size()[0] - board.get_size()[0])/2, 0)) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT and counter > 300: run = False if event.type == pygame.KEYDOWN and counter > 300: run = False exit(0)
from classes.magic import Spell from classes.item import Item # Create Black Magic fire = Spell("Fire", 10, 100, "black") thunder = Spell("Thnder", 10, 200, "black") blizzard = Spell("Blizzard", 10, 100, "black") meteor = Spell("Meteor", 40, 500, "black") quake = Spell("Quake", 44, 440, "black") # Create White Magic cure = Spell("Cure", 12, 120, "white") restore = Spell("Restore", 18, 200, "white") # Create some Items potion = Item("Potion", "potion", "Heals 50 HP", 50) hi_potion = Item("Hi-Potion", "potion", "Heals 100 HP", 100) super_potion = Item("Super Potion", "potion", "Heals 500 HP", 500) elixer = Item("Elixer", "elixer", "Fully restores HP/MP of one parter member", 9999) mega_elixer = Item("MegaElixer", "elixer", "Fully restores HP/MP", 9999) grenade = Item("Grenade", "attack", "Deals 50 damage", 50) player_spells = [fire, thunder, blizzard, meteor, cure, restore] player_items = [{ 'item': potion, 'quantity': 4 }, { 'item': hi_potion, 'quantity': 2 }, { 'item': elixer, 'quantity': 2 }, { 'item': mega_elixer, 'quantity': 2 }, { 'item': grenade, 'quantity': 10 }] enemy_spells = [meteor, blizzard, cure]
def add_item(self, _type, level): name = random.choice(config.item_names) item = Item(type=_type, name=name, level=level) self.items.append(item)