Beispiel #1
0
    def test_start_position(self):

        choice1 = "1"
        choice2 = "2"
        choice3 = "3"
        choice4 = "4"
        grid_size = 4

        expected_result1 = (0, 0)
        expected_result2 = (0, grid_size - 1)
        expected_result3 = (grid_size - 1, 0)
        expected_result4 = (grid_size - 1, grid_size - 1)

        room = classes.Rooms()
        room_list = [room]

        hero = classes.Hero("Orvar", "Riddare")

        actual_result1 = main.start_position(choice1, grid_size, room_list,
                                             hero)
        actual_result2 = main.start_position(choice2, grid_size, room_list,
                                             hero)
        actual_result3 = main.start_position(choice3, grid_size, room_list,
                                             hero)
        actual_result4 = main.start_position(choice4, grid_size, room_list,
                                             hero)

        self.assertEqual(expected_result1, actual_result1)
        self.assertEqual(expected_result2, actual_result2)
        self.assertEqual(expected_result3, actual_result3)
        self.assertEqual(expected_result4, actual_result4)
Beispiel #2
0
    def test_update_player_coordinates(self):

        test_character = classes.Hero('Orvar', 'Knight')

        old_coordinates = (0, 0)
        new_coordinates = (0, 3)

        self.assertEqual(old_coordinates, test_character.coordinates)
        test_character.update_coordinates(new_coordinates)
        self.assertEqual(new_coordinates, test_character.coordinates)
Beispiel #3
0
    def test_wizard_initiation(self):
        test_character = classes.Hero('Orvar', 'Wizard')
        expected_result = 0
        self.assertEqual(expected_result, test_character.initiative)

        test_character.add_wizard()
        expected_result_1 = 6
        expected_result_2 = 4
        expected_result_3 = 9
        expected_result_4 = 5
        self.assertEqual(expected_result_1, test_character.initiative)
        self.assertEqual(expected_result_2, test_character.resistance)
        self.assertEqual(expected_result_3, test_character.attack)
        self.assertEqual(expected_result_4, test_character.agility)
Beispiel #4
0
    def test_thief_initiation(self):
        test_character = classes.Hero('Orvar', 'Thief')
        expected_result = 0
        self.assertEqual(expected_result, test_character.initiative)

        test_character.add_thief()
        expected_result_1 = 7
        expected_result_2 = 5
        expected_result_3 = 5
        expected_result_4 = 7
        self.assertEqual(expected_result_1, test_character.initiative)
        self.assertEqual(expected_result_2, test_character.resistance)
        self.assertEqual(expected_result_3, test_character.attack)
        self.assertEqual(expected_result_4, test_character.agility)
Beispiel #5
0
    def test_knight_initiation(self):

        test_character = classes.Hero('Orvar', 'Knight')
        expected_result = 0
        self.assertEqual(expected_result, test_character.initiative)

        test_character.add_knight()
        expected_result_1 = 5
        expected_result_2 = 9
        expected_result_3 = 6
        expected_result_4 = 4
        self.assertEqual(expected_result_1, test_character.initiative)
        self.assertEqual(expected_result_2, test_character.resistance)
        self.assertEqual(expected_result_3, test_character.attack)
        self.assertEqual(expected_result_4, test_character.agility)
Beispiel #6
0
def choose_character(character_name):

    while True:
        clear_screen()
        new_game_text(character_name)
        print("\n[1] - Riddaren\n" "[2] - Trollkarlen\n" "[3] - Tjuven")

        character_choice = input("\nVälj karaktär: ")
        if character_choice == "1":
            hero = classes.Hero(character_name, "Riddare")
            hero.add_knight()

            return hero
        elif character_choice == "2":
            hero = classes.Hero(character_name, "Trollkarl")
            hero.add_wizard()
            return hero
        elif character_choice == "3":
            hero = classes.Hero(character_name, "Tjuv")
            hero.add_thief()
            return hero
        else:
            print("\n-- Felaktig input, ange en siffra från menyn. --")
            input('-- Tyck på enter för att fortsätta --')
