Пример #1
0
    def clear_sand(self, direction, dune_blaster = False):
        tile_to_clear = None
        x_delta = 0
        y_delta = 0
        if direction == "n":
            y_delta = -1
        elif direction == "s":
            y_delta = 1
        elif direction == "w":
            x_delta = -1
        elif direction == "e":
            x_delta = 1
        elif direction == "c":
            pass
        elif self.ability == "Explorer":
            if direction == "ne":
                y_delta = -1
                x_delta = 1
            if direction == "se":
                y_delta = 1
                x_delta = 1
            if direction == "nw":
                y_delta = -1
                x_delta = -1
            if direction == "sw":
                y_delta = 1
                x_delta = -1
        if self.current_tile.position["row"] + x_delta < 0 or self.current_tile.position["col"] + y_delta < 0:
            return False
        if self.current_tile.position["row"] + x_delta > 4 or self.current_tile.position["col"] + y_delta > 4:
            return False
        else:
            tile_to_clear = get_tile(self.board.tiles, [self.current_tile.position["row"] + x_delta, self.current_tile.position["col"] + y_delta])


        if tile_to_clear is None:
            return False, 0

        if tile_to_clear.sand < 1:
            return False, 0

        if dune_blaster:
            returnamount = tile_to_clear.sand
            tile_to_clear.sand = 0
            return True, returnamount
        elif self.ability == "Archaeologist":
            if tile_to_clear.sand == 1:
                tile_to_clear.sand = 0
                return True, 1
            else:
                tile_to_clear.sand -= 2
                return True, 2
        else:
            tile_to_clear.sand -= 1
            return True, 1
Пример #2
0
    def place_ship_item_if_needed(self, excavated_tile):
        """
        To be called after excavation to see if this excavation should place a ship item on the board
        """
        matching_tile_horiz = None
        matching_tile_vert = None
        vertlist = [excavated_tile.engine_vert, excavated_tile.propeller_vert, excavated_tile.wheel_vert, excavated_tile.crystal_vert]
        horizlist = [excavated_tile.engine_horiz, excavated_tile.propeller_horiz, excavated_tile.wheel_horiz, excavated_tile.crystal_horiz]
        for i, vert in enumerate(vertlist):
            if vert:
                for tile in self.tiles:
                    tile_horizlist = [tile.engine_horiz, tile.propeller_horiz, tile.wheel_horiz, tile.crystal_horiz]
                    horiz = tile_horizlist[i]
                    if horiz and tile.excavated:
                        matching_tile_horiz = tile
                        matching_tile_vert = excavated_tile
                        break
        for i, horiz in enumerate(horizlist):
            if horiz:
                for tile in self.tiles:
                    tile_vertlist = [tile.engine_vert, tile.propeller_vert, tile.wheel_vert, tile.crystal_vert]
                    vert = tile_vertlist[i]
                    if vert and tile.excavated:
                        matching_tile_horiz = excavated_tile
                        matching_tile_vert = tile
                        break

        if matching_tile_horiz is not None and matching_tile_vert is not None:
            if matching_tile_horiz.engine_horiz:
                get_tile(self.tiles, [matching_tile_vert.position["row"], matching_tile_horiz.position["col"]]).engine_on = True
            if matching_tile_horiz.propeller_horiz:
                get_tile(self.tiles, [matching_tile_vert.position["row"], matching_tile_horiz.position["col"]]).propeller_on = True
            if matching_tile_horiz.crystal_horiz:
                get_tile(self.tiles, [matching_tile_vert.position["row"], matching_tile_horiz.position["col"]]).crystal_on = True
            if matching_tile_horiz.wheel_horiz:
                get_tile(self.tiles, [matching_tile_vert.position["row"], matching_tile_horiz.position["col"]]).wheel_on = True


        return False
Пример #3
0
 def print_board(self):
     board_width = 110
     print_string = "-" * board_width
     print_string += "\n"
     for row in range(5):
         for col in range(5):
             position = [col,row]
             tile = get_tile(self.tiles, position)
             print_string += "| %s |" % tile
         print_string += "\n"
     print_string += "-" * board_width
     print_string += "\n"
     print print_string
