def draw_menu(self, current_button):
        self.window.clear()
        curses.resize_term(49, 165)

        width = 50
        height = 4
        start_y, start_x = 17, 55
        gap = 1
        for index, button in enumerate(buttons):
            # draw button
            if current_button == index + 1:
                cur_btn = rectangle.Rectangle(self.window,
                                              init_content=button,
                                              top_row=True,
                                              top_sym="X")
                cur_btn.draw_rectangle(
                    (height * index) + gap + start_y, 0 + start_x,
                    (height * (index + gap)) + start_y, width + start_x)
            else:
                cur_btn = rectangle.Rectangle(self.window, init_content=button)
                cur_btn.draw_rectangle(
                    (height * index) + gap + start_y, 0 + start_x,
                    (height * (index + gap)) + start_y, width + start_x, False)

        self.window.refresh()
 def draw_score_board(self, top_sym="SCORE BOARD"):
     border = component.Rectangle(self.window,
                                  top_row=True,
                                  top_sym=top_sym)
     border.draw_rectangle(0, 0, self.ncols, self.nlines, False)
     self.show_scores()
     self.window.refresh()
Esempio n. 3
0
    def draw_menu():

        curses.resize_term(49, 165)
        stdscr.clear()
        curses.curs_set(0)

        # draw logo
        curses.init_pair(1, curses.COLOR_YELLOW, 0)
        stdscr.attron(curses.color_pair(1))
        with open("./assets/ASCII_Art/logo1.txt", "r") as logo:
            logo_text = logo.readlines()
            for row in range(1, len(logo_text) + 1):
                stdscr.addstr(row + i, 52, logo_text[row - 1])
        stdscr.refresh()
        stdscr.attroff(curses.color_pair(1))

        width = 50
        height = 4
        start_y, start_x = 19, 55
        gap = 1

        # draw button, using rectangle class from Component -> low level component
        for index, button in enumerate(buttons):
            if current_button == index + 1:
                cur_btn = rectangle.Rectangle(stdscr,
                                              init_content=button,
                                              top_row=True,
                                              top_sym="X")
                cur_btn.draw_rectangle(
                    (height * index) + gap + start_y, 0 + start_x,
                    (height * (index + gap)) + start_y, width + start_x)
            else:
                cur_btn = rectangle.Rectangle(stdscr, init_content=button)
                cur_btn.draw_rectangle(
                    (height * index) + gap + start_y, 0 + start_x,
                    (height * (index + gap)) + start_y, width + start_x, False)

        stdscr.addstr(36, 60, "Press W S to control, Enter to choose")
        stdscr.refresh()
    def draw_column(self, up_left_y, up_left_x, low_right_y, low_right_x,
                    col_index):
        import json
        with open('./assets/data/config.json', 'r') as f:
            data = json.load(f)
            if data[0] == "YELLOW":
                color = curses.COLOR_YELLOW
            elif data[0] == "GREEN":
                color = curses.COLOR_GREEN
            elif data[0] == "RED":
                color = curses.COLOR_RED
            else:
                color = curses.COLOR_YELLOW

        self.args = up_left_y, up_left_x, low_right_y, low_right_x, col_index
        for row in range(self.row_size):
            if not row:
                current_row = component.Rectangle(self.window,
                                                  top_row=True,
                                                  top_sym=col_index,
                                                  color=color)
                current_row.draw_rectangle(
                    up_left_y + (self.box_size * row),
                    up_left_x,
                    low_right_y + (self.box_size * row),
                    low_right_x + self.box_size,
                )
                self.game_board_list.append(current_row)
            else:
                current_row = component.Rectangle(self.window, color=color)
                current_row.draw_rectangle(
                    up_left_y + (self.box_size * row),
                    up_left_x,
                    low_right_y + (self.box_size * row),
                    low_right_x + self.box_size,
                )
                self.game_board_list.append(current_row)
    def main(self):

        import GUI.Game_Logic.game_logic as log
        logic = log.GameLogic()
        logic.reset_data(self.game_mode)

        import threading
        if self.status == "O":
            text = "win"
        elif self.status == "X":
            text = "lose"
        elif self.status == "draw":
            text = "draw"
        threading.Thread(target=self.play_background,
                         args=[text], daemon=True).start()

        # draw win/lose/draw logo
        curses.init_pair(1, curses.COLOR_YELLOW, 0)
        self.window.attron(curses.color_pair(1))
        with open(f"./assets/ASCII_Art/{text}.txt", "r") as logo:
            text = logo.readlines()
            for row in range(1, len(text)+1):
                self.window.addstr(row+3, 35, text[row-1])
        self.window.refresh()
        self.window.attroff(curses.color_pair(1))

        # score
        size = self.game_mode.split(":")
        hori_size = size[0]
        verti_size = size[1]
        if self.status == "O":  # win
            score = ((int(hori_size) * int(verti_size)) -
                     self.total_attempt) * 100
            # print total attempt for win
            if self.total_attempt > 15:
                string = "You can do better"
            elif self.total_attempt >= 10 and self.total_attempt <= 15:
                string = "Not too bad"
            elif self.total_attempt < 10:
                string = "You have the talent!"
        elif self.status == "X":  # lose
            score = self.total_attempt * 100
            # print total attempt for lose
            if self.total_attempt > 15:
                string = "You can do better"
            elif self.total_attempt >= 10 and self.total_attempt <= 15:
                string = "Not too bad, try harder"
            elif self.total_attempt < 10:
                string = "You have no talent :c!"
        else:  # draw (not drawing, draw XD)
            score = self.total_attempt * 150
            # print total attempt
            string = "Not too bad, try harder"

        self.window.addstr(11+3, 36, f"Your score: {score}")
        self.window.addstr(
            8+3, 36, f"Your total attempt: {self.total_attempt}")
        self.window.addstr(9 + 3, 36, string)
        self.window.border()
        self.window.refresh()

        # input player name
        name = rectangle.Rectangle(
            self.window, top_row=True, top_sym="Your Name(Only alphabet)")
        name.draw_rectangle(18, 25, 22, 68)

        # player name input
        alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
        upper_alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
                       'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
        # 65-90
        key_int = [x for x in range(97, len(alpha)+98)]
        key_upper_int = [i for i in range(65, 91)]
        while True:
            key = self.window.getch()
            # lower alphabet
            if key in key_int:
                name.content += str(alpha[key_int.index(key)])
                name.refresh_rectangle()
            # uppercase
            if key in key_upper_int:
                name.content += str(upper_alpha[key_upper_int.index(key)])
                name.refresh_rectangle()
            # backspace
            if key == 8:
                orig_content = name.content
                content_list = [word for word in orig_content]
                content_list = content_list[:-1]
                content = str()
                for word in content_list:
                    content += word
                name.content = " "*len(orig_content)
                name.refresh_rectangle()
                name.content = content
                name.refresh_rectangle()

            # enter
            if key == curses.KEY_ENTER or key in [10, 13]:
                name_list = [word for word in name.content]
                if name_list[1] in alpha or name_list[1] in upper_alpha:
                    self.save_score(name.content, score)
                    self.distrup_music()
                    self.window.clear()
                    self.window.refresh()
                    # return to menu page
                    os.system('python app.py')
                    sys.exit(0)
                    break
                else:
                    self.window.addstr(23, 32, "Player name can't be empty")
                    self.window.refresh()
