예제 #1
0
 def __init__(self):
     while True:
         window.fill((0, 0, 0))
         font = pygame.font.SysFont('Jetbrains Mono', 30)
         text1 = font.render('Press G for generating data.', False,
                             (255, 255, 255))
         text2 = font.render('Press T for training model and predict.',
                             False, (255, 255, 255))
         text3 = font.render(
             'There are ' + str(len(store_actions)) + ' instances.', False,
             (255, 255, 255))
         window.blit(text1, (100, 200))
         window.blit(text2, (100, 300))
         window.blit(text3, (100, 400))
         pygame.display.update()
         for event in pygame.event.get():
             if event.type == QUIT:
                 pygame.quit()
                 quit()
             if event.type == KEYDOWN:
                 if event.key == K_g:
                     main(self, values)
                 if event.key == K_t:
                     x_train = np.array(store_grids)
                     y_train = to_categorical(store_actions)
                     model.fit(x_train,
                               y_train,
                               shuffle=True,
                               epochs=20,
                               verbose=1)
                     cnn_main(self, values)
                 if event.key == K_ESCAPE:
                     pygame.quit()
                     quit()
예제 #2
0
def play(obj):  #results of a play command
    if obj['object'] == 'basketball':  #if command is 'play basketball', attempt to shoot the basketball
        return shoot(obj)
    if state.state[
            'sub_location'] != 'old_man':  #if located at the benches, initiate a game of Tetris
        return
    if obj['object'] == 'GameBoy':
        return "The only game on the gameboy is pong. You play it a bit, but you've got more important things to do."
    score = tetris.main()
    if score and score > 100:  #if the player scores more than 100 points in Tetris, give them clout
        out = '"Congratulations on playing a great game," he says. "Here\'s some clout."'
        out += common_actions.add_to_inventory('clout')
        return out
    else:  #if the player fails to reach 100 points, tell them to try again
        return 'The man shrugs and frowns. "I guess kids these days just don\'t know how to play tetris," he mutters. \nEnter (play) if you wish to try again.'
예제 #3
0
def callback(index):
    """ Just a stub """
    # in pymenu.py, the button index
    # will be passed to the function
    # you add below in addButton()

    # which means you can check
    # for the index like this:
    # if index == 1:
    #  tetris.main()
    if index == 0:
        pygame.display.set_mode((600, 800))
        blocks.main()
    if index == 1:
        pygame.display.set_mode((600, 600))
        invader.main()
    if index == 2:
        tetris.main()
    if index == 3:
        pygame.quit()
        sys.exit()

    # now it just prints the index
    print(index)
