예제 #1
0
파일: player.py 프로젝트: Cesar947/TA2_IA
class Player(Component):
    def __init__(self, i, x, y, nombre1, nombre2, width=500, height=500):
        Component.__init__(self, x, y, width, height)
        if i == 1:
            self.asset = n_player
        else:
            self.asset = n_ia
        self.i = i
        #options
        self.opt1 = Option(1, x + 80, y + 100)
        self.opt2 = Option(2, x + 80, y + 160)
        self.opcion1 = nombre1
        self.opcion2 = nombre2
        self.opciones_seleccionadas = 0

    def draw_player(self, window):
        window.blit(self.asset, (self.x, self.y))
        if self.opt1.get_selected():
            self.opt2.to_block()
        if self.opt2.get_selected():
            self.opt1.to_block()
        #options
        self.opt1.draw_option(window, self.opcion1)
        self.opt2.draw_option(window, self.opcion2)
        #points
        if self.i == 1:
            global puntos_player
            points = font.render("Puntos: " + str(puntos_player), 1, (0, 0, 0))
        if self.i == 2:
            global puntos_ia
            points = font.render("Puntos: " + str(puntos_ia), 1, (0, 0, 0))
        window.blit(points, (self.x + 60, self.y + 30))

    def select_option(self, pos):
        self.opt1.is_over(pos)
        self.opt2.is_over(pos)

    def click_option(self, pos):
        self.opt1.select(pos)
        self.opt2.select(pos)

    def answer(self, opcion):
        if opcion == 0:
            self.opt1.ia_options()
        elif opcion == 1:
            self.opt2.ia_options()

    def validar_opciones(self):
        if self.opt1.get_selected() == True or self.opt2.get_selected(
        ) == True:
            self.opciones_seleccionadas += 1
        return self.opciones_seleccionadas

    def opcion_elegida(self):
        if self.opt1.get_selected() == True:
            return 0
        elif self.opt2.get_selected() == True:
            return 1

    def sumar_puntos(self):
        if self.i == 1:
            global puntos_player
            puntos_player += 1
        if self.i == 2:
            global puntos_ia
            puntos_ia += 1

    def reset(self):
        self.opt1.deselect()
        self.opt2.deselect()

    def get_puntos(self):
        if self.i == 1:
            global puntos_player
            return puntos_player
        if self.i == 2:
            global puntos_ia
            return puntos_ia
예제 #2
0
class App():
    def __init__(self, window, pipeline, som):
        self.window = window
        self.sbar = SearchBar(70, 140)
        self.tbar = ToolBar(0, 20)
        self.btn = Button(480, 200)
        self.good_option = Option(1, 200, 550)
        self.bad_option = Option(2, 400, 550)
        self.searched = False
        cwd = os.getcwd()
        files = os.listdir(cwd)
        print("Files in %r: %s" % (cwd, files))

        #CREACION DE INSTANCIA SOM
        self.som = som
        self.pipeline = pipeline
        # Pasando el pipeline como parámetro al TweetDetail
        # TweetDetail: Clase en donde se realiza la extracción y muestra del tweet
        self.tweet_detail = TweetDetail(120, 260, self.pipeline, self.som)
        self.tweet_id = ''
        self.clicked_bar = False

    def draw_app(self):
        self.sbar.draw_search_bar(self.window)
        self.tbar.draw_tool_bar(self.window)
        self.btn.draw_button(self.window)
        if self.searched == False:
            self.good_option.draw_option(self.window)
            self.bad_option.draw_option(self.window)
        if self.searched == True:
            self.tweet_detail.draw_tweet(self.window)
            if self.tweet_detail.get_result() == 0:
                self.good_option.change_opacity(self.window)
                self.bad_option.increment(self.window)
            if self.tweet_detail.get_result() == 1:
                self.bad_option.change_opacity(self.window)
                self.good_option.increment(self.window)

    def search(self, pos):
        self.sbar.is_clicked(pos)
        if self.clicked_bar == False:
            self.clicked_bar = True
        elif self.clicked_bar == True:
            self.clicked_bar = False

    def erase_text(self, pos):
        if self.clicked_bar == True:
            self.sbar.erase_text(pos)

    def search_text_write(self, event):
        if self.clicked_bar == True:
            self.sbar.write_search_text(event)

    def search_text_space(self, event):
        self.sbar.space_search_text(event)

    def search_text_paste(self):
        self.sbar.paste_search_text()

    def over_button(self, pos):
        self.btn.is_over(pos)

    def click_button(self, pos):
        if self.sbar.get_text() != '':
            self.btn.is_over(pos)
            self.tweet_id = self.sbar.get_tweet_id()
            self.tweet_detail.get_tweet(self.tweet_id)
            self.searched = True