예제 #1
0
def playGame(settings):
    global scoreKeeper
    global dartCaptureThread
    print "Starting Game"
    game = DartGame(settings)
    AIPlayer = AI.AIOpponent(difficulty)

    scoreKeeper.reset(game)
    updateUI.set()

    dartCaptureThread.setGame(game)
    dartCaptureThread.setAI(AIPlayer)
    dartCaptureThread.status = -1

    while (game.stillPlaying == True):
        ##        Now uses get_dart.GetDart()

        #if a dart has been recorded
        if dartCaptureThread.status == 0:
            # uncomment to get it to print out dart throw
            dartCaptureThread.throwResult.printThrow()
            # check correctScore event

            # Update the score
            if game.gameType == 1:
                #print "====Normal mode===="
                game.updateScoreGame(dartCaptureThread.throwResult)
                if game.currentPlayer.name == "CPU1" or game.currentPlayer.name == "CPU2":
                    time.sleep(ai_throw_wait_time)
            else:
                #print "====Practice mode===="
                game.updateScorePractice(t.throwResult)

            #change this status flag to trigger new dart capture
            if game.stillPlaying == True:
                dartCaptureThread.status = -1

        if uiCommandStream.Event.isSet():
            if uiCommandStream.Command == CMD_RECAL:
                print "Recalibration:"
                #calibration.Calibration()
            elif uiCommandStream.Command == CMD_CORRECT:
                print "Correct the score!"
            elif uiCommandStream.Command == CMD_EXIT:
                print "EXITING"
                dartCaptureThread.status = 1
                print dartCaptureThread.isAlive()
                sys.exit(0)
            elif uiCommandStream.Command == CMD_MISS:
                missedThrow = dartThrow()
                missedThrow.base = 0
                missedThrow.multiplies = 0
                missedThrow.magnitude = 700
                missedThrow.angle = 5.6

                # Update the score
                if game.gameType == 1:
                    #print "====Normal mode===="
                    game.updateScoreGame(missedThrow)
                else:
                    #print "====Practice mode===="
                    game.updateScorePractice(missedThrow)
            else:
                print "Unknown Command"
                print uiCommandStream.Command
            uiCommandStream.clear()

    print "THE WINNER IS " + game.currentPlayer.name