Пример #4
0
    def use_water_carrier(self, sharing=False):
        to_use = None
        #  If there is only the option to use one, just use that one. If no options, return False


        #  See if [A] is available
        players_available = []
        for row_delta, col_delta in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
            # Check to make sure each tile is in bounds
            row = self.current_tile.position["row"] + row_delta
            col = self.current_tile.position["col"] + col_delta

            if row >= 0 and row <= 4 and col >= 0 and col <= 4:
                players_available += get_tile(self.board.tiles, [row, col]).players_on
        for player in self.current_tile.players_on:
            if player != self:
                players_available.append(player)

        if len(players_available) > 0:
            to_use = "a"

        #  See if [B] is available
        if self.current_tile.excavated and self.current_tile.is_water:
            if to_use == "a":
                to_use = None
        else:
            if to_use is None:
                return False, 0

        if sharing:
            to_use = "a"


        if to_use is None:
            to_use = raw_input("Use [A] give water [B] draw from well ").lower()
        if to_use == "a":
            who_to_give = raw_input("Select which player to give to [%s]: " % map(show_player_list, players_available)).lower()
            player_to_give = None
            for player in players_available:
                if who_to_give == player.ability[0].lower():
                    player_to_give = player
                    break
            if player_to_give is None:
                return False, 0
            self.water -= 1
            player_to_give.water = min([player_to_give.max_water, player_to_give.water+1])
            print "%s water: %d, %s water: %d" % (self.ability, self.water, player_to_give.ability, player_to_give.water)
            return True, 1
        elif to_use == "b":
            self.water = min([self.max_water, self.water + 2])
            return True, 0
Пример #5
0
    def _use_zerascope(self):
        to_view = raw_input("Which tile to peek at [row, col]? ")
        if to_view.find(",") == -1:
            print "Invalid input"
            return False, 0, 0
        to_view = to_view.split(",")
        row = to_view[0].strip()
        col = to_view[1].strip()
        if int(row) < 0 or int(row) > 4 or int(col) < 0 or int(col) > 4:
            print "Invalid input"
            return False, 0, 0

        tile_to_view = get_tile(self.board.tiles, [row, col])
        tile_to_view.excavated = True
        what_it_is = str(tile_to_view)
        print "It is a %s!" % what_it_is
        tile_to_view.excavated = False
        return True, 0, 1
Пример #6
0
    def _use_jetpack(self, player):
        to_jetpack = raw_input("Which tile to vroom vroom to [row, col]? ")
        if to_jetpack.find(",") == -1:
            print "Invalid input"
            return False, 0, 0
        to_jetpack = to_jetpack.split(",")
        row = to_jetpack[0].strip()
        col = to_jetpack[1].strip()
        if int(row) < 0 or int(row) > 4 or int(col) < 0 or int(col) > 4:
            print "Invalid input"
            return False, 0, 0

        tile_to_jetpack_to = get_tile(self.board.tiles, [row, col])
        if tile_to_jetpack_to.sand > 1 and player.ability != "Climber":
            return False, 0, 0

        player_to_bring = player._select_player_on_current_tile()

        player._move_to_tile(tile_to_jetpack_to)
        if player_to_bring is not None:
            player_to_bring._move_to_tile(tile_to_jetpack_to)
        return True, 0, 1
Пример #7
0
 def get_tile(self, cid):
     """fetch info about a tiled tiff, or retrieve a specific tile."""
     _id = bson.ObjectId(cid)
     container, _ = self._get(_id, 'ro')  # need at least read access to view tiles
     montage_info = None
     for f in container.get('files'):
         if f['filetype'] == 'montage':
             montage_info = f
             break
     if not montage_info:
         self.abort(404, 'montage zip not found')
     fn = montage_info['filename']
     fp = os.path.join(self.app.config['data_path'], cid[-3:], cid, fn)
     z = self.request.GET.get('z')
     x = self.request.GET.get('x')
     y = self.request.GET.get('y')
     if not (z and x and y):
         return util.get_info(fp)
     else:
         self.response.content_type = 'image/jpeg'
         tile = util.get_tile(fp, int(z), int(x), int(y))
         if tile:
             self.response.write(tile)
Пример #8
0
 def get_tile(self, cid):
     """fetch info about a tiled tiff, or retrieve a specific tile."""
     _id = bson.ObjectId(cid)
     container, _ = self._get(
         _id, 'ro')  # need at least read access to view tiles
     montage_info = None
     for f in container.get('files'):
         if f['filetype'] == 'montage':
             montage_info = f
             break
     if not montage_info:
         self.abort(404, 'montage zip not found')
     fn = montage_info['filename']
     fp = os.path.join(self.app.config['data_path'], cid[-3:], cid, fn)
     z = self.request.GET.get('z')
     x = self.request.GET.get('x')
     y = self.request.GET.get('y')
     if not (z and x and y):
         return util.get_info(fp)
     else:
         self.response.content_type = 'image/jpeg'
         tile = util.get_tile(fp, int(z), int(x), int(y))
         if tile:
             self.response.write(tile)
