Пример #1
0
 def __init__(self, monster_id, health_capacity):
     self._monster_id = monster_id
     self._health_capacity = health_capacity
     self._health = health_capacity
     self._pos = Pos()
     self._drop_item_list = list()
     self._hint_list = list()
class Obstacle(object):
    def __init__(self, posx, posy, index, game):
        self.__pos = Pos(posx, posy)
        self.__index = index
        self.__game = game

    def getPos(self):
        return self.__pos

    def teleport(self):
        randx = random.randint(0, self.__game.D - 1)
        randy = self.__game.D - randx - 1
        while (self.__game.positionOccupied(randx, randy)):
            randx = random.randint(0, self.__game.D - 1)
            randy = self.__game.D - randx - 1
        self.__pos.setPos(randx, randy)
Пример #3
0
class Task4Merchant():
    def __init__(self):
        self._elixir_price = 1
        self._shield_price = 2
        self._pos = Pos()

    def set_pos(self, row, column):
        self._pos.set_pos(row, column)

    def get_pos(self):
        return self._pos

    def action_on_soldier(self, soldier):
        self._choice = input(
            "Do you want to buy something? (1. Elixir, 2. Shield) Input: ")
        if self._choice == '1':
            if soldier.get_coins() >= self._elixir_price:
                soldier.add_elixir()
                soldier.remove_coins(self._elixir_price)
                self.talk(
                    "I'll take 1 coin from you, and here is your elixir. Thank You!\n"
                )
            else:
                self.talk(
                    "How pathetic! This poor player wants to buy elixir without paying the right amount. Get out of here!\n"
                )
        elif self._choice == '2':
            if soldier.get_coins() >= self._shield_price:
                soldier.add_shield()
                soldier.remove_coins(self._shield_price)
                self.talk(
                    "I'll take 2 coin from you, and here is your shield. Thank You!\n"
                )
            else:
                self.talk(
                    "How pathetic! This poor player wants to buy shield without paying the right amount. Get out of here!\n"
                )
        else:
            print("=> Illegal choice!\n")

    def talk(self, text):
        print("Merchant$:{}".format(text), end="")
        print()

    def display_symbol(self):
        print('@', end="")
Пример #4
0
 def __init__(self, healthCap, mob, posx, posy, index, game):
     self.MOBILITY = mob
     self.health = healthCap
     self.pos = Pos.Pos(posx, posy)
     self.index = index
     self.game = game
     self.myString = ""
     self.equipment = Weapon.Weapon(1, 1, 1)
Пример #5
0
 def __init__(self, tamanho):
     self.tamanho = tamanho
     # self.tabuleiro = np.arange(1,tamanho**2+1).reshape(tamanho, tamanho)
     self.tabuleiro = []
     count = 1
     for i in range(self.tamanho):
         self.tabuleiro.append([])
         for j in range(self.tamanho):
             self.tabuleiro[i].append(count % (self.tamanho**2))
             count += 1
     # self.tabuleiro[tamanho-1][tamanho-1] = 0
     self.vazio = Pos.ponto(tamanho - 1, tamanho - 1)
     self.movimentosPossiveis = ['C', 'B', 'D', 'E']
Пример #6
0
    def leTabuleiro(self, pecas):
        """Lê o tabuleiro a partir de uma string com
        os números separados por espaço"""

        pecas = pecas.split(" ")

        count = 0
        for i in range(self.tamanho):
            for j in range(self.tamanho):
                if int(pecas[count]) == 0:
                    self.vazio = Pos.ponto(int(i), int(j))
                self.tabuleiro[i][j] = int(pecas[count])
                count += 1
Пример #7
0
class Soldier():
    def __init__(self):
        self._health = 100
        self._num_elixirs = 2
        self._pos = Pos()
        self._keys = list()

    def get_health(self):
        return self._health

    def lose_health(self):
        self._health -= 10
        return self._health <= 0

    def recover(self, healing_power):
        total_health = healing_power + self._health
        self._health = 100 if total_health >= 100 else total_health

    def get_pos(self):
        return self._pos

    def set_pos(self, row, column):
        self._pos.set_pos(row, column)

    def move(self, row, column):
        self._pos.set_pos(row, column)

    def get_keys(self):
        self._keys.sort()
        return set(self._keys)

    def add_key(self, key):
        if key not in self._keys:
            self._keys.append(key)

    def get_num_elixirs(self):
        return self._num_elixirs

    def add_elixirs(self):
        self._num_elixirs += 1

    def use_elixirs(self):
        x = random.randint(0, 5)
        self.recover(x + 15)
        self._num_elixirs -= 1

    def display_information(self):
        print("Health: {}.".format(self._health))
        print("Position (row, column): ({}, {}).".format(
            self._pos.get_row(), self._pos.get_column()))
        print("Keys: {}.".format(self._keys))
        print("Elixirs: {}.".format(self._num_elixirs))

    def display_symbol(self):
        print('S', end="")
