Example #1
0
class Final:

    def __init__(self):

        self.backGround = Object("src/Fases/Final/fundo.png")

        self.NextCurrentState = "Quit"
        self.updateState = False
        self.effect =0

        pass

    def draw(self,tela):
        self.backGround.draw(tela)
        pass

    def event(self,event):
        if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
            self.updateState = True

        pass

    def update(self,dt):
        pass

    pass
Example #2
0
    def __init__(self):
        Object.__init__(self)
        ABC.__init__(self)
        self.model_output_folder = f"outputs/weights/{self.config.run_id}"
        self.result_output_folder = f"outputs/results/{self.config.run_id}"

        if self.config.save_best_model and not os.path.exists(
                self.model_output_folder):
            os.mkdir(self.model_output_folder)
        if self.config.save_results and not os.path.exists(
                self.result_output_folder):
            os.mkdir(self.result_output_folder)

        self.model: Optional[Union[Type[Model], nn.DataParallel]] = None
        self.optimizer: Optional[Type[Optimizer]] = None

        self.logger.info(f"Loading data mapping...")
        manifest_file = f"{self.config.data_lookup}"
        self.mapping: Mapping = Mapping(mapping_path=manifest_file)

        self.logger.info(f"Building label encoder...")
        labels = list(map(lambda x: x.label, self.mapping))
        self.label_encoder = LabelEncoder()
        self.label_encoder.fit(labels)
        self.logger.info(
            f"Created encoder with classes: {self.label_encoder.classes_}.")
Example #3
0
    def __init__(self):
        Object.__init__(self)
        ABC.__init__(self)

        self.dataset: Optional[Dataset] = Dataset(self.config.dataset_path)
        self.model: Optional[Union[Model, DataParallel]] = self.build_model()
        self.optimizer: Optional[Optimizer] = Engine.build_optimizer(
            **self.build_optimizer_params())
        self.lr_scheduler: Optional[
            lr_scheduler._LRScheduler] = self.build_lr_scheduler()
Example #4
0
    def __init__(self, mapping: List[ImageRecord] = None, mapping_path: str = None):
        Object.__init__(self)
        Iterable.__init__(self)

        assert mapping is not None or mapping_path is not None, \
            "Must provide either a list of ImageRecord objects or a mapping path where such list can " \
            "be constructed from."

        self.mapping: List[ImageRecord] = mapping or self._load_mapping(mapping_path)
        self.iter_idx = 0
Example #5
0
    def __init__(self):



        #Carregando o vetor da fase pelo construtor

        self.backGround = Object("src/Fases/Fase1/fundo.png")

        self.MainObjects = [ObjectEvent((925,100), "src/Fases/Botoes/btnSetaDireita.png",
                                    "src/Fases/Botoes/btnSetaDireita_move.png",
                                    "src/Fases/Botoes/btnSetaDireita_click.png",self.next),
                            ObjectEvent((870,15),"src/Fases/Botoes/btnAjuda.png",
                                    "src/Fases/Botoes/btnAjuda_move.png",
                                    "src/Fases/Botoes/btnAjuda_click.png",self.help),
                            ObjectEvent((955,15),"src/Fases/Botoes/btnSair.png",
                                    "src/Fases/Botoes/btnSair_move.png",
                                    "src/Fases/Botoes/btnSair_click.png",self.out)]


        #========Vassoura
        self.vas = Vassoura("Fase1")
        
        self.balance = Balance(True)
        
        self.ficha = Fichas("Fase1", self.vas)
        
        self.NextCurrentState = "Fase3"
        self.updateState = False

        pass
Example #6
0
    def __init__(self):



        self.forms = Form((490,233),195,fontsize=15,bg=(255,255,255),hlcolor=((90,40,40)),maxlines=1)
        self.forms.CURSOR = False

        #Carregando o vetor da fase pelo construtor
        self.backGround = Object("src/Fases/Main/fundo.png")

        self.MainObjects = [ObjectEvent((21,500), "src/Fases/Main/btnSair.png",
                                    "src/Fases/Main/btnSair_move.png",
                                    "src/Fases/Main/btnSair_click.png",self.out),
                            ObjectEvent((875,470),"src/Fases/Main/btnJogar.png",
                                    "src/Fases/Main/btnJogar_move.png",
                                    "src/Fases/Main/btnJogar_click.png",self.next),
                            ObjectEvent((320,376),"src/Fases/Main/btnEscolaPublica.png",
                                    "src/Fases/Main/btnEscolaPublica_click.png",
                                    "src/Fases/Main/btnEscolaPublica_click.png",self.escolaPublica),
                            ObjectEvent((520,376),"src/Fases/Main/btnEscolaParticular.png",
                                    "src/Fases/Main/btnEscolaParticular_click.png",
                                    "src/Fases/Main/btnEscolaParticular_click.png",self.escolaParticular)]


        self.NextCurrentState = "Fase1"
        self.updateState = False
        self.effect = 0

        pass
