Ejemplo n.º 1
0
 def test_mover_e_calcular(self):
     largura = 800  # 800 x 800
     tamQuadrado = largura / 8  # 100
     lin = 1
     col = 2
     p = Peca(lin, col, Cores.amareloClaro, tamQuadrado)
     p.mover(2, 1)  # novo X e Y calculado
     self.assertEqual((p.x, p.y), (150, 250))
     self.assertEqual((p.lin, p.col), (2, 1))
Ejemplo n.º 2
0
    def printEstadoTabuleiro(tab):
        tabsFormat = '\t \t \t \t \t \t \t \t \t  '
        tabsFormatRow = '\t \t \t \t \t \t \t \t \t '

        print tabsFormat, '    0       1       2       3       4       5       6'
        for i in xrange(len(tab)):
            print tabsFormat, '---------------------------------------------------------'
            print tabsFormatRow + str(i), '|', Peca.toStr(tab[i][0]), '|', Peca.toStr(tab[i][1]), '|', Peca.toStr(tab[i][2]), '|', Peca.toStr(tab[i][3]), '|', Peca.toStr(tab[i][4]), '|', Peca.toStr(tab[i][5]), '|', Peca.toStr(tab[i][6]), '|'
        print tabsFormat, '---------------------------------------------------------'
Ejemplo n.º 3
0
def criar_peca(nome, nome_arquivo):
    peca = Peca(nome)
    print(peca.toString() + " foi criado")

    acesso = "./Store/Listas/" + nome_arquivo + ".txt"

    # Aproveitando esse trecho para salvar a string num txt:
    f = open(acesso, "a+")
    f.write(peca.toString() + "\n")
    f.close()
    return peca  #O QUE O USUARIO ENTROU
Ejemplo n.º 4
0
    def __init__(self, director):
        super(Tabuleiro, self).__init__()

        self.director = director
        self.tabuleiro = []
        self.offsetX = 100
        self.offsetY = 100
        lado = 32

        #montagem da matriz inicial
        self.tabMatriz = []
        for i in range(8):
            linha = []
            for j in range(8):
                linha.append(0)
            self.tabMatriz.append(linha)
        self.tabMatriz[3][3] = 1
        self.tabMatriz[3][4] = 2
        self.tabMatriz[4][3] = 2
        self.tabMatriz[4][4] = 1
        ###################################

        #Batch que vai segurar todos os pecas
        self.spriteBatch = BatchNode()
        self.add(self.spriteBatch)

        for i in range(8):
            l = []
            for j in range(8):
                if (self.tabMatriz[i][j] == 0):
                    peca = Peca("vazio.png",
                                (i * lado + lado / 2, j * lado + lado / 2))
                elif (self.tabMatriz[i][j] == 1):
                    peca = Peca("preto.png",
                                (i * lado + lado / 2, j * lado + lado / 2))
                elif (self.tabMatriz[i][j] == 2):
                    peca = Peca("branco.png",
                                (i * lado + lado / 2, j * lado + lado / 2))
                l.append(peca)
                self.spriteBatch.add(peca)
            self.tabuleiro.append(l)

        self.spriteBatch.position = (self.offsetX, self.offsetY)

        self.teste = Sprite("grossini.png", (300, 200))
        self.spriteBatch.add(self.teste)

        self.hud = GameHud()
        self.add(self.hud)

        for i in self.tabMatriz:
            print(i)
Ejemplo n.º 5
0
 def posicionarPeca(self):
     for lin in range(self.conf.linhas):
         self.tabuleiro.append([])
         for col in range(self.conf.colunas):
             if col % 2 == (lin + 1) % 2:
                 if lin < 3:
                     self.tabuleiro[lin].append(
                         Peca(lin, col, self.conf.corPA,
                              self.conf.getTamanhoQuadrado()))
                 elif lin > 4:
                     self.tabuleiro[lin].append(
                         Peca(lin, col, self.conf.corPB,
                              self.conf.getTamanhoQuadrado()))
                 else:
                     self.tabuleiro[lin].append(0)
             else:
                 self.tabuleiro[lin].append(0)
