def __init__(self, master): """Constructor Parameters: master (tk.Tk|tk.Frame): The parent widget """ super().__init__(master) self._moves = tk.Label(self, text='20', font="Verdana 25") self._moves.pack(side=tk.LEFT, anchor=tk.NW) frame = tk.Frame(self) frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self._score = tk.Label(frame, text='0', font="Verdana 25", fg='grey') self._score.pack(side=tk.LEFT, anchor=tk.E, expand=1) self._img = tk.PhotoImage(file='images/companions/eskimo.png') self._companion = tk.Label(frame, image=self._img) self._companion.pack(anchor=tk.CENTER, expand=1) self._interval_bar = tk.Canvas(frame, height=25) self._interval_bar.pack(side=tk.BOTTOM) self.reset_bar() self._image_manager = ImageManager('images/dots/', loader=load_image) self._objectives = ObjectivesView(self, image_manager=self._image_manager) self._objectives.pack(side=tk.RIGHT, anchor=tk.E, expand=1)
class InfoPanel(tk.Frame): """show remaining moves, score, companion and objectives""" def __init__(self, parent): super().__init__(parent) # remaining moves of the game self._moves = tk.Label(self, font='Helvetica 30') self._moves.pack(side=tk.LEFT, anchor=tk.NW) # show the score self._scores = tk.Label(self, font='Helvetica 20', fg="grey") self._scores.pack(side=tk.LEFT, anchor=tk.SW, padx=20) # show the image img = tk.PhotoImage(file="images/companions/images.png") self._image = tk.Label(self, image=img) self._image.img = img self._image.pack(side=tk.LEFT, anchor=tk.CENTER) # show the objectives self._image_manager = ImageManager('images/dots/', loader=load_image) self._object = ObjectivesView(self, image_manager=self._image_manager) self._object.pack(side=tk.RIGHT, pady=50) # get the current moves def remain_moves(self): return self._moves # get object def set_object(self): return self._object # get the current score def set_scores(self): return self._scores
def __init__(self, master, image_manager: ImageManager = None): super().__init__(master) self._image_manager = image_manager self._moves_label = tk.Label(self, font=('Helvetica', 30)) self._score_label = tk.Label(self, font=('Helvetica', 30), fg='gray') self._companion_label = tk.Label(self) self._objectives_view = ObjectivesView( self, image_manager=self._image_manager) self._interval_bar = IntervalBar(self) self._moves_label.grid(row=0, column=0, sticky=(tk.N, tk.W), padx=(20, 0), pady=10) self._score_label.grid(row=1, column=0, sticky=(tk.S, tk.E), padx=(0, 5), pady=(0, 10)) self._companion_label.grid(row=0, column=1, rowspan=2, pady=(5, 0)) self._objectives_view.grid(row=0, column=2, rowspan=2, padx=(10, 5)) self._interval_bar.grid(row=2, column=0, columnspan=3, pady=(5, 0)) self.columnconfigure(0, weight=1)
def __init__(self, parent): super().__init__(parent) # remaining moves of the game self._moves = tk.Label(self, font='Helvetica 30') self._moves.pack(side=tk.LEFT, anchor=tk.NW) # show the score self._scores = tk.Label(self, font='Helvetica 20', fg="grey") self._scores.pack(side=tk.LEFT, anchor=tk.SW, padx=20) # show the image img = tk.PhotoImage(file="images/companions/images.png") self._image = tk.Label(self, image=img) self._image.img = img self._image.pack(side=tk.LEFT, anchor=tk.CENTER) # show the objectives self._image_manager = ImageManager('images/dots/', loader=load_image) self._object = ObjectivesView(self, image_manager=self._image_manager) self._object.pack(side=tk.RIGHT, pady=50)
class InfoPanel(tk.Frame): def __init__(self, parent): super().__init__(parent) self.remaining_moves_label = tk.Label(self, font=('Times New Roman', 20, 'italic')) self.remaining_moves_label.pack(side=tk.LEFT, anchor=tk.NW) self.score_label = tk.Label(self) self.score_label.pack(side=tk.LEFT, anchor=tk.S) self.icon_button = tk.Button(self) self.icon_button.pack(side=tk.LEFT) self.objectives = None def set_default_icon(self, icon): self.icon_button.config(image=icon) def set_objectives(self, image_manager, objectives): self.objectives = ObjectivesView(self, image_manager=image_manager) self.objectives.pack(side=tk.RIGHT) self.objectives.draw(objectives) def refresh_objectives(self, objectives): self.objectives.draw(objectives) def decrease_remaining_moves_and_increase_score(self, moves, score): self.remaining_moves_label.config(text=moves) self.score_label.config(text=score)
def set_objectives(self, image_manager, objectives): self.objectives = ObjectivesView(self, image_manager=image_manager) self.objectives.pack(side=tk.RIGHT) self.objectives.draw(objectives)
class InfoPanel(tk.Frame): """Displays information to the user.""" def __init__(self, master): """Constructor Parameters: master (tk.Tk|tk.Frame): The parent widget """ super().__init__(master) self._moves = tk.Label(self, text='20', font="Verdana 25") self._moves.pack(side=tk.LEFT, anchor=tk.NW) frame = tk.Frame(self) frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self._score = tk.Label(frame, text='0', font="Verdana 25", fg='grey') self._score.pack(side=tk.LEFT, anchor=tk.E, expand=1) self._img = tk.PhotoImage(file='images/companions/eskimo.png') self._companion = tk.Label(frame, image=self._img) self._companion.pack(anchor=tk.CENTER, expand=1) self._interval_bar = tk.Canvas(frame, height=25) self._interval_bar.pack(side=tk.BOTTOM) self.reset_bar() self._image_manager = ImageManager('images/dots/', loader=load_image) self._objectives = ObjectivesView(self, image_manager=self._image_manager) self._objectives.pack(side=tk.RIGHT, anchor=tk.E, expand=1) def set_moves(self, moves): """Sets the remaining moves Parameters: moves (int): the remaining moves """ self._moves.config(text='{}'.format(moves)) def set_score(self, score): """Sets the score Parameters: score (int): the score that the user gains """ self._score.config(text='{}'.format(score)) def set_objectives(self, objectives): """Updates the objectives Parameters: objectives (list<tuple<AbstractDot, int>>): List of (objective, remaining) pairs """ self._objectives.draw(objectives) def set_companion(self, img): """Sets the companion image Parameter: img (tk.PhotoImage): The companion image """ self._img = img self._companion.config(image=self._img) def set_bar(self, step): """Sets the interval bar When the game is with a companion, the bar shows the times of charging the companion When the game is without a companion, the bar shows the user's moves Parameter: step (int): The progress that the bar reaches """ self._interval_bar.create_rectangle(10 + step * BAR_WIDTH, 5, 10 + (step + 1) * BAR_WIDTH, 5 + BAR_HIGHT, fill='SkyBlue') def reset_bar(self): """Resets the interval bar""" self._interval_bar.delete("all") for i in range(6): self._interval_bar.create_rectangle(10 + i * BAR_WIDTH, 5, 10 + (i + 1) * BAR_WIDTH, 5 + BAR_HIGHT)
class InfoPanel(tk.Frame): """This frame display game's information""" def __init__(self, master, image_manager: ImageManager = None): super().__init__(master) self._image_manager = image_manager self._moves_label = tk.Label(self, font=('Helvetica', 30)) self._score_label = tk.Label(self, font=('Helvetica', 30), fg='gray') self._companion_label = tk.Label(self) self._objectives_view = ObjectivesView( self, image_manager=self._image_manager) self._interval_bar = IntervalBar(self) self._moves_label.grid(row=0, column=0, sticky=(tk.N, tk.W), padx=(20, 0), pady=10) self._score_label.grid(row=1, column=0, sticky=(tk.S, tk.E), padx=(0, 5), pady=(0, 10)) self._companion_label.grid(row=0, column=1, rowspan=2, pady=(5, 0)) self._objectives_view.grid(row=0, column=2, rowspan=2, padx=(10, 5)) self._interval_bar.grid(row=2, column=0, columnspan=3, pady=(5, 0)) self.columnconfigure(0, weight=1) def set_companion(self, companion_name): """Set the companion's image on info panel Parameters: companion_name (str): The name of the companion """ image = Image.open('images/companions/' + companion_name + '.png').resize((200, 200)) self._companion_label.image = ImageTk.PhotoImage(image) self._companion_label.configure(image=self._companion_label.image) def set_score(self, score): self._score_label.configure(text=str(score)) def set_moves(self, moves): self._moves_label.configure(text=str(moves)) def hide_moves(self): """Hide the moves on panel""" self._moves_label.configure(fg='white') def show_moves(self): """Show the moves on panel""" self._moves_label.configure(fg='black') def set_objectives(self, objectives_status): """Update the objectives view widget Parameters: objectives_status (list<dot, count>): The status of the objective """ self._objectives_view.draw(objectives_status) def set_interval(self, max_charge, charge): """Update the interval bar Parameters: max_charge (int): The maximum number of charge charge (int): The current number of charge """ self._interval_bar.draw(max_charge, charge)