Example #7
0
    def __init__(self):
        self.backGround = Object("src/Fases/Intro/fundo.png")

        self.NextCurrentState = "MainState"
        self.updateState = False
        self.effect =2
        pass
Example #8
0
    def __init__(self, num_nodes: int, num_relations: int,
                 triplets: np.ndarray):
        Object.__init__(self)
        DGLGraph.__init__(self)

        assert triplets.shape[0] == 3
        src, rel, dst = triplets

        self.add_nodes(num_nodes)
        self.add_edges(src, dst)

        self.set_n_initializer(zero_initializer)
        self.set_e_initializer(zero_initializer)

        self.logger.info(
            f"Constructed graph with {num_nodes} nodes and {num_relations} relation types."
        )
Example #9
0
    def __init__(self):

        self.backGround = Object("src/Fases/Final/fundo.png")

        self.NextCurrentState = "Quit"
        self.updateState = False
        self.effect =0

        pass
Example #10
0
class IntroState(GameState):

    def __init__(self):
        self.backGround = Object("src/Fases/Intro/fundo.png")

        self.NextCurrentState = "MainState"
        self.updateState = False
        self.effect =2
        pass

    def draw(self,tela):
        self.backGround.draw(tela)
        pass

    def event (self,event):
        if event.type == pygame.MOUSEBUTTONUP or event.type == pygame.MOUSEBUTTONDOWN:
            self.updateState = True



    def update(self,dt):
        pass
Example #11
0
    def __init__(self):

        #Carregando o vetor da fase pelo construtor

        self.backGround = Object("src/Fases/Fase8/fundo.png")


        self.StateTemp = ["Fase8","Fase10","Fase6"]
        self.NextCurrentState = self.StateTemp[0]
        self.updateState = False
        self.effect = 0

        self.MainObjects = [ObjectEvent((925,100), "src/Fases/Botoes/btnSetaDireita.png",
                                    "src/Fases/Botoes/btnSetaDireita_move.png",
                                    "src/Fases/Botoes/btnSetaDireita_click.png",self.next),
                            ObjectEvent((15,100), "src/Fases/Botoes/btnSetaEsquerda.png",
                                    "src/Fases/Botoes/btnSetaEsquerda_move.png",
                                    "src/Fases/Botoes/btnSetaEsquerda_click.png",self.back),
                            ObjectEvent((870,15),"src/Fases/Botoes/btnAjuda.png",
                                    "src/Fases/Botoes/btnAjuda_move.png",
                                    "src/Fases/Botoes/btnAjuda_click.png",self.help),
                            ObjectEvent((955,15),"src/Fases/Botoes/btnSair.png",
                                    "src/Fases/Botoes/btnSair_move.png",
                                    "src/Fases/Botoes/btnSair_click.png",self.out)]


        #========Vassoura
        self.vas = Vassoura("Fase8")

        self.balance = Balance(True)

        self.ficha = Fichas("Fase8", self.vas)
        self.ficha.eixosLeft,self.ficha.eixosRight = self.balance.setRight(self.ficha.eixosLeft,self.ficha.eixosRight)

        self.base = ObjectEvent((self.vas.vas.rect.x + 43*(self.vas.vas.image.get_width()/53)
                                 ,self.vas.vas.image.get_height()/2+self.vas.vas.rect.y-15)
                                ,"src/Fases/Vassoura/prego.png",None,None)

        pass