Ejemplo n.º 6
0
 def __init__( self, director, dificuldade ):
     super( GameLayer, self ).__init__()
     
     self.director = director
     self.tabuleiro = []
     self.offsetX = director.get_window_size()[0]/3
     self.offsetY = director.get_window_size()[1]/8
     lado = 45
     self.lado = lado
     self.dificuldade = dificuldade
     
     self.cpu = False
     
     self.prolog = Prolog()
     self.prolog.consult("reversi.pl")
     self.tabMatriz = list(self.prolog.query("novotab(X)"))[0]['X']
     self.matriz = deepcopy(self.tabMatriz)
     
     pyglet.font.add_directory('.')
     self.jogadorAtivo = Label("Jogador: Player1", font_name = 'Blood Of Dracula', font_size = 22,
                              x = 20, y = 350)
     self.add(self.jogadorAtivo)
     self.dif = Label("Dificuldade: " + self.dificuldade, font_name = 'Blood Of Dracula', font_size = 16,
                              x = 20, y = 300)
     self.add(self.dif)
     self.p = list(self.prolog.query("winner(" + str(self.tabMatriz) + ", P0, P1, P2)"))[0]
     self.p1 = Label("P1: " + str(self.p['P1']) + self.dificuldade, font_name = 'Bloodsuckers', font_size = 26,
                              x = 20, y = 200)
     self.p2 = Label("P1: " + str(self.p['P2']) + self.dificuldade, font_name = 'Bloodsuckers', font_size = 26,
                              x = 20, y = 150)
     self.add(self.p1)
     self.add(self.p2)
     
     #Batch que vai segurar todos os pecas
     self.spriteBatch = BatchNode()
     self.add(self.spriteBatch)
     
     size = 8*self.lado
     for i in range(8):
         l = []
         for j in range(8):
             peca = Peca(self.tabMatriz[i][j], (j*lado + lado/2, size - (i*lado + lado/2)))
             l.append(peca)
             self.spriteBatch.add(peca)
         self.tabuleiro.append(l)
         
     self.spriteBatch.add(Sprite("tabuleiro.png", 
                                 (self.tabuleiro[4][4].position[0] - lado/2, self.tabuleiro[4][4].position[1] + lado/2) 
                                 , 0, 1, 32), 0)
     
     self.spriteBatch.position = (self.offsetX, self.offsetY)
     self.spriteBatch.scale = 1.0        
     
     self.hud = GameHud()
     self.add(self.hud)
     
     self.schedule(self.gameLoop)
Ejemplo n.º 7
0
    def printEstadoTabuleiro(tab):
        tabsFormat = '\t \t \t \t \t \t \t \t \t  '
        tabsFormatRow = '\t \t \t \t \t \t \t \t \t '

        print tabsFormat, '    0       1       2       3       4       5       6'
        for i in xrange(len(tab)):
            print tabsFormat, '---------------------------------------------------------'
            print tabsFormatRow + str(i), '|', Peca.toStr(
                tab[i][0]), '|', Peca.toStr(tab[i][1]), '|', Peca.toStr(
                    tab[i][2]), '|', Peca.toStr(tab[i][3]), '|', Peca.toStr(
                        tab[i][4]), '|', Peca.toStr(
                            tab[i][5]), '|', Peca.toStr(tab[i][6]), '|'
        print tabsFormat, '---------------------------------------------------------'
Ejemplo n.º 8
0
class Casa:
    peca = Peca()
    largura = 83
    altura = 83
    Cor = None
    WHITE = 1
    BLACK = 2
    NONE = 0
    valor = 0

    def __init__(self, valor = 0):
        self.valor = valor
        
    def setPeca(self,peca):
        self.peca = peca

    def getPeca(self):
        return self.peca

    def getAltura(self):
        return self.altura

    def getLargura(self):
        return self.largura

    def setCor(self,cor):
        self.Cor = cor

    def getCor(self):
        return self.Cor

    def setValor(self, valor):
        self.valor = valor

    def getValor(self):
        return self.valor
    
    def getValorInverso(self):
        _valor = 0
        if self.valor == self.WHITE:
            _valor = self.BLACK
        elif self.valor == self.BLACK:
            _valor = self.WHITE 
        return _valor
Ejemplo n.º 9
0
 def criarNovaPeca(self):
     self.pecaAtual = Peca()
     self.pecaAtual.gerarPeca()
     self.desenhoPeca.receberPeca(self.pecaAtual)
     self.desenhoPeca.desenharNovaPeca()
     self.desenhoPeca.tocouY = False
