zelena.link_street(franka, "південь") saksahanskoho.link_street(franka, "схід") franka.link_street(saksahanskoho, "захід") saksahanskoho.link_street(shevchenka, "північ") shevchenka.link_street(saksahanskoho, "південь") shevchenka.link_street(halytska, "схід") halytska.link_street(shevchenka, "захід") halytska.link_street(krakivska, "північ") krakivska.link_street(halytska, "південь") zelena.link_street(kniazia_romana, "північ") kniazia_romana.link_street(zelena, "південь") kniazia_romana.link_street(halytska, "північ") halytska.link_street(kniazia_romana, "південь") curse_work = game.Enemy( "Магнат", "Злий багатій, який планує побудувати казино замість мого університету.") curse_work.set_conversation("Ха-ха-ха, я отримаю дохвіл швидше.") curse_work.set_weakness("дозвіл") kozelnytska.set_character(curse_work) posipaka_b = game.Enemy( "Посіпаки-батяри", "Кілька хлопців спортивної зовнішності найнятих магнатом, " "аби протидіяти мені.") posipaka_b.set_conversation("Ти нас не переможеш власноруч!!!") posipaka_b.set_weakness("поліцейський") franka.set_character(posipaka_b) posipaka_l = game.Enemy("Посіпака-лотер", "Ще один прихвостень магната.")
kitchen = game.Room("Kitchen") kitchen.set_description("A dank and dirty room buzzing with flies.") dining_hall = game.Room("Dining Hall") dining_hall.set_description("A large room with ornate golden decorations on each wall.") ballroom = game.Room("Ballroom") ballroom.set_description("A vast room with a shiny wooden floor. Huge candlesticks guard the entrance.") kitchen.link_room(dining_hall, "south") dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "west") ballroom.link_room(dining_hall, "east") dave = game.Enemy("Dave", "A smelly zombie") dave.set_conversation("What's up, dude! I'm hungry.") dave.set_weakness("cheese") dining_hall.set_character(dave) tabitha = game.Enemy("Tabitha", "An enormous spider with countless eyes and furry legs.") tabitha.set_conversation("Sssss....I'm so bored...") tabitha.set_weakness("book") ballroom.set_character(tabitha) cheese = game.Item("cheese") cheese.set_description("A large and smelly block of cheese") ballroom.set_item(cheese) book = game.Item("book") book.set_description("A really good book entitled 'Knitting for dummies'")
def Main(): player = game.Player() walls = game.LoadLevel2(Lvl0()) graphicInterface=GUI.characterPortrait() heart1 = GUI.heartContainers(43) heart2 = GUI.heartContainers(70) heart3 = GUI.heartContainers(97) enemies = [] enemies += [game.Enemy()] while True: screen.fill((0, 0, 200)) player.Controls(walls) player.Update() for bullet in player.bullets: for wall in walls: if wall.rect.colliderect(bullet.rect): player.bullets.remove(bullet) break for enemy in enemies: if bullet.rect.colliderect(enemy.rect): player.bullets.remove(bullet) enemy.life -= bullet.demage if enemy.life <= 0: enemies.remove(enemy) break bullet.Update() for wall in walls: if wall.type == 1: pygame.draw.rect(screen, (200, 200, 200), wall.rect) if wall.type == 2: pygame.draw.rect(screen, (100, 100, 100), wall.rect) if wall.rect.colliderect(player.hitBox): if wall.side == '1': player.rect.y = 625 player.hitBox.y = 625 if wall.side == '4': player.rect.x = 125 player.hitBox.x = 125 if wall.side == '2': player.rect.y = 50 player.hitBox.y = 50 if wall.side == '3': player.rect.x = 1000 player.hitBox.x = 1000 walls = game.LoadLevel2(wall.level) pygame.draw.rect(screen, (2, 250, 200), pygame.Rect(300, 85, player.abilCool, 5)) screen.blit(player.image, player.rect) screen.blit(graphicInterface.image, graphicInterface.rect) screen.blit(heart1.image, heart1.rect) screen.blit(heart2.image, heart2.rect) screen.blit(heart3.image, heart3.rect) for enemy in enemies: screen.blit(enemy.imageMaster, enemy.rect) for bullet in player.bullets: screen.blit(bullet.image, bullet.rect) for event in pygame.event.get(): if event.type == pygame.QUIT: exit(0) clock.tick(60) pygame.display.flip()
def setUp(self): self.game = game.Game('Python Game Project - Chai Grindean', 800, 800) self.player = game.Player('./Assets/player.png', 375, 700, 60, 60) self.enemy1 = game.Enemy('./Assets/monster4.png', 375, 700, 75, 50, 7) self.chest = game.GameObject('./Assets/chest.png', 375, 25, 50, 50)
import game kitchen = game.Room('Kitchen') kitchen.set_description('My favourite room with frige and food.') dining_room = game.Room('Dining Room') dining_room.set_description('Small room with big table.') bathroom = game.Room('Bathroom') bathroom.set_description('Toilet and shower. Thats all.') kitchen.room_location(dining_room, 'south') dining_room.room_location(kitchen, 'north') dining_room.room_location(bathroom, 'west') bathroom.room_location(dining_room, 'east') zombie = game.Enemy('Ted', 'A stuped zombie') zombie.set_conversation('Aaaaaaaarrrr!') zombie.set_weakness('sword') dining_room.set_character(zombie) spider = game.Enemy('Spidy', 'A small spider but so terrible.') spider.set_conversation('Now I living here. I must leave.') spider.set_weakness('magazine') bathroom.set_character(spider) sword = game.Item('sword') sword.set_description('A long acute sword.') bathroom.set_item(sword) magazine = game.Item('magazine') magazine.set_description('A boring magazine.') dining_room.set_item(magazine) current_room = kitchen bag = [] dead = False if __name__ == '__main__':
def main_game(): ''' Main function that organises the flow of the game ''' print_intro_screen() reception = game.Location('Reception') reception.set_description( 'Sheptytsky Center reception on the first floor next to entrance.\ With monitors, termometer and guards') basement = game.Location('Basement') basement.set_description( 'Sheptytsky Center Underground Basement with lots of tables,\ chairs, desks and sofas to study') it_space = game.Location('IT Space') it_space.set_description( 'Basement in Academic Corps with tables and comfortable chairs') trapezna = game.Location('Trapezna') trapezna.set_description('Place to eat. Large room with tables') striysky_park_south = game.Location('Stryiskyi Park South Side Entrance') striysky_park_south.set_description( 'Dark park. Nobody knows what a mistery and dangerous\ creatures hides inside') railway_station = game.Location('Children Railway Station') railway_station.set_description( 'Forgoten and abandoned childrens railway station.\ Old building and trains') striysky_park_fountain = game.Location('Stryiskyi Park Fountain') striysky_park_fountain.set_description( 'Fountain in Stryiskyi Park, with some\ infrastructure around') luno = game.Item('LUNO') luno.set_description('Mysterious and powerful object') luno.set_damage(150) guard = game.Character('Guard', 'Angry guard, you\'d better not mess up with him') guard_conv = read_conversation('guard.txt', False) guard.set_conversation(guard_conv) lotr1 = game.Enemy('Lotr 1', 'Aggressive tall and slim jerk, blocking you way') lotr1.set_properties(5, 7) lotr1_conv = read_conversation('lotr1.txt', False) lotr1.set_conversation(lotr1_conv) lotr1.not_passable() lotr2 = game.Enemy('Lotr 2', 'Angry fat but slow lotr, blocking you way') lotr2.set_properties(40, 3) lotr2_conv = read_conversation('lotr2.txt', False) lotr2.set_conversation(lotr2_conv) lotr2.not_passable() alcoholic = game.Enemy( 'Alcoholic', 'Old mysterous homeless alcoholic with white beard') alcoholic.set_properties(10, 10) alcoholic_conv = read_conversation('alcoholic.txt', False) alcoholic.set_conversation(alcoholic_conv) alcoholic.set_drop(luno) abaddon = game.Enemy('Abaddon', 'Mighty creature, blocking you way to win') abaddon.set_properties(125, 75) abaddon_conv = read_conversation('abaddon.txt', False) abaddon.set_conversation(abaddon_conv) abaddon.not_passable() vendor = game.Character('Vendor', 'Polite vendor in Trapezna') vendor_conv = read_conversation('vendor.txt', False) vendor.set_conversation(vendor_conv) spider = game.Enemy('Spider', 'Tiny spider hidding in his corner') spider.set_properties(1, 3) spider_conv = read_conversation('spider.txt', True) spider.set_conversation(spider_conv) hero = game.Hero() basement.link_loc(reception) reception.link_loc(striysky_park_south) reception.link_loc(it_space) reception.link_loc(trapezna) it_space.link_loc(trapezna) it_space.link_loc(striysky_park_south) it_space.link_loc(reception) trapezna.link_loc(reception) trapezna.link_loc(it_space) trapezna.link_loc(striysky_park_south) striysky_park_south.link_loc(railway_station) striysky_park_south.link_loc(striysky_park_fountain) striysky_park_south.link_loc(trapezna) striysky_park_south.link_loc(it_space) striysky_park_south.link_loc(reception) railway_station.link_loc(striysky_park_fountain) railway_station.link_loc(striysky_park_south) trapezna.set_character(vendor) reception.set_character(guard) striysky_park_south.set_character(lotr1) striysky_park_south.set_character(lotr2) it_space.set_character(spider) railway_station.set_character(alcoholic) striysky_park_fountain.set_character(abaddon) pencil = game.Item('Pencil') pencil.set_description('Sharp gray pencil') pencil.set_damage(20) basement.set_item(pencil) current_location = basement previous_location = None backpack = {} while True: time.sleep(0.9) print('\n') print(term.bold(f'HP: {hero.hp}')) print(f'{term.bold("BKPCK: ")}', end='') print(', '.join(backpack.keys())) time.sleep(0.2) could_pass = True current_location.get_details() time.sleep(0.3) personages, personages_dict = current_location.get_characters(), {} fightable_personages_dict = {} for personage in personages: time.sleep(0.1) personage.describe() personages_dict[personage.name] = personage if isinstance(personage, game.Enemy): fightable_personages_dict[personage.name] = personage could_pass = could_pass and personage.passable if current_location.name == 'Stryiskyi Park Fountain': if could_pass: print('Yey, you won') return print( 'This is the last stage. Defeat enemy, who block your pass here and you win' ) items, items_dict = current_location.get_items(), {} for item in items: item.describe() items_dict[item.name] = item print() linked_locs = [] print(f'{term.bold("[GO]: ")}', end='') for loc in current_location.linked_locs: linked_locs.append(loc.name) print(', '.join(linked_locs)) time.sleep(0.1) print(f'{term.bold("[TAKE]: ")}', end='') print(', '.join(items_dict.keys())) time.sleep(0.1) print(f'{term.bold("[TALK]: ")}', end='') print(', '.join(personages_dict.keys())) time.sleep(0.1) print(f'{term.bold("[FIGHT]: ")}', end='') print(', '.join(fightable_personages_dict.keys())) time.sleep(0.1) command = input('> ') if command.lower() == 'go': if not could_pass: print( 'It was a trap, you should defeat enemy who is blocking your way ahead' ) print( 'But still, you can return to the previous location. Returning...' ) current_location, previous_location = previous_location, current_location elif len(linked_locs) > 1: print('Where you want to go?') goto_loc = input('> ') if goto_loc in linked_locs: previous_location = current_location current_location = current_location.move(goto_loc) else: print(f'There is no such location as {goto_loc}') else: previous_location = current_location current_location = current_location.move(linked_locs[0]) elif command.lower() == 'talk': if personages_dict: if len(personages_dict) > 1: print('Whom you want to talk to?') talkto_personage = input('> ') if talkto_personage in list(personages_dict.keys()): personages_dict[talkto_personage].talk() else: print(f'Your can\'t talk to {talkto_personage}') else: personages_dict[list(personages_dict.keys())[0]].talk() else: print('There is nobody to talk to') elif command.lower() == 'take': if items_dict: if len(items_dict) > 1: print('What you wann take?') for item in items_dict: print(item) time.sleep(0.1) take_item = input('> ') if take_item in list(items_dict.keys()): backpack[take_item] = items_dict[take_item] current_location.items.remove(items_dict[take_item]) else: print(f'Your can\'t take to {take_item}') else: backpack_item_key = list(items_dict.keys())[0] backpack[backpack_item_key] = items_dict[backpack_item_key] current_location.items.remove( items_dict[backpack_item_key]) print(f'Put {backpack_item_key} in backpack') else: print('There is nothing to take') elif command.lower() == 'fight': if fightable_personages_dict: if len(fightable_personages_dict) > 1: print('Whom you want to fight with?') fightwith_personage = input('> ') if fightwith_personage not in list( fightable_personages_dict.keys()): print(f'You can\'t fight with {fightwith_personage}') continue else: fightwith_personage = list( fightable_personages_dict.keys())[0] adverser = fightable_personages_dict[fightwith_personage] print('What you wanna fight with?') for fightwith_item in backpack: backpack[fightwith_item].describe() fightwith_item = input('> ') if fightwith_item in backpack: fight_damage = adverser.fight( backpack[fightwith_item].damage) hero.hp -= fight_damage if hero.hp > 0: hero.victories += 1 print('Congrats, you won. Remaining health:', hero.hp) try: current_location.set_item(adverser.get_drop_item()) except AttributeError: pass current_location.characters.remove(adverser) else: print('Oups, you are dead.') break else: print(f'You have no {fightwith_item}') else: print('There is nobody to fight with') else: print('Hmm, seems like a wrong command')
game.Node(''), game.Node(''), game.Node(''), game.Node(''), game.Node(''), game.Node(''), game.Node(''), game.Node('') ] tile_types = [ 'start', 'end', 'recharge', 'weak', 'weak', 'weak', 'weak', 'strong', 'strong' ] weak_enemy = game.Enemy(30, 10) strong_enemy = game.Enemy(100, 35) def welcome_message(client): client.ttsmsg = 'Welcome to Lloydsville. Home of the wicked. Lets begin' def goodbye_message(client): client.ttsmsg = 'The Game is over. Good\'day' def start_scenario(client): client.ttsmsg = 'you made it but not to the end, you made it back to the start'
def Main(): player = game.Player() walls = game.LoadLevel(Lvl1()) graphicInterface = GUI.characterPortrait() heart1 = GUI.heartContainers(43) heart2 = GUI.heartContainers(70) heart3 = GUI.heartContainers(97) skill1 = GUI.skillMap(screen, 60, player.QCoolDown, "assets/GoFast.png") skill2 = GUI.skillMap(screen, 116, player.ECoolDown, "assets/Scare_Chase.png") enemyes = [] enemyes += [game.Enemy()] while True: screen.fill((0, 0, 0)) player.Controls(walls) player.Update() for bullet in player.bullets: for wall in walls: if wall.rect.colliderect(bullet.rect): player.bullets.remove(bullet) break for enemy in enemyes: if bullet.rect.colliderect(enemy.rect): player.bullets.remove(bullet) enemy.life -= bullet.demage if enemy.life <= 0: enemyes.remove(enemy) break bullet.Update() for wall in walls: if wall.type == 1: pygame.draw.rect(screen, (200, 200, 200), wall.rect) if wall.type == 2: pygame.draw.rect(screen, (100, 100, 100), wall.rect) if wall.rect.colliderect(player.hitBox): if wall.side == 1: player.rect.y = 625 player.hitBox.y = 625 if wall.side == 2: player.rect.x = 150 player.hitBox.x = 150 if wall.side == 3: player.rect.y = 50 player.hitBox.y = 50 if wall.side == 4: player.rect.x = 1025 player.hitBox.x = 1025 walls = game.LoadLevel(wall.level) screen.blit(player.image, player.rect) screen.blit(graphicInterface.image, graphicInterface.rect) screen.blit(heart1.image, heart1.rect) screen.blit(heart2.image, heart2.rect) screen.blit(heart3.image, heart3.rect) screen.blit(skill1.image, skill1.rect) pygame.draw.rect(screen, (2, 25, 255), pygame.Rect(0, 85, 50 / player.QProgress, 5)) screen.blit(skill2.image, skill2.rect) pygame.draw.rect(screen, (255, 25, 2), pygame.Rect(0, 141, 50 / player.EProgress, 5)) for enemy in enemyes: screen.blit(enemy.imageMaster, enemy.rect) for bullet in player.bullets: screen.blit(bullet.image, bullet.rect) for event in pygame.event.get(): if event.type == pygame.QUIT: exit(0) clock.tick(60) pygame.display.flip()
space = game.Building("IT-space") collegium = game.Building("Collegium") church.link_building(sheptytsky) sheptytsky.link_building(church) sheptytsky.link_building(collegium) sheptytsky.link_building(academic) academic.link_building(space) academic.link_building(sheptytsky) academic.link_building(collegium) space.link_building(academic) collegium.link_building(sheptytsky) collegium.link_building(academic) ############################################################### librarian = game.Enemy("Angry Librarian") librarian.set_conversation("WHERE ARE YOUR READER'S TICKET??") librarian.set_weakness("reader's ticket") sheptytsky.set_character(librarian) chef = game.Enemy("Greedy Chef") chef.set_conversation( "You don't have enough money or discount?.. It's your problem, loser))") chef.set_weakness("local card") academic.set_character(chef) teacher = game.Friend("Teacher") teacher.set_conversation("Don't forget your books.") space.set_character(teacher) conscience = game.Friend("Your Conscience")