def flag_view(request): """Call this view when right click a cell to flag it """ if 'service' not in request.session: return ERROR service = request.session["service"] row = int(request.json_body['row']) col = int(request.json_body['col']) service.update_board_with_flag(row, col) return [Jsonify.to_board_view(service._game._board, service._game._result), service._game._result, request.session['level']];
def new_game_view(request): """Create a new game from level 0 no matter what """ print 'Start a new game from beginner level...' level = 0 service = create_game(level, [Player("player1")]) request.session['service'] = service request.session['level'] = level print "mines:", service._game._mines return [Jsonify.to_board_view(service._game._board, service._game._result), request.session['level']];
def update_view(request): """Call this view when left click to reveal a cell """ if 'service' not in request.session: return ERROR service = request.session["service"] row = int(request.json_body['row']) col = int(request.json_body['col']) print "Update:", row, col service.update_board_with_reveal(row, col) if service._game._result==1: #Enter next level if player won request.session['level'] += 1 return [Jsonify.to_board_view(service._game._board, service._game._result), service._game._result, request.session['level']];
def load_game_view(request): """If unfinished game is found in memory, then load it Otherwise create a new game """ level = 0 if 'level' not in request.session: request.session['level'] = level else: level = request.session['level'] #If there was no game service, or current game finished, then we can start a new game service if 'service' not in request.session or request.session['service']._game._result is not 0: print 'Init game...' service = create_game(level, [Player("player1")]) request.session['service'] = service else: print "load existing game..." service = request.session["service"] print "mines:", service._game._mines return [Jsonify.to_board_view(service._game._board, service._game._result), request.session['level']];