Ejemplo n.º 10
0
class GameBehavior(QtGui.QMainWindow, Ui_MainWindow):
    # atributos da classe
    desenhoPeca = None
    pecaAtual = None
    velocidadeQueda = 300  # tempo que leva para a peça se mover(dado em milésimos)
    timer = None

    def __init__(self, parent=None):
        super(GameBehavior, self).__init__(parent)
        self.setupUi(self)
        # cria tela onde vão ser desenhadas as peças
        self.desenhoPeca = DesenhoPeca(self.centralwidget, self.widget.width(), self.widget.height())
        # gera a primeira peca
        self.criarNovaPeca()
        # desenha a peça na tela
        self.desenhoPeca.receberPeca(self.pecaAtual)
        self.widget_2 = self.desenhoPeca

        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.time)
        self.timer.start(self.velocidadeQueda)  # inicia a função time
        tocarMusica(True)
        self.show()

    # funçao que recebe eventos do teclado
    def keyPressEvent(self, event):
        key = event.key()
        if key == QtCore.Qt.Key_Right:  # mover para a direira
            self.desenhoPeca.moverDir()
        if key == QtCore.Qt.Key_Left:  # mover para a esquerda
            self.desenhoPeca.moverEsq()
        if key == QtCore.Qt.Key_Up:  # rotacionar peça ao apertar up
            self.pecaAtual.rotacionar()
        if key == QtCore.Qt.Key_Space:  # faz a peça cair rápido
            self.desenhoPeca.soltarPeca()
        if key == QtCore.Qt.Key_G:
            print("\n")
            self.desenhoPeca.imprimirCampo()

        self.update()  # Atualiza a GUI

    # Responsavel por fazer a peça cair a cada 1s
    def time(self):
        posX = self.desenhoPeca.posX
        posY = self.desenhoPeca.posY
        matriz = self.pecaAtual.getPeca()
        cor = self.desenhoPeca.cor
        # exibe o número de linhas feitas na tela SCORE
        self.score.display(self.desenhoPeca.linhasFeitas)
        # caso a peça toque o limite do campo
        # gera uma nova peca
        if self.desenhoPeca.tocouY:
            # preenche os quadrados do campo
            for i in range(0, 4):
                self.desenhoPeca.postoIndex(posX + (23 * matriz[i][0]), posY + (22 * matriz[i][1]), cor)
            self.criarNovaPeca()
        else:  # trecho responsavel por dectecar a colisão entre peças
            for i in range(0, 4):  # verifica se algum dos quadrados que compoem a peça colidiu
                if self.detectarColisao(posX + (23 * matriz[i][0]), posY + (22 * matriz[i][1])):
                    for i in range(0, 4):  # preenche os quadrados do campo
                        self.desenhoPeca.postoIndex(posX + (23 * matriz[i][0]), posY + (22 * matriz[i][1]), cor)
                    self.criarNovaPeca()
                    break
        if self.terminarPartida():
            print("acabou: seus número de linha foi: %s" % (self.desenhoPeca.linhasFeitas))
            self.timer.stop()
            self.update()
            return 0

        self.desenhoPeca.descerPeca()
        self.update()

    # cria uma nova peça
    def criarNovaPeca(self):
        self.pecaAtual = Peca()
        self.pecaAtual.gerarPeca()
        self.desenhoPeca.receberPeca(self.pecaAtual)
        self.desenhoPeca.desenharNovaPeca()
        self.desenhoPeca.tocouY = False

    # indica se a peça colidiu com outra peça no eixo y.
    def detectarColisao(self, posX, posY):
        temColisao = False
        try:
            if self.desenhoPeca.campo[self.desenhoPeca.posYtoIndex(posY) + 1][self.desenhoPeca.posXtoIndex(posX)] != 0:
                temColisao = True
        except (IndexError):
            temColisao = False
        return temColisao

    def terminarPartida(self):
        terminou = False
        if self.desenhoPeca.campo[0].count(0) != len(self.desenhoPeca.campo[0]):
            terminou = True
        return terminou
Ejemplo n.º 11
0
    def test_definir_posicao(self):
        largura = 800  # 800 x 800
        # sendo tamanho do quadrado 100
        # para a linha 0 e coluna 0, o x e y será 50 ou seja a peça será desenhada
        # a partir do centro do quadrado até o raio definido
        tamQuadrado = largura / 8
        lin = 0
        col = 0
        p = Peca(lin, col, Cores.amareloClaro, tamQuadrado)
        p.converterPosicao()
        self.assertEqual((p.x, p.y), (50, 50))

        lin = 0
        col = 1  # soma 100 no X para a coluna 1 e assim sucessivamente
        p = Peca(lin, col, Cores.amareloClaro, tamQuadrado)
        p.converterPosicao()
        self.assertEqual((p.x, p.y), (150, 50))

        lin = 0
        col = 2  # soma 200
        p = Peca(lin, col, Cores.amareloClaro, tamQuadrado)
        p.converterPosicao()
        self.assertEqual((p.x, p.y), (250, 50))

        # para a linha segue a mesma lógica ocorrendo no Y
        lin = 1  # soma 100 no y
        col = 2  # soma 200 no x
        p = Peca(lin, col, Cores.amareloClaro, tamQuadrado)
        p.converterPosicao()
        self.assertEqual((p.x, p.y), (250, 150))