Пример #1
0
    def enter(self, player):

        print(
            dedent("""
        You stride boldly towards the cave. As you approach, two GOBLIN GUARDS
        emerge from the darkness. They are chittering in a language that you do not understand,
        but you have seen enough combat to understand the cruel gleam in their eyes.
        You must FIGHT!
        Press ENTER to begin the combat.
        """))

        self.choose(player)
        self.combat(units.Unit('GOBLIN GUARD', 5, 4), 2, player)

        print(
            dedent("""
        Victory over the GOBLIN GUARDS is yours! You take a moment to
        examine their belongings. Their arms and armor are crude and worthless, but you
        find 1 GOLD and a COPPER KEY. You decide that you have found everything of value
        that these lowly guards have to offer and head deeper into the cave.\n
        Press ENTER to continue.
        """))

        player.stats['gold'] += 1
        player.stats['items'].append('a copper key')

        self.choose(player)

        return 'first_fork'
Пример #2
0
    def createunit(self, unit):
        try:
            unit['fighter'] += ''
            if unit['fighter'] == 'bear':
                x = units.Bear()
                x.controller = 'ai'
                x.name = 'Медведь'
        except:
            if unit['fighter']['type'] == 'basic':
                x = units.Unit()
            elif unit['fighter']['type'] == 'warrior':
                x = units.Warrior()
            x.name = unit['name']
            x.controller = 'player'
            x.id = unit['fighter']['id']

        x.team = unit['team']

        return {unit['id']: x}
Пример #3
0
    def place_unit(self, pos):
        x, y = pos
        # Check if the cell is free to place here
        if self._field[x][y] is None:
            self._winner_checker.register_move(pos, self._current_player)

            # Logical placing of unit
            self._field[x][y] = self._current_player

            # Add unit to corresponding sprite group
            group = self._crosses \
                if self._current_player == units.Cross \
                else self._noughts
            group.add(units.Unit(self._current_player, pos, self._unit_size))

            # Check winner
            try:
                self._winner_checker.check_winner(self._field,
                                                  self._current_player)
            finally:
                self.update()

            # Switch player
            self._current_player ^= units.Cross  # using xor properties
Пример #4
0
    # create numpy array for units
    m.board = np.zeros((3, m.height, m.width), dtype=np.int32)
    for (row, col), unit_code in np.ndenumerate(np.array(splitted_units)):
        if unit_code != ".":
            unit_id = units.id_from_code(unit_code[0:2])
            unit_color = unit_code[2]
            unit_health = int(unit_code[3]) if len(unit_code) > 3 else 10

            color_id = colors.id_from_code(unit_color)

            m.board[0, row, col] = unit_id
            m.board[1, row, col] = color_id
            m.board[2, row, col] = unit_health

    m.board = np.array(
        [hexlib.oddr_to_axial_array(m.board[x]) for x in range(3)])

    ## create units dict from numpy array
    for row, col in np.transpose(np.nonzero(m.board[0] > 0)):
        unit_id, unit_color, unit_health = m.board[:, row, col]
        if unit_color not in m.units:
            m.units[unit_color] = []
        u = units.Unit(unit_id, unit_color, unit_health, row, col)
        m.units[unit_color].append(u)

for m in maps:
    pprint(vars(m))

#print hexlib.rings(maps[0].terrain.shape, 5, 5, 2)
Пример #5
0
    def __init__(self, gameWidth, gameHeight):

        self.selected = []
        self.dbbee = units.Unit(gameWidth, gameHeight)
Пример #6
0
 def addUnitAt(self,unit_type,col,row): #Make sure to update this for nations
   """Adds a new unit to the Game State at specified location.  Assigns to proper lists."""
   target_tile = self.world.getTile(col,row)
   unit = units.Unit(target_tile,unit_type)
   target_tile.units.append(unit)
   self.units.append(unit)
Пример #7
0
 def addUnit(self, unit_type, col, row):
     """Adds a new unit to the grid at specified location.  Assigns to proper lists."""
     target_coords = self.tiles[row][col]
     unit = units.Unit(target_coords, unit_type)
     target_coords.units.append(unit)
     self.units.append(unit)