def know(): (usr, grp, game) = mg.getObjs( request.cookies.get('usrID') ) #print 'GET know %d' %(usr.getUsrID()) if game.allKnow(): curCtrlGrp = mg.getGrp( game.getCtrl()[1] ) nextCtrlGrp = mg.getGrp( curCtrlGrp.getEnemyGID() ) game.usrChangeState() if game.allChanged(): game.reset() nextCtrler = nextCtrlGrp.getUsrs()[0] game.setCtrl( nextCtrler.getUsrID(), nextCtrlGrp.getGrpID() ) if usr.getGrpID() == nextCtrlGrp.getGrpID(): return jsonify(allknow=1, ctrl=1) else: return jsonify(allknow=1, ctrl=0) else: usr.setKnow() return make_response()
def wait(): #- used by recvAns() from teammate and enemies -# usr = mg.getUsr( request.cookies.get('usrID') ) game = mg.getGame( usr.getGameID() ) (ctrlUID, ctrlGID) = game.getCtrl() if ctrlUID == -1 or ctrlGID == -1: return flask.make_response() ctrler = mg.getUsr(ctrlUID) ctrlGrp = mg.getGrp(ctrlGID) (imgs, boxes) = ctrlGrp.getAns() isEnemy = usr.isEnemyWith(ctrler) if ctrlGrp.isGiveUp(): print 'Know Give Up' usr.listenAns() if game.allKnowAns(): #- reset for next turn -# game.reset() if ctrlGrp.isHalfAns(): #- ctrler runs out of time with 1 card open -# return flask.jsonify( giveup=1, img=imgs[0], box=boxes[0], isEnemy=isEnemy ) else: #- ctrler runs out of time with 0 card open -# return flask.jsonify( giveup=1, img='', box='', isEnemy=isEnemy ) elif ctrlGrp.isHalfAns(): #- just for display imgs -# print 'Know Half Ans' print game.getCountdown() return flask.jsonify( half=1, img=imgs[0], box=boxes[0], countdown=game.getCountdown() ) elif ctrlGrp.isFullAns(): #- ctrler finished ans -# print 'Know Full Ans' if game.allKnowAns(): #- all player know answer, so reset for next turn -# return flask.jsonify( full=1, allknow=1, isEnemy=isEnemy, end=game.isOver() ) elif usr.knowAns(): return flask.jsonify( full=1, know=1 ) else: usr.listenAns() return flask.jsonify( full=1, know=0, img0=imgs[0], box0=boxes[0], img1=imgs[1], box1=boxes[1] ) else: print 'No Move' print game.getCountdown() return flask.jsonify( countdown=game.getCountdown() )
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())