Esempio n. 6
0
        def draw_options(current_button, current_music, current_color):
            self.window.addstr(
                13, 60, "Press W A S D to control, ENTER to preview music.")

            if current_button == 1:
                # button change animation------------------------------------
                '''
                 < a >
                arrow move to
                <  a  >
                and move back to
                 < a >
                '''
                music = rectangle.Rectangle(
                    self.window, top_row=True, top_sym=buttons[0])
                music.content = music_list[current_music - 1]
                music.draw_rectangle(15, 43, 20, 118)
                self.window.addstr(18, 39, "<")
                self.window.addstr(18, 122, ">")
                self.window.addstr(28, 39, " ")
                self.window.addstr(28, 122, " ")

                color = rectangle.Rectangle(
                    self.window, top_row=True, top_sym=buttons[1])
                color.content = color_list[current_color-1]
                color.draw_rectangle(25, 43, 30, 118, False)
                self.window.addstr(18, 41, " ")
                self.window.addstr(18, 120, " ")
                self.window.addstr(28, 41, "<")
                self.window.addstr(28, 120, ">")

                save = rectangle.Rectangle(self.window)
                save.content = buttons[2]
                save.draw_rectangle(33, 74, 37, 86, False)

            elif current_button == 2:
                color = rectangle.Rectangle(
                    self.window, top_row=True, top_sym=buttons[1])
                color.content = color_list[current_color-1]
                color.draw_rectangle(25, 43, 30, 118)
                self.window.addstr(18, 41, "<")
                self.window.addstr(18, 120, ">")
                self.window.addstr(28, 41, " ")
                self.window.addstr(28, 120, " ")

                music = rectangle.Rectangle(
                    self.window, top_row=True, top_sym=buttons[0])
                music.content = music_list[current_music - 1]
                music.draw_rectangle(15, 43, 20, 118, False)
                self.window.addstr(18, 39, " ")
                self.window.addstr(18, 122, " ")
                self.window.addstr(28, 39, "<")
                self.window.addstr(28, 122, ">")

                save = rectangle.Rectangle(self.window)
                save.content = buttons[2]
                save.draw_rectangle(33, 74, 37, 86, False)

            elif current_button == 3:
                save = rectangle.Rectangle(
                    self.window, top_row=True, top_sym="X")
                save.content = buttons[2]
                save.draw_rectangle(33, 74, 37, 86)

                color = rectangle.Rectangle(
                    self.window, top_row=True, top_sym=buttons[1])
                color.content = color_list[current_color-1]
                color.draw_rectangle(25, 43, 30, 118, False)

                music = rectangle.Rectangle(
                    self.window, top_row=True, top_sym=buttons[0])
                music.content = music_list[current_music - 1]
                music.draw_rectangle(15, 43, 20, 118, False)

                self.window.addstr(18, 41, "<")
                self.window.addstr(18, 120, ">")
                self.window.addstr(28, 41, "<")
                self.window.addstr(28, 120, ">")

                self.window.addstr(18, 39, " ")
                self.window.addstr(18, 122, " ")
                self.window.addstr(28, 39, " ")
                self.window.addstr(28, 122, " ")

            self.window.refresh()