Beispiel #7
0
count_tutorial = 0
count_menu = 0
count_rastart_mode = ''
count_rastart = 0

# данные, нужные для более универсального
# представления персонажей на разных мониторах
width_mob = x_mobs = width // 45
y_mobs = height // 2
height_mob = height // 5

speed_mob = 700

# объекты движующиеся
enemy = classes.Enemy(x_mobs, y_mobs, width_mob, height_mob, speed_mob)
hero = classes.Hero(width - x_mobs * 2, y_mobs, width_mob, height_mob, speed_mob)
hero_2 = classes.Hero(x_mobs, y_mobs, width_mob, height_mob, speed_mob)
ball = classes.Ball((400, 560), screen, 35, hero, enemy, hero_2)

enemy.add_ball(ball)

# объекты дисплейные
background = classes.DrawBackground()
sprite_tutorial = classes.tutorial_sprite()
sprite_menu = classes.menu_sprite()
restart_sprite = classes.restart_sprite()

# подравнивание меню под экран
classes.transforms(sprite_tutorial, width, height)
classes.transforms(sprite_menu, width, height)
for i in restart_sprite:
Beispiel #8
0
def go(match):

    game = classes.Game()
    game.properties = {
        "seed": match[2],
        "block": match[0],
        "recipient": match[3],
        "amount": match[4],
        "league": match[11]
    }

    game.start_block = game.properties["block"]
    game.recipient = game.properties["recipient"]
    game.bet = game.properties["amount"]
    game.current_block = game.start_block
    game.seed = game.properties["seed"]
    game.hash = blake2b(
        (game.properties["seed"] + str(game.properties["block"])).encode(),
        digest_size=10).hexdigest()

    if game.recipient == coordinator and game.bet >= league_requirement:
        game.league = game.properties["league"]
    else:
        game.league = "casual"

    game.filename_temp = "static/replays/unfinished/" + str(game.hash +
                                                            ".json")
    game.filename = "static/replays/" + str(game.hash + ".json")

    def db_output():

        if not game.finished:
            scores_db.c.execute("DELETE FROM unfinished WHERE hash = ?",
                                (game.hash, ))  # remove temp entry if exists
            scores_db.c.execute(
                "INSERT INTO unfinished VALUES (?,?,?,?,?,?,?)", (
                    game.properties["block"],
                    game.hash,
                    game.seed,
                    hero.experience,
                    json.dumps(hero.inventory),
                    game.league,
                    game.bet,
                ))
            scores_db.conn.commit()

        elif game.finished and not game.replay_exists:
            scores_db.c.execute("DELETE FROM unfinished WHERE hash = ?",
                                (game.hash, ))  # remove temp entry if exists
            scores_db.c.execute("INSERT INTO scores VALUES (?,?,?,?,?,?,?)", (
                game.properties["block"],
                game.hash,
                game.seed,
                hero.experience,
                json.dumps(hero.inventory),
                game.league,
                game.bet,
            ))
            scores_db.conn.commit()

    def output(entry):
        game.step += 1
        print(entry)
        game.story[game.step] = entry

    def replay_save():

        if not os.path.exists("static"):
            os.mkdir("static")
        if not os.path.exists("static/replays"):
            os.mkdir("static/replays")
        if not os.path.exists("static/replays/unfinished"):
            os.mkdir("static/replays/unfinished")

        if game.finished and not game.replay_exists:
            if os.path.exists(game.filename_temp):
                os.remove(game.filename_temp)
            with open(game.filename, "w") as file:
                file.write(json.dumps(game.story))

        elif not game.finished:
            with open(game.filename_temp, "w") as file:
                file.write(json.dumps(game.story))

    if os.path.exists(game.filename):
        game.finished = True
        game.quit = True
        game.replay_exists = True
        output(f"Replay for {game.hash} already present, skipping match")

    hero = classes.Hero()

    #trigger is followed by events affected by modifiers

    #define events

    EVENTS = {
        game.properties["seed"][2:4]: "attack",
        game.properties["seed"][4:6]: "attacked",
        game.properties["seed"][6:8]: "attack_critical"
    }

    #define triggers
    triggers_combat = {
        "4f": "troll",
        "df": "goblin",
        "5a": "berserker",
        "61a": "dragon"
    }

    triggers_peaceful = {"3d": "health_potion", "69a": "armor", "70b": "sword"}

    triggers_human_individual = {"item:chaos_ring": "chaos_ring"}
    triggers_human_global = {"event:rangarok": "ragnarok"}

    def enemy_dead_check():
        if enemy.health < 1:
            hero.in_combat = False
            enemy.alive = False
            output(f"{enemy.name} died")
            output(f"You now have {hero.experience} experience")

    def hero_dead_check():
        if hero.health < 1:
            hero.alive = False
            game.finished = True
            output(f"You died with {hero.experience} experience")

    def enemy_define(event):
        if event == "troll":
            enemy = classes.Troll()
        elif event == "goblin":
            enemy = classes.Goblin()
        elif event == "berserker":
            enemy = classes.Berserker()
        elif event == "dragon":
            enemy = classes.Dragon()
        elif event == "fenrir":  #only triggers on ragnarok
            enemy = classes.Fenrir()
        elif event == "dwarf":  #only triggers on ragnarok
            enemy = classes.Dwarf()
        else:
            enemy = None

        return enemy

    def chaos_ring():
        if not hero.inventory["ring"]:
            output(
                f'You see a chaos ring, the engraving says {subcycle["cycle_hash"][0:5]}'
            )
            if subcycle["cycle_hash"][0] in [
                    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
            ]:
                hero.inventory["ring"] = "ring_perseverance"
                hero.full_hp = 650
                if hero.health < hero.full_hp:
                    hero.health = hero.full_hp

                output(
                    f"You slide the ring on your finger and immediately feel stronger"
                )
            else:
                hero.inventory["ring"] = "ring_blight"
                hero.full_hp = 350
                if hero.health > hero.full_hp:
                    hero.health = hero.full_hp
                output(
                    f"You slide the ring on your finger and your hands start to tremble"
                )

    def ragnarok():
        output(f"Ragnarök begins")
        # add new monsters to the world
        triggers_combat["53b"] = "fenrir"
        triggers_combat["4c"] = "dwarf"

    def sword_get():
        if not hero.inventory["weapon"]:
            hero.inventory["weapon"] = "sword"
            output(f"You obtained a sword")

    def armor_get():
        if not hero.inventory["armor"]:
            hero.inventory["armor"] = "armor"
            output(f"You obtained armor")

    def attack():
        hero.experience += 1
        damage = hero.power
        if hero.inventory["weapon"] == "sword":
            damage += 10

        enemy.health -= hero.power
        output(
            f"{enemy.name} suffers {damage} damage and is left with {enemy.health} HP"
        )
        enemy_dead_check()

    def attack_critical():
        hero.experience += 1
        damage = hero.power + hero.experience
        enemy.health -= damage
        output(
            f"{enemy.name} suffers {damage} *critical* damage and is left with {enemy.health} HP"
        )
        enemy_dead_check()

    def cycle():
        db.c.execute(
            "SELECT * FROM transactions WHERE block_height = ? ORDER BY block_height",
            (game.current_block, ))
        result = db.c.fetchall()

        position = 0
        game.cycle = {}  #remove previous cycle if exists
        for tx in result:
            position = position + 1

            block_height = tx[0]
            timestamp = tx[1]
            address = tx[2]
            recipient = tx[3]
            amount = tx[4]
            block_hash = tx[7]
            operation = tx[10]
            data = tx[11]

            cycle_hash = blake2b((str(tx)).encode(),
                                 digest_size=60).hexdigest()

            game.cycle[position] = {
                "block_height": block_height,
                "timestamp": timestamp,
                "address": address,
                "recipient": recipient,
                ":amount": amount,
                "block_hash": block_hash,
                "operation": operation,
                "data": data,
                "cycle_hash": cycle_hash
            }

    def heal():
        if hero.in_combat:
            hero.health = hero.health + 5
            output(f"You drink a potion and heal to {hero.health} HP...")
            if hero.health > hero.full_hp:
                hero.health = hero.full_hp

        elif not hero.in_combat:
            hero.health = hero.health + 15
            if hero.health > hero.full_hp:
                hero.health = hero.full_hp
            output(f"You rest and heal well to {hero.health} HP...")

    def attacked():
        damage_taken = enemy.power

        if hero.inventory["armor"] == "armor":
            damage_taken -= 5

        hero.health = hero.health - damage_taken

        output(
            f"{enemy.name} hits you for {enemy.power} HP, you now have {hero.health} HP"
        )
        hero_dead_check()

    while hero.alive and not game.quit:

        cycle()
        if not game.cycle:
            output("The game is still running")
            game.quit = True
            break

        for subposition, subcycle in game.cycle.items():  #for tx in block
            print(subcycle)

            # human interaction
            for trigger_key in triggers_human_individual:
                trigger = triggers_human_individual[trigger_key]
                if trigger_key == subcycle["data"] and subcycle[
                        "address"] == game.seed and subcycle[
                            "operation"] == "autogame:add":
                    if trigger == "chaos_ring":
                        chaos_ring()

            for trigger_key in triggers_human_global:
                trigger = triggers_human_global[trigger_key]
                if trigger_key == subcycle["data"] and subcycle[
                        "operation"] == "autogame:add":
                    if trigger == "ragnarok":
                        ragnarok()
            # human interaction

            for trigger_key in triggers_peaceful:
                if not hero.in_combat:
                    trigger = triggers_peaceful[trigger_key]

                    if trigger_key in subcycle["cycle_hash"]:
                        if trigger == "health_potion" and hero.health < hero.full_hp:
                            heal()
                        elif trigger == "armor":
                            armor_get()
                        elif trigger == "sword":
                            sword_get()

            for trigger_key in triggers_combat:
                if trigger_key in subcycle[
                        "cycle_hash"] and hero.alive and not hero.in_combat:
                    trigger = triggers_combat[trigger_key]

                    enemy = enemy_define(trigger)
                    output(
                        f"You meet {enemy.name} on transaction {subposition} of block {game.current_block}"
                    )
                    hero.in_combat = True

            for event_key in EVENTS:  #check what happened
                if hero.in_combat and hero.alive and not game.quit:

                    if event_key in subcycle["cycle_hash"] and enemy.alive:
                        event = EVENTS[event_key]
                        output(f"Event: {event}")

                        if event == "attack":
                            attack()

                        elif event == "attack_critical":
                            attack_critical()

                        elif event == "attacked":
                            attacked()

        game.current_block = game.current_block + 1

    replay_save()
    db_output()

    return game, hero
