def main(): print_header() rolls = build_three_rolls() name = get_players_name() player1 = Person(name) player2 = Person('Computer') game_loop(player1, player2, rolls)
def game_loop(): app_logger.trace('Game loop starting') player1 = Person(get_player_name()) player2 = Person('Computer') rolls = read_battle_data_from_file_and_create_rolls() p1_win = p2_win = 0 cnt = 1 while cnt <= 3: p2_roll = random.choice(list(rolls.values())) print() print('----------------------------------------------------------') print(f' Hello {player1.name}, here are your available rolls ') print('----------------------------------------------------------') print() rolls_with_index_nr = list_rolls() print('\n') selection = int(input('Please select your roll: ')) p1_roll = rolls[rolls_with_index_nr[selection]] outcome = p1_roll.can_defeat(p2_roll) print( f'{player1.name} selected {p1_roll.name}. {player2.name} selected {p2_roll.name}.' ) if outcome == 'yes': p1_win += 1 print(f'{player1.name} wins this round') if outcome == 'no': p2_win += 1 print(f'{player2.name} wins this round!!') if outcome == 'draw': p1_win += 1 p2_win += 1 print(f'Its a tie!!') cnt += 1 app_logger.trace('Game loop ended.') app_logger.trace('Finding the winner!') print('*************************************************') if p1_win == p2_win: print('Everyone is a winner!!') if p1_win > p2_win: print(f'{player1.name} is the final Winner!!!') if p2_win > p1_win: print(f'{player2.name} is the final Winner!!!') print('*************************************************')
def test_rotating_order_of_players_works_correctly(self): team1 = Team('Malinka', (Person('Ivan'), Person('Gosho'))) team2 = Team('Yagodka', (Person('Pesho'), Person('Tosho'))) players_order = [ team1.teammates[0], team2.teammates[0], team1.teammates[1], team2.teammates[1] ] result = Game.rotate_players_order(players_order) self.assertEqual(result, [ team2.teammates[0], team1.teammates[1], team2.teammates[1], team1.teammates[0] ]) result2 = Game.rotate_players_order(result) self.assertEqual(result2, [ team1.teammates[1], team2.teammates[1], team1.teammates[0], team2.teammates[0] ])
def test_get_player_announcements_point_function_should_return_addition_of_announcements_points( self): team2 = Team('Yagodka', (Person('Pesho'), Person('Tosho'))) team2.teammates[1].cards = [ Card('K', 'S'), Card('Q', 'S'), Card('J', 'S'), Card('A', 'S'), Card('7', 'S'), Card('8', 'S'), Card('9', 'S') ] team2.teammates[1].cards = Utls.sort_cards(team2.teammates[1].cards) contracts = 'all trumps' result = Game.get_player_announcements_ploints(contracts, team2.teammates[1]) contracts = 'no trumps' result2 = Game.get_player_announcements_ploints( contracts, team2.teammates[1]) contracts = 'S' result3 = Game.get_player_announcements_ploints( contracts, team2.teammates[1]) contracts = 'H' result4 = Game.get_player_announcements_ploints( contracts, team2.teammates[1]) self.assertEqual(result, 90) self.assertEqual(result2, 0) self.assertEqual(result3, 90) self.assertEqual(result4, 70)
dead = True break return dead # Print stats of all the players def show_stats(players: list): for player in players: player.get_stat() # Initialize players # More general way using list, so we can expand the game easily if we want to add more players players = [] players.append(Person("Thor", 100, 100, 30)) players.append(Person("Thanos", 100, 100, 25)) # Game initial prints print("This game is ....") for player in players: player.get_stat() # Highlander Game "There can be only one!" # This is the main game loop while (len(players) > 1): # If there are more players than just ONE while not someone_died( players): # as long as they have health, then they fight for player in players: player.take_dmg(20) # for now
"quantity": 5 }, { "name": "MegaElixer", "type": "elixer", "description": "Fully restores party's HP/MP", "prop": 9999, "quantity": 2 }, { "name": "Grenade", "type": "attack", "description": "Deals 500 damage", "prop": 500, "quantity": 5 }] player = Person(500, 65, 60, 34, magic, items) enemy = Person(1200, 65, 45, 25, magic, items) running = True while running: print("===================================================") player.choose_action() choice = input("Choose action: ") index = int(choice) - 1 #action process if index == 0: dmg = player.hit_damage() enemy.take_damage(dmg) print("You hit for", dmg, "points!") enemy_dmg = enemy.hit_damage()
from game import Person from random import randint from random import randrange import random import time import os import textwrap from magic import Magic # instantiate objects from imported Magic class fire = Magic("Fire", 10, 30, "dark") wind = Magic("Wind", 15, 50, "dark") ice = Magic("Ice", 20, 70, "dark") magic_list = [fire, wind, ice] # instantiate objects from imported Person class player = Person("Knight", 150, 50, 50, magic_list) enemy = Person("Vampire", 100, 100, 20, magic_list) # clear terminal and game begins os.system("cls") # game title print(""" ############################### ## Welcome to Castle Crawler ## ############################### """) # print stats before battle begins player.stats() enemy.stats()
from game import Person, Colors magic = [{ "name": "Fire", "cost": 10, "dmg": 60 }, { "name": "Thunder", "cost": 10, "dmg": 60 }, { "name": "Blizzard", "cost": 10, "dmg": 60 }] player = Person(460, 65, 60, 34, magic) print(player.generate_damage()) print(player.generate_damage()) print(player.generate_damage())
"quantity": 5 }, { "item": superpotion, "quantity": 5 }, { "item": elixer, "quantity": 5 }, { "item": hielixer, "quantity": 2 }, { "item": grenade, "quantity": 5 }] player1 = Person("Valos: ", 3260, 132, 300, 34, player_spells, player_items) player2 = Person("Nick: ", 4160, 188, 311, 34, player_spells, player_items) player3 = Person("Robot: ", 3089, 174, 288, 34, player_spells, player_items) enemy = Person("Magus", 11200, 701, 525, 25, [], []) players = [player1, player2, player3] running = True i = 0 print(bcolors.FAIL + bcolors.BOLD + "AN ENEMY ATTACKS" + bcolors.ENDC) while running: print("================") print("\n\n")
# items potion=items("potion","potion","Heals 100 hp",100) hipotion=items("Hi-Potion","potion","Heals 150 hp",150) super_potion=items("Super-Potion","potion","Heals 500 hp",500) elixir=items("elxir","elixir","fully restores HP/MP of one party member",99999) mega_elixir=items("mega elixir","elixir","fully restores HP/MP of party ",99999) grenade=items("Grenade","attack","Deals 500 damage ",500) player_spells=[fire,thunder,quake,cure,cura] enemy_spells=[fire,thunder,cure] player_items=[{"item":potion,"quantity":5},{"item":hipotion,"quantity":5}, {"item":super_potion,"quantity":1},{"item":elixir,"quantity":2}, {"item":mega_elixir,"quantity":1},{"item":grenade,"quantity":2}] # players player0 =Person("VALOS ",3060,65,200,34,player_spells,player_items) player1=Person("ROBOT ",3460,65,180,34,player_spells,player_items) player2=Person("BATMAN ",4160,65,210,34,player_spells,player_items) players=[player0,player1,player2] #enemies enemy1=Person("IMP ",500,65,325,25,enemy_spells,[]) enemy2=Person("MAGUS ",6000,65,700,25,enemy_spells,[]) enemy3=Person("IMP ",600,65,300,25,enemy_spells,[]) enemies=[enemy1,enemy2,enemy3] running=True i=0 print(bcolors.FAIL+bcolors.BOLD+"ENEMY STRIKES"+bcolors.ENDC)
}, { "item": superpotion, "quantity": 5 }, { "item": elixer, "quantity": 5 }, { "item": hielixer, "quantity": 2 }, { "item": grenade, "quantity": 5 }] #instantiate people Player1 = Person("Mike ", 1500, 300, 60, 34, player_spells, player_items, "alive") Player2 = Person("Ali ", 2000, 200, 60, 34, player_spells, player_items, "alive") Player3 = Person("Floyd ", 1000, 100, 60, 34, player_spells, player_items, "alive") Enemy1 = Person("Devil ", 5000, 500, 500, 25, enemy_spells, [], "alive") Enemy2 = Person("Sutar ", 1000, 100, 100, 25, enemy_spells, [], "alive") Enemy3 = Person("Mago ", 500, 100, 100, 25, enemy_spells, [], "alive") PlayerL = [Player1, Player2, Player3] Enemies = [Enemy1, Enemy2, Enemy3] running = True i = 0 print(bcolors.FAIL + bcolors.BOLD + "AN Enemy Attacks!" + bcolors.ENDC) while running: print("===================")
}, { "item": superpotion, "quantity": 5 }, { "item": elixer, "quantity": 5 }, { "item": hielixer, "quantity": 2 }, { "item": grenade, "quantity": 5 }] # Instantiate People player1 = Person("Valos:", 3260, 132, 300, 34, player_spells, player_items) player2 = Person("Nick :", 4160, 188, 311, 34, player_spells, player_items) player3 = Person("Robot:", 3089, 174, 288, 34, player_spells, player_items) enemy1 = Person("Imp ", 1250, 130, 560, 325, enemy_spells, []) enemy2 = Person("Magus", 18200, 701, 525, 25, enemy_spells, []) enemy3 = Person("Imp ", 1250, 130, 560, 325, enemy_spells, []) players = [player1, player2, player3] enemies = [enemy1, enemy2, enemy3] running = True i = 0 print(Bcolors.FAIL + Bcolors.BOLD + "AN ENEMY ATTACKS!" + Bcolors.ENDC)
from game import Person from magoc import Magic print("This is the instruction.....") #Magic fire = Magic ("Fire", 10,30,"dark") wind = Magic ("Wind", 15, 50, "dark") ice = Magic ("Ice", 20,70, "dark") magic_list = [fire,wind,ice] player = Person("Daniel", 500, 100, 50, magic_list) enemy = Person("Vampire", 1000, 100, 20, magic_list) player.stats() enemy.stats() print("-----------------------------") running = True while running: #Player's turn print(player.name) print("Choose your action: ") player.choose_action() try: choice = int(input(">>>: ")) except ValueError: print("Choose a number") continue action_index = choice - 1
"quantity": 5 }, { "item": elixer, "quantity": 5 }, { "item": hielixer, "quantity": 2 }, { "item": grenade, "quantity": 5 }, { "item": bomb, "quantity": 5 }] player1 = Person("Parth ", 3260, 132, 300, 34, player_spells, player_items) player2 = Person("Stark ", 4160, 188, 311, 34, player_spells, player_items) player3 = Person("Steve ", 3089, 174, 288, 34, player_spells, player_items) enemy1 = Person("Ronan ", 1250, 130, 560, 325, enemy_spells, []) enemy2 = Person("Ultron", 1250, 130, 560, 325, enemy_spells, []) enemy3 = Person("Thanos", 18200, 701, 525, 25, enemy_spells, []) players = [player1, player2, player3] enemies = [enemy1, enemy2, enemy3] running = True i = 0 print(bcolors.FAIL + bcolors.BOLD + " An Enemy Attacks!" + bcolors.ENDC)
# Adding magic spells for the enemy enemy_magic = [fire, thunder, blizzard, cure] # Instantiating the items and their quantity player_items = [{"item": potion, "quantity": 10}, {"item": hipotion, "quantity": 5}, {"item": superpotion, "quantity": 5}, {"item": elixir, "quantity": 5}, {"item": superelixir, "quantity": 2}, {"item": grenade, "quantity": 5}] # Instantiate the items for enemy enemy_items = [{"item": grenade, "quantity": 5}] # Instantiate the players player1 = Person("Shree", 3000, 300, 200, 34, player_magic, player_items) player2 = Person("Rawal", 2500, 200, 150, 34, player_magic, player_items) player3 = Person("Flash", 1200, 150, 100, 34, player_magic, player_items) # Instantiate the Enemies enemy2 = Person("De-voe", 1400, 200, 700, 300, enemy_magic, enemy_items) enemy1 = Person("Savtar", 9000, 500, 550, 30, enemy_magic, enemy_items) enemy3 = Person("Thorne", 1400, 200, 700, 300, enemy_magic, enemy_items) players = [player1, player2, player3] enemies = [enemy1, enemy2, enemy3] running = True i = 0 print(bcolors.FAIL + bcolors.BOLD + "ENEMY ATTACKS" + bcolors.ENDC)
TEST_ITEM_NO_VIS = Item.Item("test invisible", ["keyword"], "Short desc invisible", "Long desc invisible", False, True) # Containers TEST_EMPTY_CONTAINER = Container.Container("test", ["keyword"], "Short desc", "Long desc", True, False, []) TEST_CONTAINER_WITH_ITEM = Container.Container("test", ["keyword"], "Short desc", "Long desc", True, False, [TEST_ITEM_ON_GROUND]) TEST_CONTAINER_WITH_INVISIBLE_ITEM = Container.Container( "test", ["keyword"], "Short desc", "Long desc", True, False, [TEST_ITEM_NO_VIS]) # People TEST_PERSON = Person.Person("Testman", "You see a test man", True) TEST_INVISIBLE_PERSON = Person.Person("Testman", "You shouldn't see this test man", False) TEST_GIDEON = Gideon.Gideon("Gideon", "You see a Gideon", True) TEST_INVISIBLE_GIDEON = Gideon.Gideon("Gideon", "You should not see this Gideon", False) # Rooms TEST_ROOM = Room.Room("Test Room", "This is a test room for testing.", {}, [TEST_ITEM_ON_GROUND], []) TEST_ROOM_2 = Room.Room( "Test Room 2", "This is a test room 2 for testing.", {"s": TEST_ROOM}, [TEST_ITEM_ON_GROUND, TEST_ITEM_NO_GET, TEST_ITEM_NO_VIS], []) TEST_ROOM.exits = {"n": TEST_ROOM_2} TEST_ROOM_WITH_PERSON = Room.Room("Test Room With Person", "This is a test room for testing people.",
potion = Item("Potion", "potion", "Heals 50 HP", 50) hipotion = Item("Hi-Potion", "potion", "Heals 100 HP", 100) superpotion = Item("Super Potion", "potion", "Heals 1000 HP", 1000) elixer = Item("Elixer", "elixer", "Fully restores HP/MP of one party membrer", 9999) hielixer = Item("MegaElixer", "elixer", "Fully restores party's HP/MP", 9999) grenade = Item("Grenade", "attack", "Deals 500 damage", 500) player_spells = [fire, thunder, blizzard, meteor, cure, cura] enemy_spells = [fire, meteor, curaga] player_items = [{"item": potion, "quantity": 15}, {"item": hipotion, "quantity": 5}, {"item": superpotion, "quantity": 5}, {"item": elixer, "quantity": 5}, {"item": hielixer, "quantity": 2}, {"item": grenade, "quantity": 5}] #Instantiate People player1 = Person( "Pramod:", 3260, 132, 300, 34, player_spells, player_items) player2 = Person( "Kris :", 4160, 138, 311, 34, player_spells, player_items) player3 = Person( "Horler:", 3089, 174, 288, 34, player_spells, player_items) enemy1 = Person("Tanishi", 1250, 130, 560, 325, enemy_spells, []) enemy2 = Person("Tanu ", 18200, 701, 525, 25, enemy_spells, []) enemy3 = Person("Priya ", 1250, 130, 560, 325, enemy_spells, []) players = [player1, player2, player3] enemies = [enemy1, enemy2, enemy3] defeated_enemies = 0 defeated_players = 0 running = True i = 0
def test_announcements_list_of_player_returns_expected_consecutive_cards_and_belotes( self): team1 = Team('Malinka', (Person('Ivan'), Person('Gosho'))) team2 = Team('Yagodka', (Person('Pesho'), Person('Tosho'))) team3 = Team('Kapinka', (Person('Panda'), Person('Panda2'))) team1.teammates[0].cards = [ Card('K', 'S'), Card('Q', 'S'), Card('J', 'S'), Card('A', 'S') ] #quarte and belot team1.teammates[0].cards = Utls.sort_cards(team1.teammates[0].cards) team1.teammates[1].cards = [ Card('K', 'S'), Card('Q', 'S'), Card('J', 'S'), Card('A', 'S'), Card('T', 'S') ] team1.teammates[1].cards = Utls.sort_cards(team1.teammates[1].cards) team2.teammates[0].cards = [ Card('K', 'S'), Card('Q', 'S'), Card('J', 'S'), Card('A', 'S'), Card('T', 'S'), Card('9', 'S') ] team2.teammates[0].cards = Utls.sort_cards(team2.teammates[0].cards) team2.teammates[1].cards = [ Card('K', 'S'), Card('Q', 'S'), Card('J', 'S'), Card('A', 'S'), Card('7', 'S'), Card('8', 'S'), Card('9', 'S') ] team2.teammates[1].cards = Utls.sort_cards(team2.teammates[1].cards) team3.teammates[0].cards = [ Card('K', 'S'), Card('Q', 'S'), Card('J', 'S'), Card('A', 'S'), Card('7', 'D'), Card('8', 'D'), Card('9', 'D'), Card('T', 'D') ] team3.teammates[0].cards = Utls.sort_cards(team3.teammates[0].cards) team3.teammates[1].cards = [ Card('K', 'S'), Card('Q', 'S'), Card('J', 'S'), Card('A', 'S'), Card('9', 'S'), Card('9', 'D'), Card('9', 'H'), Card('9', 'C') ] team3.teammates[1].cards = Utls.sort_cards(team3.teammates[1].cards) result = Game.take_player_annoucements(team1.teammates[0]) result2 = Game.take_player_annoucements(team1.teammates[1]) result3 = Game.take_player_annoucements(team2.teammates[0]) result4 = Game.take_player_annoucements(team2.teammates[1]) result5 = Game.take_player_annoucements(team3.teammates[0]) result6 = Game.take_player_annoucements(team3.teammates[1]) self.assertEqual(result, [['Quarte', 'S', '14'], ['Belote', 'S']]) self.assertEqual(result2, [['Quinte', 'S', '14'], ['Belote', 'S']]) self.assertEqual(result3, [['Quinte', 'S', '14'], ['Belote', 'S']]) self.assertEqual( result4, [['Quarte', 'S', '14'], ['Tierce', 'S', '9'], ['Belote', 'S']]) self.assertEqual( result5, [['Quarte', 'D', '10'], ['Quarte', 'S', '14'], ['Belote', 'S']]) self.assertEqual( result6, [['Carre', '9'], ['Quarte', 'S', '14'], ['Belote', 'S']])
author.in_guard = True print(f"{author.name} entrou em guarda!") author.guard_delay = 2 else: if author.in_guard: print(f"{author.name} se distraiu e abaixou a guarda!") author.in_guard = False else: print(f"{author.name} tropeceu e não entrou em guarda!") decisions.add(Decision(name="Atacar", function=atacar)) decisions.add(Decision(name="Passar", function=passar)) decisions.add(Decision(name="Entrar em guarda", function=guard)) persons.add(Person(name="Nium", name_color=color.blue)) persons.add(Person(name="Goblin", name_color=color.green)) @persons.event def on_damage(person, damage_value): print( f"{person.name} recebeu {to_color(str(damage_value), color.red)} de dano!", end="\n\n") @persons.event def on_defense(person, author_of_attack): print( f"{person.name} escorregou e fez {author_of_attack.name} errar o ataque!" )
# Items warrior_items = [{"item": Hammer, "quantity": 2}, {"item": Axe, "quantity": 5}, {"item": SuperPotion, "quantity": 2}] mage_items = [{"item": Dagger, "quantity": 5}, {"item": Potion, "quantity": 5}, {"item": ManaPotion, "quantity": 10}] assassin_items = [{"item": Bow, "quantity": 5}, {"item": Sword, "quantity": 5}, {"item": Potion, "quantity": 5}] running = True game = True BattleNumber = 1 while game: b = 0 mageCount = 0 warriorCount = 0 AssassinCount = 0 ForIn = 0 player = Person("Mage", 300, 200, 10, 34, mage_spells, mage_items) players = [player] enemy = Person("Imp", 200, 200, 30, 21, enemy_spells, []) enemies = [enemy] mage = 'Mage ' warrior = "Warrior " Assassin = "Assassin " # Number of players NumberPlayers = input("How many players: ") ForIn = int(NumberPlayers) # Choosing character for b in range(ForIn): player.choose_character() a = input("Choose your character: ") ind = int(a) - 1
magic = [{ "name": "Fire", "cost": 10, "dmg": 60 }, { "name": "Thunder", "cost": 10, "dmg": 60 }, { "name": "Blizzard", "cost": 10, "dmg": 60 }] player = Person(460, 65, 60, 34, magic) enemy = Person(1200, 65, 45, 25, magic) running = True i = 0 print(bcolors.FAIL + bcolors.BOLD + "AN ENEMY ATTACKS" + bcolors.ENDC) while running: print("======================") player.choose_action() choice = input("Choose action:") index = int(choice) - 1 if index == 0: dmg = player.generate_damage() enemy.take_damage(dmg) print("you attacked for", dmg, "points of damage. enemy HP:",
"name": superpotion, "quantity": 5 }, { "name": elixer, "quantity": 5 }, { "name": hielixer, "quantity": 3 }, { "name": grenade, "quantity": 2 }] # Instantiate People # (self, name, hp, mp, atk, df, magic, items): player1 = Person("Valos: ", 5600, 165, 235, 34, player_spells, player_items) player2 = Person("Nick: ", 6500, 165, 307, 34, player_spells, player_items) player3 = Person("Robot: ", 4400, 165, 468, 34, player_spells, player_items) enemy1 = Person("Mega: ", 10800, 165, 540, 25, enemy_spells, enemy_items) enemy2 = Person("Hela: ", 4600, 165, 326, 25, enemy_spells, enemy_items) enemy3 = Person("Inox: ", 3800, 165, 432, 25, enemy_spells, enemy_items) players = [player1, player2, player3] enemies = [enemy1, enemy2, enemy3] # just for stats running = True i = 0 """ if enemy1.hp == 0 and enemy1.hp == 0 and enemy3.hp == 0: print("Player Won") running = False # for player in players:
}, { "item": superpotion, "quantity": 5 }, { "item": elixer, "quantity": 5 }, { "item": hielixer, "quantity": 2 }, { "item": grenade, "quantity": 5 }] # Instantiate People player1 = Person(bcolors.OKBLUE + "Valos:" + bcolors.ENDC, 3260, 132, 300, 34, player_spells, player_items) player2 = Person(bcolors.OKBLUE + "Nick :" + bcolors.ENDC, 4160, 188, 311, 34, player_spells, player_items) player3 = Person(bcolors.OKBLUE + "Robot:" + bcolors.ENDC, 3089, 174, 288, 34, player_spells, player_items) enemy1 = Person(bcolors.FAIL + "Imp " + bcolors.ENDC, 1250, 130, 560, 325, enemy_spells, []) enemy2 = Person(bcolors.FAIL + "Magus" + bcolors.ENDC, 18200, 701, 525, 25, enemy_spells, []) enemy3 = Person(bcolors.FAIL + "Imp " + bcolors.ENDC, 1250, 130, 560, 325, enemy_spells, []) players = [player1, player2, player3] enemies = [enemy1, enemy2, enemy3]