def logOut(self):
     common.net.initializeSession(common.user.token)
     data = common.net.logout(common.user.token)
     if data['code'] != 1:
         err_str = getErrorString(data['code'])
         print err_str
         showContent(err_str)
     common.user.token = ""
     common.user.save()
     global start_botton
     start_botton.__init__()
     gameLayer.remove(self.name)
     gameLayer.add(start_botton, z=50, name=start_botton.name)
    def next_func(self):
        if self.isRegister == False:
            #Login
            data = common.net.login(self.user_name, self.keys_pressed)
            if data['code'] == 1:
                common.user.token = data['token']
                common.user.username = self.user_name
                common.user.save()
            else:
                err_str = getErrorString(data['code'])
                print err_str
                showContent(err_str)
            self.backToPrePreMenu()
        else:
            #Register
            data = common.net.registration(self.user_name, self.keys_pressed)
            if data['code'] != 1:
                err_str = getErrorString(data['code'])
                print err_str
                showContent(err_str)

            self.backToPrePreMenu()
 def showRankList(self):
     data = common.net.getLeaderboard(self.choosed)
     if data['code'] != 1:
         err_str = getErrorString(data['code'])
         print err_str
         showContent(err_str)
     rankList = data['leaderboard']
     # rankList = [{"user_name":"abc", "data":123}, {"user_name":"abcdefghij", "data":123}]
     for i in range(len(rankList)):
         user = rankList[i]
         string = str(i + 1) + " " + user["username"]
         while (len(string) < 13):
             string += " "
         string += "{:<8.2f}".format(user["data"])
         label = createLabel(
             string, common.visibleSize["width"] / 2,
             common.visibleSize["height"] * (80 - i * 6) / 100.0)
         self.add(label)
Exemplo n.º 4
0
    def calScore(dt):
        global g_score, pass_num, time
        time = time + dt
        birdXPosition = spriteBird.position[0]
        for i in range(0, pipeCount):
            if pipeState[
                    i] == PIPE_NEW and pipes[i].position[0] < birdXPosition:
                pipeState[i] = PIPE_PASS
                #update data
                if difficulty == 0:
                    g_score = g_score + 1
                elif difficulty == 1:
                    g_score = g_score + 3
                elif difficulty == 2:
                    g_score = g_score + 5
                pass_num = pass_num + 1
                setSpriteScores(g_score)  #show score on top of screen

                data = common.net.initializeSession(common.user.token)
                if data['code'] != 1:
                    err_str = getErrorString(data['code'])

                common.net.updateData(common.user.token, g_score, time,
                                      pass_num)
def showNotice():
    data = common.net.notice()
    if data['code'] != 1:
        showContent(getErrorString(data['code']))
    else:
        showContent("Notice:" + data['notice'])