Beispiel #9
0
def draw_sprites():
    screen.fill(CONSTS.GREY)
    cl.heros.draw(screen)
    cl.plats.draw(screen)
    cl.borders.draw(screen)
    pg.display.flip()


running = True

pg.init()

width, height = size = [1080, 720]
screen = pg.display.set_mode(size)

hero = cl.Hero([0, 0], cl.heros)
platform = cl.Platform([0, 640], CONSTS.plat, cl.plats)

ADDEVENT = 10

pg.time.set_timer(ADDEVENT, 40)

pg.mouse.set_visible(True)

screen.fill(CONSTS.WHITE)

pg.display.flip()

clock = pg.time.Clock()

speed = 10
Beispiel #10
0
def go(match, iterator, coordinator, league_requirement=0):
    game = classes.Game()

    def game_saved():
        try:
            scores_db.c.execute(
                "SELECT * FROM scores WHERE hash = ? AND saved = ? ", (
                    game.hash,
                    1,
                ))
            result = scores_db.c.fetchone()[0]
            return True
        except:
            return False

    def game_finished():
        try:
            scores_db.c.execute(
                "SELECT * FROM scores WHERE hash = ? AND finished = ? ", (
                    game.hash,
                    1,
                ))
            result = scores_db.c.fetchone()[0]
            return True
        except:
            return False

    def db_output():

        try:
            output_weapon = hero.weapon.name
        except:
            output_weapon = None
        try:
            output_armor = hero.armor.name
        except:
            output_armor = None
        try:
            output_ring = hero.ring.name
        except:
            output_ring = None

        if not game_finished():
            scores_db.c.execute("DELETE FROM scores WHERE hash = ?",
                                (game.hash, ))
            scores_db.c.execute(
                "INSERT INTO scores VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
                (game.properties["block"], game.hash, game.seed,
                 hero.experience,
                 json.dumps({
                     "weapon": output_weapon,
                     "armor": output_armor,
                     "ring": output_ring
                 }), game.league, game.bet, json.dumps(
                     hero.damage_table), json.dumps(hero.defense_table),
                 game.current_block, game.finished, game.saved))
            scores_db.conn.commit()

    def output(entry):
        game.step += 1
        print(entry)
        game.story[game.step] = entry

    def replay_save():
        if not os.path.exists("static"):
            os.mkdir("static")
        if not os.path.exists("static/replays"):
            os.mkdir("static/replays")

        if not game_saved() or not game_finished():
            with open(game.filename, "w") as file:
                file.write(json.dumps(game.story))
                scores_db.c.execute(
                    "UPDATE scores SET saved = 1 WHERE hash = ?",
                    (game.hash, ))
                scores_db.conn.commit()
                game.saved = True

        if not hero.alive:
            game.finished = True
            scores_db.c.execute(
                "UPDATE scores SET finished = 1 WHERE hash = ?", (game.hash, ))
            scores_db.conn.commit()

    try:
        assert ":" in match[11]
        recipient = match[11].split(":")[1]
        league = match[11].split(":")[0]
    except:
        recipient = match[2]
        league = match[11]

    try:
        assert essentials.address_validate(recipient)
    except:
        recipient = match[2]

    game.properties = {
        "seed": recipient,
        "block": match[0],
        "recipient": match[3],
        "amount": match[4],
        "league": league
    }

    game.start_block = game.properties["block"]
    game.recipient = game.properties["recipient"]
    game.bet = game.properties["amount"]
    game.current_block = game.start_block
    game.seed = game.properties["seed"]
    game.hash = blake2b(
        (game.properties["seed"] + str(game.properties["block"])).encode(),
        digest_size=10).hexdigest()
    game.enemies = game.enemies

    if game.recipient == coordinator and game.bet >= league_requirement:
        game.league = game.properties["league"]
    else:
        game.league = "casual"

    game.filename = "static/replays/" + str(game.hash + ".json")

    hero = classes.Hero()

    if game_finished():
        game.quit = True
        print(f"Game {game.hash} tagged as finished, skipping")

    #trigger is followed by events affected by modifiers

    #define events

    EVENTS = {
        game.properties["seed"][2:4]: "attack",
        game.properties["seed"][4:6]: "attacked",
        game.properties["seed"][6:8]: "attack_critical"
    }

    #define triggers

    def enemy_dead_check():
        if enemy.health < 1:
            hero.in_combat = False
            enemy.alive = False
            output(f"{enemy.name} died")
            output(f"You now have {hero.experience} experience")

    def hero_dead_check():
        if hero.health < 1:
            hero.alive = False
            output(f"You died with {hero.experience} experience")

    def chaos_ring():
        if not hero.ring:
            output(
                f'You see a chaos ring, the engraving says {subcycle["cycle_hash"][0:5]}'
            )
            if subcycle["cycle_hash"][0] in ["0", "1", "2", "3", "4"]:
                hero.ring = classes.ChaosRing().roll_good()
            else:
                hero.ring = classes.ChaosRing().roll_bad()

            hero.full_hp += hero.ring.health_modifier

            if hero.health > hero.full_hp:
                hero.health = hero.full_hp

            output(hero.ring.string)

    def ragnarok():
        output(f"Ragnarök begins")
        # add new monsters to the world
        for enemy in classes.Game().enemies_ragnarok:
            game.enemies.append(enemy)

    def attack():
        hero.experience += 1
        damage = hero.damage
        enemy.health -= hero.damage
        output(
            f"{enemy.name} suffers {damage} damage and is left with {enemy.health} HP"
        )
        enemy_dead_check()

    def attack_critical():
        hero.experience += 1
        damage = hero.damage + hero.experience
        enemy.health -= damage
        output(
            f"{enemy.name} suffers {damage} *critical* damage and is left with {enemy.health} HP"
        )
        enemy_dead_check()

    def cycle():
        db.c.execute(
            "SELECT * FROM transactions WHERE block_height = ? ORDER BY block_height",
            (game.current_block, ))
        result = db.c.fetchall()

        position = 0
        game.cycle = {}  #remove previous cycle if exists
        for tx in result:
            position = position + 1

            block_height = tx[0]
            timestamp = tx[1]
            address = tx[2]
            recipient = tx[3]
            amount = tx[4]
            block_hash = tx[7]
            operation = tx[10]
            data = tx[11]

            cycle_hash = blake2b((str(tx)).encode(),
                                 digest_size=60).hexdigest()

            game.cycle[position] = {
                "block_height": block_height,
                "timestamp": timestamp,
                "address": address,
                "recipient": recipient,
                ":amount": amount,
                "block_hash": block_hash,
                "operation": operation,
                "data": data,
                "cycle_hash": cycle_hash
            }

    def attacked():
        damage_taken = enemy.damage

        if hero.armor:
            damage_taken -= hero.defense

        hero.health = hero.health - damage_taken

        output(
            f"{enemy.name} hits you for {enemy.damage} HP, you now have {hero.health} HP"
        )
        hero_dead_check()

    while hero.alive and not game.quit:

        cycle()
        if not game.cycle:
            output("The game is still running")
            game.quit = True
            break

        for subposition, subcycle in game.cycle.items():  #for tx in block
            #print (subcycle)

            # human interaction
            for item_interactive_class in classes.items_interactive:
                if item_interactive_class(
                ).trigger == subcycle["data"] and subcycle[
                        "address"] == game.seed and subcycle[
                            "operation"] == game.interaction_string:
                    if item_interactive_class == classes.ChaosRing:
                        chaos_ring()

            for events_interactive_global_class in classes.events_interactive_global:
                if events_interactive_global_class(
                ).trigger == subcycle["data"] and subcycle[
                        "operation"] == game.interaction_string:
                    if events_interactive_global_class == classes.Ragnarok:
                        ragnarok()
            # human interaction

            if iterator == 2:
                for pvp_class in game.pvp:
                    if pvp_class().trigger == subcycle["data"] and subcycle[
                            "operation"] == game.interaction_string and subcycle[
                                "recipient"] == game.seed and hero.pvp_interactions > 0:
                        attacker = subcycle["address"]
                        try:
                            scores_db.c.execute(
                                "SELECT damage FROM scores WHERE seed = ? AND block_start <= ? AND block_end >= ? ORDER BY block_start DESC LIMIT 1",
                                (
                                    attacker,
                                    game.current_block,
                                    game.current_block,
                                ))

                            enemy_damage_table = json.loads(
                                scores_db.c.fetchone()[0])

                            for enemy_damage_block, enemy_damage_value in enemy_damage_table.items(
                            ):
                                if int(enemy_damage_block
                                       ) <= game.current_block:
                                    enemy_damage = int(enemy_damage_value)

                            hero.health = hero.health - (enemy_damage -
                                                         hero.defense)
                            hero.pvp_interactions -= 1
                            hero_dead_check()

                            output(
                                f"Player {attacker} hits you and you lose {enemy_damage - hero.defense} health down to {hero.health}"
                            )

                        except Exception:
                            output(
                                f"Player {attacker} tried to attack you, but they failed"
                            )

            for potion_class in game.potions:
                if potion_class(
                ).trigger in subcycle["cycle_hash"] and not hero.in_combat:

                    if potion_class == classes.HealthPotion and hero.health < hero.full_hp:

                        if hero.in_combat:
                            hero.health = hero.health + classes.HealthPotion(
                            ).heal_in_combat
                            output(
                                f"You drink a potion and heal to {hero.health} HP..."
                            )

                        elif not hero.in_combat:
                            hero.health = hero.health + classes.HealthPotion(
                            ).heal_not_in_combat
                            output(
                                f"You rest and heal well to {hero.health} HP..."
                            )

                        if hero.health > hero.full_hp:
                            hero.health = hero.full_hp

            for armor_class in game.armors:
                if armor_class(
                ).trigger in subcycle["cycle_hash"] and not hero.in_combat:
                    if not hero.armor:
                        hero.armor = armor_class()
                        hero.defense += hero.armor.defense
                        hero.defense_table[game.current_block] = hero.defense

                        output(f"You obtained {armor_class().name}")

            for weapon_class in game.weapons:
                if weapon_class(
                ).trigger in subcycle["cycle_hash"] and not hero.in_combat:
                    if not hero.weapon:
                        hero.weapon = weapon_class()
                        hero.damage += hero.weapon.damage
                        hero.damage_table[game.current_block] = hero.damage

                        output(f"You obtained {weapon_class().name}")

            for enemy_class in game.enemies:
                if enemy_class().trigger in subcycle[
                        "cycle_hash"] and hero.alive and not hero.in_combat:
                    enemy = enemy_class()

                    output(
                        f"You meet {enemy.name} on transaction {subposition} of block {game.current_block}"
                    )
                    hero.in_combat = True

            for event_key in EVENTS:  #check what happened
                if hero.in_combat and hero.alive and not game.quit:

                    if event_key in subcycle["cycle_hash"] and enemy.alive:
                        event = EVENTS[event_key]
                        output(f"Event: {event}")

                        if event == "attack":
                            attack()

                        elif event == "attack_critical":
                            attack_critical()

                        elif event == "attacked":
                            attacked()

        game.current_block = game.current_block + 1

    if iterator == 2:  # db iteration finished, now save the story (player interactions serial, based on db)
        replay_save()

    db_output()

    return game, hero
