コード例 #1
0
    def _draw_player_laps(self):
        """Draws laps traveled per player with a loop."""

        for i in range(len(self.service.players)):
            laps = display_textbox(self.window, 1, 5, TEXT_FONT)
            laps.place(x=310, y=90 + (i * 25), anchor="w")
            laps.insert(tk.END, self.service.laps[i])
            laps.config(state=DISABLED)
コード例 #2
0
    def _draw_player_names(self):
        """Draws player names with a loop."""

        for i, player in enumerate(self.service.players):
            player = display_textbox(self.window, 1, 25, TEXT_FONT)
            player.place(x=30, y=90 + (i * 25), anchor="w")
            player.insert(tk.END, self.service.players[i])
            player.config(state=DISABLED)
コード例 #3
0
    def _build_widgets(self):
        """Builds the widgets of the parent window."""

        title = display_textbox(self.window, 1, 60, TITLE_FONT)
        title.place(x=30, y=30)
        title.insert(tk.END, "Trivioboros")
        title.config(state=DISABLED)

        rules = display_textbox(self.window, 40, 87, TEXT_FONT)
        rules.place(x=30, y=80)
        rules.insert(tk.END, self._game_rules_text())
        rules.config(state=DISABLED)

        button(
            self.window,
            "Got it!",
            self.window.destroy,
        ).place(x=370, y=580, anchor="center")
コード例 #4
0
    def _draw_player_names(self, window):
        """Draw the player names on the scoreboard with a loop."""

        y_increase = 0
        for i in range(len(self.players)):
            player = display_textbox(window, 1, 25, TEXT_FONT)
            player.place(x=40, y=30 + y_increase, anchor="w")
            player.insert(tk.END, self.players[i])
            player.config(state=DISABLED, fg=self.player_colors[i])
            y_increase += 25
コード例 #5
0
    def _build_widgets(self):
        """Builds the widgets of the parent window."""

        title = display_textbox(self.window, 1, 85, TITLE_FONT)
        title.place(x=30, y=30)
        title.insert(tk.END, "Laps per player")
        title.config(state=DISABLED)

        self._draw_player_names()
        self._draw_player_laps()

        button(self.window, "Got it!",
               self.window.destroy).place(x=180, y=260, anchor="center")
コード例 #6
0
    def _draw_board(self):
        """Draws the category board on the canvas with a loop."""

        x_increase = 0
        y_increase = 0
        for i in range(len(self.categories)):
            category = display_textbox(self.window, 1, 25, TEXT_FONT)
            category.place(x=40 + x_increase, y=560 + y_increase, anchor="w")
            category.insert(tk.END, self.categories[i])
            category.config(state=DISABLED, fg=self.category_colors[i])
            y_increase += 25
            if i == 5:
                x_increase += 250
                y_increase = 0
コード例 #7
0
    def _show_answer(self):
        """Shows the correct answer and buttons for confirming
        whwther the player's answer was correct."""

        self.answer_textbox = display_textbox(self.window, 3, 45)
        self.answer_textbox.place(x=30, y=420, anchor="w")
        self.answer_textbox.insert(tk.END,
                                   self.service.get_answer_for_player())
        self.answer_textbox.config(state=DISABLED)

        self.answer_correct_btn = button(
            self.window,
            "Player's answer was correct",
            self._handle_correct_answer,
        )
        self.answer_correct_btn.place(x=30, y=490, anchor="w")

        self.answer_incorrect_btn = button(
            self.window,
            "Player's answer was incorrect",
            self._handle_incorrect_answer,
        )
        self.answer_incorrect_btn.place(x=300, y=490, anchor="w")
コード例 #8
0
    def _handle_question_phase(self):
        """Shows the current category and question,
        and builds a button for showing the correct answer.

        If an error occurs while retrieving a category from the Open Trivia Database,
        i.e. the category is None, calls another method that will handle the situation,
        so that the UI won't get stuck in an unplayable state."""

        if self.service.get_category_for_player() is None:
            self._handle_category_error()
        else:
            self.category_board.highlight_category(
                self.service.current_category_index)

            self.question_textbox = display_textbox(self.window, 7, 45)
            self.question_textbox.place(x=30, y=285, anchor="w")
            self.question_textbox.insert(
                tk.END, self.service.get_question_for_player())
            self.question_textbox.config(state=DISABLED)

            self.show_answer_btn = button(self.window, "Show answer",
                                          self._show_answer)
            self.show_answer_btn.place(x=280, y=420, anchor="center")