Example #12
0
    def __init__(self):

        #Carregando o vetor da fase pelo construtor

        self.backGround = Object("src/Fases/Fase4/fundo.png")

        self.StateTemp = ["Fase4","Fase6","Fase3"]
        self.NextCurrentState = self.StateTemp[1]
        self.updateState = False
        self.effect = 0


        self.base = [ObjectEvent((740,350),"src/Fases/Vassoura/base.png",None,None,self.base),
                     ObjectEvent((700,300),"src/Fases/Vassoura/prego.png",None,None,self.prego)]

        self.MainObjects = [ObjectEvent((925,100), "src/Fases/Botoes/btnSetaDireita.png",
                                    "src/Fases/Botoes/btnSetaDireita_move.png",
                                    "src/Fases/Botoes/btnSetaDireita_click.png",self.next),
                            ObjectEvent((15,100), "src/Fases/Botoes/btnSetaEsquerda.png",
                                    "src/Fases/Botoes/btnSetaEsquerda_move.png",
                                    "src/Fases/Botoes/btnSetaEsquerda_click.png",self.back),
                            ObjectEvent((870,15),"src/Fases/Botoes/btnAjuda.png",
                                    "src/Fases/Botoes/btnAjuda_move.png",
                                    "src/Fases/Botoes/btnAjuda_click.png",self.help),
                            ObjectEvent((955,15),"src/Fases/Botoes/btnSair.png",
                                    "src/Fases/Botoes/btnSair_move.png",
                                    "src/Fases/Botoes/btnSair_click.png",self.out)]


        #========Vassoura
        self.vas = Vassoura("Fase4")
        
        self.balance = Balance(False)

        self.ficha = Fichas("Fase4",self.vas,self.MainObjects)

        pass
Example #13
0
class Fase8(GameState):


    def out (self):
        self.updateState = True
        self.NextCurrentState = "Quit"

    def back (self):
        self.updateState = True
        self.NextCurrentState = self.StateTemp[2]
        self.effect =1

    def next(self):
        self.updateState = True
        self.effect = 0
        pass

    def help (self):
        print "Help"
        pass

    def __init__(self):

        #Carregando o vetor da fase pelo construtor

        self.backGround = Object("src/Fases/Fase8/fundo.png")


        self.StateTemp = ["Fase8","Fase10","Fase6"]
        self.NextCurrentState = self.StateTemp[0]
        self.updateState = False
        self.effect = 0

        self.MainObjects = [ObjectEvent((925,100), "src/Fases/Botoes/btnSetaDireita.png",
                                    "src/Fases/Botoes/btnSetaDireita_move.png",
                                    "src/Fases/Botoes/btnSetaDireita_click.png",self.next),
                            ObjectEvent((15,100), "src/Fases/Botoes/btnSetaEsquerda.png",
                                    "src/Fases/Botoes/btnSetaEsquerda_move.png",
                                    "src/Fases/Botoes/btnSetaEsquerda_click.png",self.back),
                            ObjectEvent((870,15),"src/Fases/Botoes/btnAjuda.png",
                                    "src/Fases/Botoes/btnAjuda_move.png",
                                    "src/Fases/Botoes/btnAjuda_click.png",self.help),
                            ObjectEvent((955,15),"src/Fases/Botoes/btnSair.png",
                                    "src/Fases/Botoes/btnSair_move.png",
                                    "src/Fases/Botoes/btnSair_click.png",self.out)]


        #========Vassoura
        self.vas = Vassoura("Fase8")

        self.balance = Balance(True)

        self.ficha = Fichas("Fase8", self.vas)
        self.ficha.eixosLeft,self.ficha.eixosRight = self.balance.setRight(self.ficha.eixosLeft,self.ficha.eixosRight)

        self.base = ObjectEvent((self.vas.vas.rect.x + 43*(self.vas.vas.image.get_width()/53)
                                 ,self.vas.vas.image.get_height()/2+self.vas.vas.rect.y-15)
                                ,"src/Fases/Vassoura/prego.png",None,None)

        pass


    def draw(self,tela):

        #Pintando o vetor da fase
        self.backGround.draw(tela)
        DrawVector(self.MainObjects,tela)


        #==========================VASSOURA===============================

        self.vas.draw(tela)

        self.balance.draw(tela, self.ficha.eixosLeft, self.ficha.eixosRight)
        
        self.ficha.draw(tela)
        
        pass

    def event (self,event):

        self.ficha.event(event)

        if event.type == pygame.MOUSEMOTION:
            for q in self.MainObjects:
                q.update(pygame.mouse.get_pos())

        if event.type == pygame.MOUSEBUTTONDOWN:

            for q in self.MainObjects:
                q.clickStart(pygame.mouse.get_pos())

        if event.type == pygame.MOUSEBUTTONUP:
            for q in self.MainObjects:
                if q.clickEnd(pygame.mouse.get_pos()):
                    return
                pass
            pass


    def update(self,dt):

        self.ficha.update(dt)
        self.vas.update(self.ficha.speed,self.ficha.resultWeigth,dt)

        pass