Beispiel #11
0
show_ether = True

# Initialize items count
count_item = 3

# Repeat move while arrow key is pressed
pygame.key.set_repeat(200, 200)

# Generate labyrinth by the file
show_game = cl.GameBoard('labyrinth')
show_game.generate_board()
show_game.display_board(game_window)
pygame.display.flip()

# Generate MacGyver and items
MAC = cl.Hero(cst.MACGYVER_PIC, show_game)  # Create MacGyver
NEEDLE = cl.Items(cst.NEEDLE_PIC, show_game)  # Create Item
NEEDLE.display_random(cst.NEEDLE_PIC, game_window)  # Init random position
PIPE = cl.Items(cst.PIPE_PIC, show_game)
PIPE.display_random(cst.PIPE_PIC, game_window)
ETHER = cl.Items(cst.ETHER_PIC, show_game)
ETHER.display_random(cst.ETHER_PIC, game_window)
SYRINGUE = cl.Items(cst.SYRINGUE_PIC, show_game)

run_window_loop = True
while run_window_loop:

    # 30 FPS limit
    pygame.time.Clock().tick(30)

    window_background = pygame.image.load(cst.BKG_PIC).convert_alpha()
Beispiel #12
0
#sprite_hero = classes.Sprites_hero()
"_____________________________________________"
width_window = 1000
height_window = 500
background = classes.Background(width_window, height_window, 0, 0)  #все фоны
"_____________________________________________"
bullets = []
enemys = []
"_____________________________________________"
width_h = 50
height_h = 50
speed = 10
is_jump = False
xy = [1, height_window - int(height_h + 110)]  #320
hero = classes.Hero(xy, width_h, height_h, speed)
"_____________________________________________"

def enemy_add(width_en):
    width_enemy = 60
    height_enemy = 70
    xy = [random.randint(1, width_en), 410 - height_enemy]
    speed = 5
    enemys.append(classes.Enemy(xy, width_enemy, height_enemy, speed))

"_____________________________________________"

def attack_ball():  # выстрел
    speed_ball = 20
    x_ball = hero.xy[0] + hero.width//2
    y_ball = hero.xy[1] + hero.height//2