当前位置: 首页>>代码示例>>Python>>正文


Python Grid.clear方法代码示例

本文整理汇总了Python中grid.Grid.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.clear方法的具体用法?Python Grid.clear怎么用?Python Grid.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grid.Grid的用法示例。


在下文中一共展示了Grid.clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GameDisplay

# 需要导入模块: from grid import Grid [as 别名]
# 或者: from grid.Grid import clear [as 别名]
class GameDisplay(Stage):
    def __init__(self, parent, state):
        Stage.__init__(self, parent)
        self.state = state
        
        self.state = state
        
        self.fps_counter = FpsCounter()

        self.init_widgets()
        self.init_bindings()

        self.ghost_piece = None

        #True when the user pauses the game
        self.paused = False

        #True when a coroutine is playing that should halt game logic, ex. when lines flash before disappearing
        self.blocking = False

        self.state.register_listener(self.model_alert)
        self.state.start()
        self.update_labels()

    def init_widgets(self):
        rows = self.state.rows - self.state.obstructed_rows
        self.field = Grid(self, rows=rows, cols=self.state.cols, length=25, background_color = level_colors[0])
        self.field.grid(row=0,column=0)

        info = Frame(self)
        info.grid(row=0, column=1)

        Label(info, text="Hold").pack()
        self.hold = Grid(info, rows=4, cols=4, length=25)
        self.hold.pack()

        Label(info, text="Preview").pack()
        self.preview = Grid(info, rows=4, cols=4, length=25)
        self.preview.pack()

        self.level_label = ExLabel(info)
        self.level_label.pack()

        self.line_label = ExLabel(info)
        self.line_label.pack()

        self.score_label = ExLabel(info)
        self.score_label.pack()

        self.fps_label = ExLabel(info)
        self.fps_label.pack()

    def init_bindings(self):
        self.bind_parent("<Down>", lambda *event: self.send(Request.down))
        self.bind_parent("<Left>", lambda *event: self.send(Request.left))
        self.bind_parent("<Right>", lambda *event: self.send(Request.right))
        self.bind_parent("<Return>", lambda *event: self.send(Request.hard_drop))
        self.bind_parent("<space>", lambda *event: self.send(Request.rotate_left))
        self.bind_parent("<z>", lambda *event: self.send(Request.rotate_left))
        self.bind_parent("<Up>", lambda *event: self.send(Request.hold))
        self.bind_parent("<x>", lambda *event: self.send(Request.rotate_right))
        self.bind_parent("<p>", lambda *event: self.toggle_paused())
        self.bind_parent("<c>", lambda *event: self.send(Request.up))
        
    def toggle_paused(self):
        self.paused = not self.paused
        if self.paused:
            sound.pause_music()
        else:
            sound.resume_music()
        sound.play("pause")

    def update_labels(self):
        self.score_label.set("Score: " + str(self.state.score))
        self.line_label.set("Lines: " + str(self.state.lines_cleared))
        self.level_label.set("Level: " + str(self.state.level))

    def send(self, msg):
        if not self.paused and not self.blocking:
            self.state.consume_message(msg)

    def idle(self):
        self.fps_counter.tick()
        self.fps_label.set("FPS: " + str(self.fps_counter.fps))
        if not self.blocking:
            self.send(Request.idle)

    def model_alert(self, message):
        """
            callback function for messages from the game state.
        """
        def set(piece, color, grid=self.field):
            for p in piece:
                grid.set(p, color)
        def update_ghost_piece():
            #erase the last frame's ghost piece
            if self.ghost_piece:
                set(self.ghost_piece, None)
            
            self.ghost_piece = self.state.get_ghost_piece()
#.........这里部分代码省略.........
开发者ID:kms70847,项目名称:Falling-Block-Game,代码行数:103,代码来源:gameDisplay.py

示例2: Game