Пример #9
0
    def move(self, direction, moved_by_climber = False):
        if self.current_tile.sand > 1 and self.ability != "Climber" and not moved_by_climber \
                and "Climber" not in map(lambda x: x.ability, self.current_tile.players_on):
            print "You are buried and can not move!"
            return False
        tile_to_move_to = None

        x_delta = 0
        y_delta = 0
        if direction == "n":
            y_delta = -1
        elif direction == "s":
            y_delta = 1
        elif direction == "w":
            x_delta = -1
        elif direction == "e":
            x_delta = 1
        elif self.ability == "Explorer":
            if direction == "ne":
                y_delta = -1
                x_delta = 1
            elif direction == "se":
                y_delta = 1
                x_delta = 1
            elif direction == "nw":
                y_delta = -1
                x_delta = -1
            elif direction == "sw":
                y_delta = 1
                x_delta = -1
            else:
                if direction != "t":
                    print "Invalid direction"
                    return False
        else:
            if direction != "t":
                print "Invalid direction"
                return False
        if self.current_tile.position["row"] + x_delta < 0 or self.current_tile.position["col"] + y_delta < 0:
            return False
        if self.current_tile.position["row"] + x_delta > 4 or self.current_tile.position["col"] + y_delta > 4:
            return False
        else:
            tile_to_move_to = get_tile(self.board.tiles, [self.current_tile.position["row"] + x_delta, self.current_tile.position["col"] + y_delta])

        if direction == "t":
            to_tunnel = raw_input("Which tile to tunnel to [row, col]? ")
            if to_tunnel.find(",") == -1:
                print "Invalid input"
                return False, 0, 0
            to_tunnel = to_tunnel.split(",")
            row = to_tunnel[0].strip()
            col = to_tunnel[1].strip()
            if int(row) < 0 or int(row) > 4 or int(col) < 0 or int(col) > 4:
                print "Invalid input"
                return False, 0, 0

            tile_to_tunnel_to = get_tile(self.board.tiles, [row, col])
            if tile_to_tunnel_to.tunnel and tile_to_tunnel_to.excavated:
                tile_to_move_to = tile_to_tunnel_to
            else:
                return False, 0, 0

        if tile_to_move_to is None:
            print "Incorrect direction specified!"
            return False

        if tile_to_move_to.blank:
            print "You can't move to the blank space!"
            return False
        elif tile_to_move_to.sand > 1 and self.ability != "Climber" and not moved_by_climber:
            print "You can't move to the space because too much sand!"
            return False
        else:
            if self.ability == "Climber":
                player_to_bring = self._select_player_on_current_tile()
                if player_to_bring is not None:
                    player_to_bring._move_to_tile(tile_to_move_to)
            self._move_to_tile(tile_to_move_to)
            return True
Пример #10
0
    def draw_cards(self):
        storm_increments = 0
        for i in range(self.storm.this_turn_storm_level):
            self.board.print_board()
            to_use = "init"
            while to_use != "":
                to_use = raw_input("Press ENTER to Draw Card... (E[Q]uipment, [D]isplay info, [S]hare) ").lower().strip()
                if to_use == "q":
                    self.players[0].use_equipment(self.players, during_storm_cards=True)
                elif to_use == "d":
                    self.players[0].display(self.storm, self.players)
                elif to_use == "s":
                    self.players[0].select_sharer(self.players)

            card = self.storm.draw_card()
            if card == "Sun beats down":
                print card
                for player in self.players:
                    if (not player.current_tile.tunnel or not player.current_tile.excavated) and not player.is_solar_shielded():
                        player.water -= 1
                    print "%s: %d water remaining." % (player.ability, player.water)
                    if player.water < 0:
                        print "\n\nYou have lost! %s has run out of water!" % player.ability
                        exit(0)
            elif card == "Storm picks up":
                print card
                storm_increments += 1
            else: #Move stuff
                move_direction = card[0]
                move_amount = card[1]
                storm_center_tile = get_storm_center(self.board.tiles)
                print move_amount,
                if move_direction == "n":
                        print "v"
                elif move_direction == "s":
                        print "^"
                elif move_direction == "w":
                        print "->"
                elif move_direction == "e":
                        print "<-"
                for i in range(move_amount):
                    x_delta = 0
                    y_delta = 0
                    if move_direction == "n":
                        y_delta = -1
                    elif move_direction == "s":
                        y_delta = 1
                    elif move_direction == "w":
                        x_delta = -1
                    elif move_direction == "e":
                        x_delta = 1
                    if storm_center_tile.position["row"] + x_delta < 0 or storm_center_tile.position["col"] + y_delta < 0:
                        break
                    if storm_center_tile.position["row"] + x_delta > 4 or storm_center_tile.position["col"] + y_delta > 4:
                        break
                    else:
                        card_to_move = get_tile(self.board.tiles, [storm_center_tile.position["row"] + x_delta, storm_center_tile.position["col"] + y_delta])
                        self.board.switch_tile_positions(storm_center_tile, card_to_move)
                        self.storm.sand -= 1
        #  Raise storm level
        for i in range(storm_increments):
            self.storm.increment_storm_pointer()
            if self.storm.storm_level == "Death":
                print "\n\nYou have lost! Storm level has reached max storm!"
                exit(0)
        self.storm.this_turn_storm_level = self.storm.structure[self.storm.storm_pointer]
Пример #11
0
 def __setup_init_sand__(self):
     tile_positions = [(0,2),(2,0),(4,2),(2,4),(1,3),(3,1),(1,1),(3,3)]
     for position in tile_positions:
         get_tile(self.tiles, position).sand = 1