def countdown(): usr = mg.getUsr( request.cookies.get('usrID') ) game = mg.getGame( usr.getGameID() ) game.setCountDown( request.form.get('countdown') ) print 'Set Countdown' print request.form.get('countdown') return flask.make_response()
def shuffle(): usr = mg.getUsr( request.cookies.get('usrID') ) game = mg.getGame( usr.getGameID() ) if request.method == 'GET': #- for recvOrder() -# if game != -1 and game.isReady() : ctrler = mg.getUsr( game.getCtrl()[0] ) return flask.jsonify( order=game.getOrder(), gameID=game.getGameID() ) else: return flask.jsonify( gameID=-1 ) elif request.method == 'POST': #- for sendOrder(), the usr is ctrler of 1st turn -# game.setOrder( request.form.getlist('order') ) return flask.jsonify( gameID=game.getGameID() )
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())
def shuffle(): global GAME_ID, READY usr = mg.getUsr( request.cookies.get('usrID') ) game = mg.getGame( usr.getGameID() ) GAME_ID = game.getGameID() if request.method == 'GET': #- for recvOrder() -# if ( game == -1 ) or ( not game.isReady() ): #print 'GET shuffle %d' %(usr.getUsrID()) return jsonify( gameID=-1 ) else: ctrler = mg.getUsr( game.getCtrl()[0] ) return jsonify( order=game.getOrder(), gameID=game.getGameID(), isEnemy=int(usr.isEnemyWith(ctrler)), side=usr.getSide() ) elif request.method == 'POST': #- for sendOrder(), the usr is ctrler of 1st turn -# #print 'POST shuffle %d' %(usr.getUsrID()) READY = True game.setOrder( request.form.getlist('order') ) return jsonify( gameID=game.getGameID(), side=usr.getSide() )