Example #14
0
class Fase4(GameState):

    def out (self):
        self.updateState = True
        self.NextCurrentState = "Quit"

    def back (self):
        self.updateState = True
        self.NextCurrentState = self.StateTemp[2]
        self.effect =1

    def next(self):
        self.updateState = True
        self.effect = 0
        pass

    def help (self):
        print "Help"
        pass

    def base (self):
        pass

    def prego (self):
        pass

    def __init__(self):

        #Carregando o vetor da fase pelo construtor

        self.backGround = Object("src/Fases/Fase4/fundo.png")

        self.StateTemp = ["Fase4","Fase6","Fase3"]
        self.NextCurrentState = self.StateTemp[1]
        self.updateState = False
        self.effect = 0


        self.base = [ObjectEvent((740,350),"src/Fases/Vassoura/base.png",None,None,self.base),
                     ObjectEvent((700,300),"src/Fases/Vassoura/prego.png",None,None,self.prego)]

        self.MainObjects = [ObjectEvent((925,100), "src/Fases/Botoes/btnSetaDireita.png",
                                    "src/Fases/Botoes/btnSetaDireita_move.png",
                                    "src/Fases/Botoes/btnSetaDireita_click.png",self.next),
                            ObjectEvent((15,100), "src/Fases/Botoes/btnSetaEsquerda.png",
                                    "src/Fases/Botoes/btnSetaEsquerda_move.png",
                                    "src/Fases/Botoes/btnSetaEsquerda_click.png",self.back),
                            ObjectEvent((870,15),"src/Fases/Botoes/btnAjuda.png",
                                    "src/Fases/Botoes/btnAjuda_move.png",
                                    "src/Fases/Botoes/btnAjuda_click.png",self.help),
                            ObjectEvent((955,15),"src/Fases/Botoes/btnSair.png",
                                    "src/Fases/Botoes/btnSair_move.png",
                                    "src/Fases/Botoes/btnSair_click.png",self.out)]


        #========Vassoura
        self.vas = Vassoura("Fase4")
        
        self.balance = Balance(False)

        self.ficha = Fichas("Fase4",self.vas,self.MainObjects)

        pass

    def draw(self,tela):

        #Pintando o vetor da fase
        self.backGround.draw(tela)

        self.base[0].draw(tela)

        self.vas.draw(tela)

        DrawVector(self.MainObjects,tela)

        self.base[1].draw(tela)

        self.ficha.draw(tela)
       
        self.balance.draw(tela, self.ficha.eixosLeft,self.ficha.eixosRight)           


        pass

    def event (self,event):

        self.ficha.event(event)
        self.vas.event(event)

        if event.type == pygame.MOUSEMOTION:
            for q in self.MainObjects:
                q.update(pygame.mouse.get_pos())

        if event.type == pygame.MOUSEBUTTONDOWN:
            for base in self.base:
                base.clickStart(pygame.mouse.get_pos())
            for q in self.MainObjects:
                q.clickStart(pygame.mouse.get_pos())

        if event.type == pygame.MOUSEBUTTONUP:
            for base in self.base:
                base.clickEnd(pygame.mouse.get_pos())
            for q in self.MainObjects:
                if q.clickEnd(pygame.mouse.get_pos()):
                    return
                pass
            pass


    def update(self,dt):

        self.ficha.update(dt,self.vas.vas)
        self.vas.update(self.ficha.speed,self.ficha.resultWeigth,dt)
        
        
        #Base da Vassoura
        
        if self.base[1].state == "Clicking" and not self.vas.vas.state == "Clicking ":
            x,y = pygame.mouse.get_pos()
            self.base[1].rect.x , self.base[1].rect.y = x - self.base[1].rect.width/2, y - self.base[1].rect.height/2
        if self.base[0].state == "Clicking" and not self.vas.vas.state == "Clicking" and not self.base[1].state == "Clicking":
            x,y = pygame.mouse.get_pos()
            self.base[0].rect.x  = x - self.base[0].rect.width/2
        pass
        
        
        #Vassoura
        
        if self.vas.vas.state == "Clicking" and not self.base[1].state == "Clicking":
            x,y = pygame.mouse.get_pos()
            self.vas.vas.rect.x , self.vas.vas.rect.y = x - self.vas.vas.rect.width/2, y -self.vas.vas.rect.height/2
            

        if self.vas.vas.state == "Idle":
            
            loop = True
            while loop:
                if self.vas.vas.rect.y <= 160: 
                    self.vas.vas.rect.y +=1
                else: loop = False    
                
            if self.vas.vas.rect.x < 0 :
                self.vas.vas.rect.x = 0
            elif self.vas.vas.rect.x+self.vas.vas.image.get_width() > 1024:
                self.vas.vas.rect.x = 1024-self.vas.vas.image.get_width()


    
    
        # Balance 
        if self.base[1].state == "Idle" and self.vas.vas.state == "Idle":
            if self.base[1].rect.colliderect(self.vas.vas.rect):
                
                if self.base[1].rect.x < self.vas.vas.rect.x+216:
                    self.base[1].rect.x = self.vas.vas.rect.x + 9*(self.vas.vas.image.get_width()/53)
                    #self.ficha.eixosLeft,self.ficha.eixosRight = self.balance.setLeft()
                    pass
                
                if self.base[1].rect.x >= self.vas.vas.rect.x+216 and self.base[1].rect.x <= self.vas.vas.rect.x+578:
                    self.base[1].rect.x = self.vas.vas.rect.x + self.vas.vas.image.get_width()/2-self.base[1].image.get_width()/2
                    #self.ficha.eixosLeft,self.ficha.eixosRight = self.balance.setCenter()
                    pass
                
                if self.base[1].rect.x >self.vas.vas.rect.x+ 578:
                    self.base[1].rect.x = self.vas.vas.rect.x + 43*(self.vas.vas.image.get_width()/53)
                    #self.ficha.eixosLeft,self.ficha.eixosRight = self.balance.setRight()
                    pass
                
                self.base[1].rect.y = self.vas.vas.image.get_height()/2+self.vas.vas.rect.y-self.base[1].image.get_height()/2                
                pass