예제 #4
0
def jogar(individuos,
          numeroDaGeracao,
          multVel,
          scoreMax=20000,
          jogoRapido=True):

    numInd = len(individuos)

    t.FPS = int(multVel)
    t.main(telaX=120 * ((numInd - 1) % 5) + 220,
           telaY=260 * ((numInd - 1) // 5 + 1),
           boxSize=10)

    board = [t.getBlankBoard() for i in range(len(individuos))]

    score = [0 for i in range(numInd)]

    #   ??? deveria estar dentro de individuo ???
    pecasJogadas = [0 for i in range(numInd)]
    linhasDestruidas = [[0, 0, 0, 0] for i in range(numInd)]  #combos

    vivo = [True for i in range(numInd)]
    ganhou = [False for i in range(numInd)]

    nextPiece = t.getNewPiece()

    while vivo != [False] * numInd:  #game loop
        '''
        #process
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print ("Game exited by user")
                exit()
        '''

        fallingPiece = nextPiece
        nextPiece = t.getNewPiece()

        #decide a melhor jogada baseado no que acha (pesos)
        for i in range(len(individuos)):
            if vivo[i]:
                individuos[i].calcularMelhorJogada(board[i], fallingPiece,
                                                   True)

                if not t.isValidPosition(board[i], fallingPiece):
                    #nao existe possiçao que caiba na tela
                    vivo[i] = False
                else:
                    pecasJogadas[i] += 1
                    score[i] += 1

                    t.addToBoard(board[i], fallingPiece)
                    numLines = t.removeCompleteLines(board[i])
                    if (numLines == 1):
                        score[i] += 40
                        linhasDestruidas[i][0] += 1
                    elif (numLines == 2):
                        score[i] += 120
                        linhasDestruidas[i][1] += 1
                    elif (numLines == 3):
                        score[i] += 300
                        linhasDestruidas[i][2] += 1
                    elif (numLines == 4):
                        score[i] += 1200
                        linhasDestruidas[i][3] += 1

                    #condiçao de parada
                    if score[i] > scoreMax:
                        vivo[i] = False
                        ganhou[i] = True

        #if not jogoRapido:
        desenharNaTela(board, score, 1, nextPiece, fallingPiece,
                       numeroDaGeracao)

    # retorna [numero de pecas, linhas destruidas(combos de 1,2,3,4), score normal de tetris, ganhou]
    gameState = [[pecasJogadas[i], linhasDestruidas[i], score[i], ganhou[i]]
                 for i in range(numInd)]
    return (gameState)
    def Login_Reslute(self):
        try:
            user_dist = {}
            sql_order = "select user_id,password from nc_user"
            get_result = Execute_Sql_Get_Date(sql_order)
            print('365', get_result)

            #从sql得到的东西有很多的空格
            for user in get_result:
                user_id = str(user[0]).replace(' ', '')
                password = str(user[1]).replace(' ', '')

                #print(user_id,password)

                user_dist[user_id] = password

            print(user_dist)

            #print(self.lineEdit.text() in list(user_dist.keys()))

            ##print(user_dist[self.lineEdit.text()])
            #这是一个检测已经注册过的人员,是否可以登录
            if self.lineEdit.text() in list(user_dist.keys()):
                if user_dist[self.lineEdit.text()] == self.lineEdit_2.text():
                    #print('有这个账号')
                    main_window_show.show()
                    main_window_show.move(self.x(), self.y())
                    admin_register_show.close()
                else:
                    self.Message_two('账号或密码错误')

            #没有输入账号也可以自己进行登录
            elif self.lineEdit.text() == '123':

                get_num, get_sum = random_question_register.random_produce_funcation(
                )
                print("得到的数字", get_num, get_sum)

                QMessageBox.question(self, 'dhdfh', 'title', QMessageBox.Yes)

                main_window_show.show()
                admin_register_show.close()

            #一个自己的账号HE
            elif self.lineEdit.text() == 'HE':
                main_window_show.but_admin_info_show.setText('HE')
                admin_register_show.close()
                self.Message_one('登录成功')

            #这是一个俄罗斯方块
            elif self.lineEdit.text() == 'HJWZL':
                main_window_show.but_admin_info_show.setText('补天裂')
                admin_register_show.close()
                tetris.main()

            #这是登录主界面的验证
            elif self.lineEdit.text() == '24680':
                main_window_show.show()
                admin_register_show.close()

            elif self.lineEdit.text() == "888":
                database_set_show.show()
                admin_register_show.close()

                #print("窗口是false,ture",admin_register_show.w)

            #这些是检测导入数据是要输入密码()
            #也就是在有导入功能界面下,输入密码的界面才可以进行显示

            elif serson_computer_register_show.isHidden() == False:
                serson_computer_register_show.to_lend()

            elif machine_lh_contrast_show.isHidden() == False:
                machine_lh_contrast_show.to_lend()

            elif thing_lh_contrast_show.isHidden() == False:
                thing_lh_contrast_show.to_lend()

            elif thing_num_address_show.isHidden() == False:
                thing_num_address_show.to_lend()

            else:
                self.Message_two('没有账号或权限')
                self.lineEdit.setText('')
                self.lineEdit_2.setText('')

        except Exception:
            print_exc()
예제 #6
0
파일: jogo.py 프로젝트: brunoxd13/ag-tetris
def jogar(individuo, multVel, scoreMax = 20000, jogoRapido = False):

    t.FPS = int(multVel)
    t.main()

    board = t.getBlankBoard()
    lastFallTime = time.time()
    score = 0
    
    level, fallFreq = t.calculateLevelAndFallFreq(score)

    fallingPiece = t.getNewPiece()
    nextPiece = t.getNewPiece()
    individuo.calcularMelhorJogada(board, fallingPiece)
    
    pecasJogadas = 0
    linhasDestruidas = [0,0,0,0] #combos
    
    vivo = True
    ganhou = False

    
    while vivo: #game loop
        #process
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print ("Game exited by user")
                exit()
                
        if fallingPiece == None:
            # nenhuma peca caindo, gera uma nova peca
            fallingPiece = nextPiece
            nextPiece = t.getNewPiece()

            #decide a melhor jogada baseado no que acha (pesos)
            individuo.calcularMelhorJogada(board, fallingPiece, jogoRapido)

            pecasJogadas +=1
            score += 1

            lastFallTime = time.time() # reseta lastFallTime

            if not t.isValidPosition(board, fallingPiece):
                #nao existe possiçao que caiba na tela
                vivo = False


        if jogoRapido or time.time() - lastFallTime > fallFreq:

            if not t.isValidPosition(board, fallingPiece, adjY=1):
                # A peca caiu, adiciona ela para o tabuleiro
                t.addToBoard(board, fallingPiece)
                numLines = t.removeCompleteLines(board)
                if(numLines == 1):
                    score += 40
                    linhasDestruidas[0] += 1
                elif (numLines == 2):
                    score += 120
                    linhasDestruidas[1] += 1
                elif (numLines == 3):
                    score += 300
                    linhasDestruidas[2] += 1
                elif (numLines == 4):
                    score += 1200
                    linhasDestruidas[3] += 1

                fallingPiece = None
            else:
                # A peca ainda esta caindo, move ela para baixo
                fallingPiece['y'] += 1
                lastFallTime = time.time()


        if not jogoRapido:
            desenharNaTela(board,score,level,nextPiece, fallingPiece)

        #condiçao de parada
        if score > scoreMax:
            vivo = False
            ganhou = True

    # retorna [numero de pecas, linhas destruidas(combos de 1,2,3,4), score normal de tetris, ganhou]
    gameState = [pecasJogadas, linhasDestruidas ,score, ganhou]
    return(gameState)
예제 #7
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import tetris, sys

# Recebe o nome do Jogador
player = sys.argv[0]

# Inicializa o Client com o Tetris
tetris.main(player)