# 需要导入模块: from grid import Grid [as 别名]
# 或者: from grid.Grid import clear [as 别名]
class Game():

    def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
        self._activity = parent
        self.colors = colors

        # Starting from command line
        if parent is None:
            self._running_sugar = False
            self._canvas = canvas
        else:
            self._running_sugar = True
            self._canvas = canvas
            parent.show_all()

        self._canvas.set_flags(gtk.CAN_FOCUS)
        self._canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK)
        self._canvas.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
        self._canvas.add_events(gtk.gdk.POINTER_MOTION_MASK)
        self._canvas.connect("expose-event", self._expose_cb)
        self._canvas.connect("button-press-event", self._button_press_cb)
        self._canvas.connect("button-release-event", self._button_release_cb)
        self._canvas.connect("motion-notify-event", self._mouse_move_cb)
        self._canvas.connect("key_press_event", self._keypress_cb)

        self._width = gtk.gdk.screen_width()
        self._height = gtk.gdk.screen_height() - (GRID_CELL_SIZE * 1.5)
        self._scale = self._height / (8.0 * TILE_HEIGHT)
        self.tile_width = TILE_WIDTH * self._scale
        self.tile_height = TILE_HEIGHT * self._scale

        # Generate the sprites we'll need...
        self._sprites = Sprites(self._canvas)
        self.grid = Grid(self._sprites, self._width, self._height,
                         self.tile_width, self.tile_height, self._scale,
                         colors[0])
        self.deck = Deck(self._sprites, self._scale, colors[1])
        self.deck.board.move((self.grid.left, self.grid.top))
        self.hands = []
        self.hands.append(Hand(self.tile_width, self.tile_height))
        self._errormsg = []
        for i in range(4):
            self._errormsg.append(error_graphic(self._sprites))
        self._highlight = highlight_graphic(self._sprites, self._scale)
        self._score_card = blank_tile(self._sprites, scale=self._scale * 2,
                                      color=colors[1])
        self._score_card.set_label_attributes(64)
        self._score_card.move(((int(self._width / 2) - self.tile_width),
                               int(self._height / 2) - self.tile_height))

        # and initialize a few variables we'll need.
        self.buddies = []
        self._my_hand = MY_HAND
        self.playing_with_robot = False
        self._all_clear()

    def _all_clear(self):
        ''' Things to reinitialize when starting up a new game. '''
        self._hide_highlight()
        self._hide_errormsgs()
        self.deck.hide()
        self.deck.clear()
        self.grid.clear()
        for hand in self.hands:
            hand.clear()
        self.show_connected_tiles()

        self._press = None
        self._release = None
        self._dragpos = [0, 0]
        self._total_drag = [0, 0]
        self.last_spr_moved = None
        self._last_tile_played = None
        self._last_tile_orientation = 0
        self._last_grid_played = None

        self.whos_turn = MY_HAND
        self._waiting_for_my_turn = False
        self._waiting_for_robot = False
        self.placed_a_tile = False
        self._there_are_errors = False

        self.score = 0
        self._score_card.set_layer(HIDE)
        self._score_card.move(((int(self._width / 2) - self.tile_width),
                               int(self._height / 2) - self.tile_height))
        self.saw_game_over = False

    def _initiating(self):
        if not self._running_sugar:
            return True
        return self._activity.initiating

    def new_game(self, saved_state=None, deck_index=0):
        ''' Start a new game. '''
        self._all_clear()

        # If we are not sharing or we are the sharer...
        if not self.we_are_sharing() or self._initiating():
            # Let joiners know we are starting a new game...
#.........这里部分代码省略.........
开发者ID:erilyth,项目名称:paths,代码行数:103,代码来源:game.py

示例3: __init__

# 需要导入模块: from grid import Grid [as 别名]
# 或者: from grid.Grid import clear [as 别名]

#.........这里部分代码省略.........

                section = Grid(self.board.ncolumns, self.board.nrows)
                for j in range(section_min, section_max):
                    section.put((j, r), 'X')
                self.sections.append(section)

                self.section_nodes.append(create_node(self.section_node, 'rect',
                    pos=self.board.get_nw_point((section_min, r)),
                    size=Point2D(section_ncolumns, 1)*self.board.scale,
                    opacity=0.2,
                    color='ffffff',
                    sensitive=False))

                section_min = section_max

    def destroy(self):
        self.pause()
        for piece in self.pieces:
            piece.destroy()
        for node in self.section_nodes:
            node.unlink()
        self.board.destroy()
        self.node.unlink()
        self.board_rect.unlink()
        self.section_node.unlink()
        self.starting_zone_node.unlink()

    def run(self):
        self.pause()
        self.interval_id = set_interval(self.tick_interval, self.tick)

    def pause(self):
        if self.interval_id:
            clear_interval(self.interval_id)
            self.interval_id = None

    def tick(self):
        """Advance the game by one step."""
        self.fall_and_freeze()
        self.delete_dissolving()
        self.mark_dissolving()
        if (not list(self.dissolving.get_blocks()) and
            self.board.frozen_grid.overlaps_any(self.starting_zone, (0, 0))):
            self.app.end_game()
            return

        self.ticks_to_next_drop -= 1
        if (self.ticks_to_next_drop <= 0 or
            not list(self.board.piece_grid.get_blocks())):
            self.ticks_to_next_drop = self.ticks_per_drop
            for p in range(self.pieces_per_drop):
                if not self.add_piece():
                    print 'end_game: add_piece failed'
                    self.app.end_game()
                    return

        self.app.tick()

    def fall_and_freeze(self):
        """Classify all pieces as suspended (by a player grab), stopped (by
        frozen blocks), or falling; move falling pieces down by one step and
        freeze all stopped pieces."""

        # 1. Determine what supports each piece.  Pieces can be supported by
        # other pieces, by frozen blocks, or by the bottom edge of the board.
        supported_pieces = dict((piece, set()) for piece in self.pieces)
开发者ID:lynxis,项目名称:mtc-multitet,代码行数:70,代码来源:multitet.py


注:本文中的grid.Grid.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。