Пример #1
0
    def __init__( self, gui, next=None,
                  rows=5, columns=7, ghost_eaters=3,
                  completeness=10, connectedness=60,
                  room_size=80,
                  escaped=0, eaten=0 ):
        Canvas.__init__( self, gui ) # superclass constructor
        
        self.next = next # function to move to next level
        self.rows = rows
        self.columns = columns
        self.room_size = room_size
        self.completeness = completeness
        self.connectedness = connectedness

        # game score
        self.escaped = escaped
        self.eaten = eaten

        # set up window
        self.title = "escape machine"
        width = (self.columns + 1) * self.room_size
        height = ((self.rows + 1) * self.room_size) + self.FONT_SIZE * 5
        self.size = ( width, height )

        # color ranking to determine movements
        self.color_lock = Lock()
        self.color_ranking = None

        text_x = width / 2
        text_y = (self.rows + 1) * self.room_size
        self.escaped_position = ( text_x, text_y )
        self.eaten_position = ( text_x, text_y + (2 * self.FONT_SIZE) )

        self.go_size = self.FONT_SIZE * 3
        self.go_position = ( text_x - (self.go_size * 2), text_y )
        self.go_center = tuple( p + self.go_size / 2 for p in self.go_position )
        self.go_hover = False
        
        # game variables
        self.black_ghost = None
        self.ghost_eaters = [None] * ghost_eaters
        self.purple_ghost_eaters = set()
        self.imprisoned_ghosts = set()
        self.game_over = False

        # generate maze
        self.rooms = None
        self.generate_maze()

        # start move thread
        self.moving_flag = False
        self.move_queue = Queue()
        self.move_thread = Thread( target=self.handle_move )
        self.move_thread.start()
Пример #2
0
    def __init__( self, assembly_graph, gui=None, room_size=30 ):
        self.draw_gui = False
        if gui is not None:
            self.draw_gui = True
            Canvas.__init__( self, gui )
            self.room_size = room_size

            # set up window
            self.title = "color rank"
            width = self.room_size * 6.5
            height = self.room_size * 7.5
            self.size = ( width, height )
        
        self.maze = None
        self.assembly_graph = assembly_graph

        # set rank colors method as graph observer
        assembly_graph.observers.append( self.rank_colors )

        self.ranked_colors = { 0:[], 1:[], 2:[], 3:[] }