def create_game(board_name):
    if not board_name:
        board_name = get_random_board()
    if not does_board_exist(board_name):
        return None
    game_id = get_random_id()
    game = {
        'boardName': board_name,
        'players': {},
        'cells': {},
        'colors': [color for color in COLORS]
    }
    GAMES[game_id] = game
    db.create_game(game_id, game_to_save_blob(game))
    return game_id
Esempio n. 2
0
File: views.py Progetto: tomik/honey
def upload_game():
    """Loads game from url/file, stores in the DB and displays. Requires login."""
    form = forms.SgfUploadForm()
    # this must be done explicitly
    # because for some reason request.files is not picked up by the wtf form
    if request.method == "POST" and "file" in request.files:
        form.file.data = request.files["file"]
    if request.method == "POST" and form.validate_on_submit():
        if form.sgf:
            username = session["username"]
            user = db.get_user_by_username(username)
            if not user:
                abort(500)
            game, err = db.create_game(user._id, form.sgf, request.game_type)
            if not game:
                # attach the error to the form
                if form.url.data:
                    form.url.errors = (err,)
                elif form.file.data:
                    form.file.errors = (err,)
                return render_template("upload_game.html", menu_toggle_upload=True, form=form)
            return redirect(url_for("view_game", game_id=game._id))
        else:
            abort(500)
    return render_template("upload_game.html", menu_toggle_upload=True, form=form)
Esempio n. 3
0
def create_game_post(response):
  code_in_use = True
  while code_in_use:
    #create a roomcode, 
    code = randomword(4)
    #check if code is in use
    code_in_use = db.room_code_in_use(code)
  #add it to the database of room codes
  game_id = db.create_game(code)
  #add the player to the games_players table for this room redirect to the lobby for the room code
  join_lobby(response, code)
Esempio n. 4
0
def create_game_post(response):
    code_in_use = True
    while code_in_use:
        #create a roomcode,
        code = randomword(4)
        #check if code is in use
        code_in_use = db.room_code_in_use(code)
    #add it to the database of room codes
    game_id = db.create_game(code)
    #add the player to the games_players table for this room redirect to the lobby for the room code
    join_lobby(response, code)
Esempio n. 5
0
def create_game(player_name):
    """
    Generate a room access code and create a game with the creator as the first player
    """

    # create a player with player_name who is the moderator
    player = db_util.create_player(player_name, True)

    # generate an access code for the game
    while True:
        access_code = gl.generate_access_code()
        if db.games.count_documents({'access_code': access_code}) == 0:
            break

    # create a game with the player and access code
    game = db_util.create_game(access_code, player)
    db.games.insert_one(game)

    # send the room access code back to the creator
    send(access_code)
    join_room(access_code)
Esempio n. 6
0
	def initialize(self):
		self.game_id = db.create_game()