Пример #8
0
 def direita(self):
     """Movimenta o espaço em branco pra direita"""
     if self.vazio.y < self.tamanho - 1:
         self.trocaPeca(self.vazio, Pos.ponto(self.vazio.x,
                                              self.vazio.y + 1))
         self.vazio = Pos.ponto(self.vazio.x, self.vazio.y + 1)
Пример #9
0
 def esquerda(self):
     """Movimenta o espaço em branco pra esquerda"""
     if self.vazio.y > 0:
         self.trocaPeca(self.vazio, Pos.ponto(self.vazio.x,
                                              self.vazio.y - 1))
         self.vazio = Pos.ponto(self.vazio.x, self.vazio.y - 1)
Пример #10
0
 def baixo(self):
     """Movimenta o espaço em branco pra baixo"""
     if self.vazio.x != self.tamanho - 1:
         self.trocaPeca(self.vazio, Pos.ponto(self.vazio.x + 1,
                                              self.vazio.y))
         self.vazio = Pos.ponto(self.vazio.x + 1, self.vazio.y)
Пример #11
0
 def cima(self):
     """Movimenta o espaço em branco pra cima"""
     if self.vazio.x > 0:
         self.trocaPeca(self.vazio, Pos.ponto(self.vazio.x - 1,
                                              self.vazio.y))
         self.vazio = Pos.ponto(self.vazio.x - 1, self.vazio.y)
Пример #12
0
 def __init__(self, posx, posy, index, game):
     self.__pos = Pos(posx, posy)
     self.__index = index
     self.__game = game
Пример #13
0
 def __init__(self):
     self._elixir_price = 1
     self._shield_price = 2
     self._pos = Pos()
Пример #14
0
class Monster():
    def __init__(self, monster_id, health_capacity):
        self._monster_id = monster_id
        self._health_capacity = health_capacity
        self._health = health_capacity
        self._pos = Pos()
        self._drop_item_list = list()
        self._hint_list = list()

    def add_drop_item(self, key):
        self._drop_item_list.append(key)

    def add_hint(self, monster_id):
        self._hint_list.append(monster_id)

    def get_monster_id(self):
        return self._monster_id

    def get_pos(self):
        return self._pos

    def set_pos(self, row, column):
        self._pos.set_pos(row, column)

    def get_health_capacity(self):
        self._health_capacity

    def get_health(self):
        return self._health

    def lose_health(self):
        self._health -= 10
        return self._health <= 0

    def recover(self, healing_power):
        self._health = healing_power

    def action_on_soldier(self, soldier):
        if (self._health <= 0):
            self.talk('You had defeated me.\n')
        else:
            if (self.require_key(soldier.get_keys())):
                self.fight(soldier)
            else:
                self.display_hints()

    def require_key(self, keys):
        return self._monster_id in keys

    def display_hints(self):
        self.talk("Defeat Monster {} first.\n".format(self._hint_list))

    def fight(self, soldier):
        fight_enabled = True

        while fight_enabled:
            print("       | Monster{} | Soldier |".format(self._monster_id))
            print("Health | %8d | %7d |\n" %
                  (self._health, soldier.get_health()))
            choise = input(
                "=> What is the next step? (1 = Attack, 2 = Escape, 3 = Use Elixir.) Input: "
            )

            if choise == '1':
                if self.lose_health():
                    print("=> You defeated Monster{}.\n".format(
                        self._monster_id))
                    self.drop_items(soldier)
                    fight_enabled = False
                else:
                    if soldier.lose_health():
                        self.recover(self._health_capacity)
                        fight_enabled = False
            elif choise == '2':
                self.recover(self._health_capacity)
                fight_enabled = False
            elif choise == '3':
                if soldier.get_num_elixirs() == 0:
                    print("=> You have run out of elixirs.\n")
                else:
                    soldier.use_elixirs()
            else:
                print("=> Illegal choice!\n")

    def drop_items(self, soldier):
        for item in self._drop_item_list:
            soldier.add_key(item)

    def talk(self, text):
        print("Mosnter{}: {}".format(self._monster_id, text), end="")

    def display_symbol(self):
        print('M', end="")
Пример #15
0
 def __init__(self, posx, posy, index, game):
     self.pos = Pos.Pos(posx, posy)
     self.index = index
     self.game = game
Пример #16
0
 def __init__(self):
     self._health = 100
     self._num_elixirs = 2
     self._pos = Pos()
     self._keys = list()
Пример #17
0
def gen_challenge(seed, size):
    rand = seed
    p = Pos(seed, size)
    chal = p.gen_challenge().hashval
    chal = binascii.hexlify(chal)
    return (chal, p.path)