Example #15
0
class MainState(GameState):


    def next(self):
        self.updateState = True
        self.NextCurrentState = "Fase1"
        self.effect =2

    def out (self):
        self.updateState = True
        self.NextCurrentState = "Quit"

    def escolaParticular(self):
        self.MainObjects[3].idle = self.MainObjects[3].click
        self.MainObjects[2].idle = self.MainObjects[2].oldIdle
        pass

    def escolaPublica (self):
        self.MainObjects[2].idle = self.MainObjects[2].click
        self.MainObjects[3].idle = self.MainObjects[3].oldIdle
        pass

    def __init__(self):



        self.forms = Form((490,233),195,fontsize=15,bg=(255,255,255),hlcolor=((90,40,40)),maxlines=1)
        self.forms.CURSOR = False

        #Carregando o vetor da fase pelo construtor
        self.backGround = Object("src/Fases/Main/fundo.png")

        self.MainObjects = [ObjectEvent((21,500), "src/Fases/Main/btnSair.png",
                                    "src/Fases/Main/btnSair_move.png",
                                    "src/Fases/Main/btnSair_click.png",self.out),
                            ObjectEvent((875,470),"src/Fases/Main/btnJogar.png",
                                    "src/Fases/Main/btnJogar_move.png",
                                    "src/Fases/Main/btnJogar_click.png",self.next),
                            ObjectEvent((320,376),"src/Fases/Main/btnEscolaPublica.png",
                                    "src/Fases/Main/btnEscolaPublica_click.png",
                                    "src/Fases/Main/btnEscolaPublica_click.png",self.escolaPublica),
                            ObjectEvent((520,376),"src/Fases/Main/btnEscolaParticular.png",
                                    "src/Fases/Main/btnEscolaParticular_click.png",
                                    "src/Fases/Main/btnEscolaParticular_click.png",self.escolaParticular)]


        self.NextCurrentState = "Fase1"
        self.updateState = False
        self.effect = 0

        pass


    def draw(self,tela):

        #Pintando o vetor da fase
        self.backGround.draw(tela)
        DrawVector(self.MainObjects,tela)

        self.forms.show()

        pass


    def event (self,event):

        #self.forms.wakeup(event)

        if event.type == pygame.MOUSEMOTION:
            for q in self.MainObjects:
                q.update(pygame.mouse.get_pos())

        if event.type == pygame.MOUSEBUTTONDOWN:
            for q in self.MainObjects:
                q.clickStart(pygame.mouse.get_pos())

        if event.type == pygame.MOUSEBUTTONUP:
            for q in self.MainObjects:
                if q.clickEnd(pygame.mouse.get_pos()):
                    return



    def update(self,dt):
        pass

    pass
Example #16
0
 def __init__(self):
     Object.__init__(self)
     nn.Module.__init__(self)
     ABC.__init__(self)