Пример #1
0
def load_save(save_name=""):
    save_file = shelve.open("saves/save")
    save_load = save_file[save_name]

    player_chars = []
    player_name = save_load[0][0]

    for char_li in save_load[:-1]:
        temp_char = Character([0, 0])

        temp_char.name = char_li[0]
        temp_char.health = char_li[1]
        temp_char.max_health = char_li[2]
        temp_char.attack = char_li[3]
        temp_char.ammo = char_li[4]
        temp_char.max_ammo = char_li[5]
        temp_char.mana = char_li[6]
        temp_char.max_mana = char_li[7]
        temp_char.attacks = char_li[8]
        temp_char.equipped_items = char_li[9]
        player_chars.append(temp_char)
    rounds = save_load[-1]

    player_party = Party(player_chars)

    save_file.close()
    return [player_name, player_party, rounds]
Пример #2
0
# rpg, broń postaci
from weapons import Wand, Sword
from characters import Character
from time import perf_counter as getTime

player = Character("Rektor", 1000)
victim = Character("student", 100)

# nasze "strategie", bronie
sword = Sword(5)
wand = Wand(10, 1000)

# atak bez broni
print("# pięści")
player.attack(victim)
print()

# wyposażenie w broń
player.setWeapon(sword)
print("# miecz")
player.attack(victim)
player.attack(victim)
print()

# wyposażenie w inną broń
player.setWeapon(wand)
print("# różdżka")
player.attack(victim)
player.attack(victim)  # <- to nie wyjdzie, bo cooldown 1s

curr_time = getTime()
Пример #3
0
class Game:
    def __init__(self):
        self.player = Character()
        self.monsters = [Goblin(), Troll(), Dragon()]
        self.monster = self.get_next_monster()

        # game loop
        while self.player.hit_points and (self.monster or self.monsters):
            print('\n' + '=' * 20)
            print(self.player)
            self.monster_turn()
            print('-' * 20)
            self.player_turn()
            self.cleanup()
            print('\n' + '=' * 20)

        if self.player.hit_points:
            print("You win!")
        elif self.monster or self.monsters:
            print("You lose!")

        sys.exit()

    def get_next_monster(self):
        try:
            return self.monsters.pop(0)
        except IndexError:
            return None

    def monster_turn(self):
        if self.monster.attack():
            print("{} is attacking!".format(self.monster))
            if self.player.dodge():
                print("You dodged the attack!")
            else:
                print("You got hit anyway!")
                self.player.hit_points -= 1
        else:
            print("{} isn't attacking this turn".format(self.monster))

    def player_turn(self):
        action = input("Action ([A]ttack, [R]est, [Q]uit): ").lower()

        if action == 'a':
            print("You're attacking {}!".format(self.monster))
            if self.player.attack():
                if self.monster.dodge():
                    print("{} dodged your attack!".format(self.monster))
                else:
                    if self.player.leveled_up():
                        self.monster.hit_points -= 2
                    else:
                        self.monster.hit_points -= 1
                    print("You hit {} with your {}!".format(self.monster, self.player.weapon))
            else:
                print("You missed!")
        elif action == 'r':
            self.player.rest()
        elif action == 'q':
            print("Quited")
            sys.exit()
        else:
            self.player_turn()

    def cleanup(self):
        if self.monster.hit_points <= 0:
            self.player.experience += self.monster.experience
            print("You killed {}!".format(self.monster))
            self.monster = self.get_next_monster()