Ejemplo n.º 1
0
def end():
    (usr, grp, game) = mg.getObjs( request.cookies.get('usrID') )

    if mg.isSupervisor(usr):   
        usr.setGameID(-1)
        return make_response() 

    #print 'POST end %d' %(usr.getUsrID())
    game.writeRes()
    return jsonify( result=game.getResult( grp.getGrpID() ) )
Ejemplo n.º 2
0
def restart():
    usr = mg.getUsr( request.cookies.get('usrID') )  
    if mg.isSupervisor( usr ):
        return jsonify(success=1)

    usrID = usr.getUsrID()
    mg.killGame( usrID )

    #print 'POST RESTART %d' %(int(usrID))
    side_char = request.form.get('side')
    side = 0            #- if side_char == 'A': side = 0 -#
    if side_char == 'B':
        side = 1

    mg.takeSpace( usrID, side )
    return jsonify(success=1)
Ejemplo n.º 3
0
def wait():    #- used by recvAns() from teammate and enemies -#

    usr  = mg.getUsr( request.cookies.get('usrID') )
    game = mg.getGame( usr.getGameID() )
    UID  = int(usr.getUsrID())
    #print 'GET wait %d' %(usr.getUsrID())

    (ctrlUID, ctrlGID) = game.getCtrl()
    if not(game.allChanged) or ctrlUID == -1 or ctrlGID == -1:
        return make_response()

    ctrlGrp       = mg.getGrp(ctrlGID)
    (imgs, boxes) = ctrlGrp.getAns()

    isEnemy = int( usr.isEnemyWith( mg.getUsr(ctrlUID) ) )

    img = ''
    box = ''
    half = 0
    if len(boxes) > 0:
        img  = imgs[0]
        box  = boxes[0]
        half = 1

    moveN    = ctrlGrp.getMoveN()
    correctN = ctrlGrp.getCorrectN()

    if   ctrlGrp.isGiveUp():
        if not isEnemy:
            img = ''
            box = ''
        return jsonify( giveup=1, half=half, img=img, box=box, moveN=moveN, isEnemy=isEnemy, side=ctrlGrp.getSide() )

    elif ctrlGrp.isFullAns():    #- ctrler finished ans -#
        return jsonify( full=1, img0=imgs[0], box0=boxes[0], img1=imgs[1], box1=boxes[1], 
                        moveN=moveN, correctN=correctN, isEnemy=isEnemy, end=game.isOver(), side=ctrlGrp.getSide() )

    elif mg.isSupervisor(usr) and ctrlGrp.isHalfAns():    #- just for display imgs -#
        return jsonify( giveup=0, half=half, img=img, box=box, countdown=game.getCountdown(), side=ctrlGrp.getSide() )

    else:                        #- no move -#
        return jsonify( countdown=game.getCountdown(), UID=int(usr.getUsrID()), side=ctrlGrp.getSide())