def new_game(): """Form for submitting new game""" #name,players = None,None create_game_form = NewGameForm() if create_game_form.validate_on_submit(): #split the string of player names #TODO: error handling if this is not formatted correctly players = create_game_form.players.data.split(',') #Instantiate class game = Game(name=create_game_form.name.data) #add players game.add_players(player_names=players,num_players=len(players)) #add to database game.archive(db) return render_template('new_game.html',form=create_game_form)
def new_game(): """Form for submitting new game""" #name,players = None,None create_game_form = NewGameForm() if create_game_form.validate_on_submit(): #split the string of player names #TODO: error handling if this is not formatted correctly players = create_game_form.players.data.split(',') #Instantiate class game = Game(name=create_game_form.name.data) #add players game.add_players(player_names=players, num_players=len(players)) #add to database game.archive(db) return render_template('new_game.html', form=create_game_form)
def enter_game_code_view(): form = NewGameForm() if form.validate_on_submit(): # get the id of the scenario corresponding to the code scenario = db.session.query(Scenario).filter(and_(Scenario.code == form.code.data, Scenario.status == ACTIVE)).first() player = db.session.query(Player).get(current_user.get_id()) if scenario: # the code is valid # check if the scenario is ACTIVE or RUNNING # if so, redirect to the game if scenario in player.played_scenario and scenario.status in [ACTIVE, RUNNING]: session['scenario_code'] = scenario.code session['scenario_id'] = scenario.id return redirect(url_for('demand_game_dashboard')) player.played_scenario.append(scenario) db.session.commit() session['scenario_id'] = scenario.id session['scenario_code'] = scenario.code scenario = Scenario.query.get(scenario.id) #init the gameboard gameboard = GameBoard() gameboard.period = 1 gameboard.table = cPickle.dumps(TableDict(scenario.duration)) # a dump of the table containing th game data player.gameboards.append(gameboard) scenario.gameboards.append(gameboard) db.session.add(gameboard) db.session.commit() return redirect(url_for('demand_game_dashboard')) else: form = NewGameForm() return render_template('new_game_form.html', form=form, message='Code not valid') return render_template('new_game_form.html', form=form)
def new_game(): form = NewGameForm() if form.validate_on_submit(): rows = form.rows.data columns = form.columns.data mines = form.mines.data if mines < rows * columns: session['game_board'] = ms.create_game_board(rows, columns, mines=mines) session['game_on'] = True return redirect(url_for('render_board')) else: flash(u"You can't have more mines than spaces!") else: for field, errors in form.errors.items(): for error in errors: flash(u"Error in the %s field - %s" % (getattr(form, field).label.text, error)) return render_template('new_game.html', form=form)
def new_game(): """Form for submitting new game""" #name,players = None,None create_game_form = NewGameForm() if create_game_form.validate_on_submit(): #split the string of player names #TODO: error handling if this is not formatted correctly players = create_game_form.players.data.split(',') #Instantiate class game = scrabble.Game(name=create_game_form.name.data) #add players game.add_players(player_names=players, num_players=len(players)) #add to database game_archive = pack_game(game) db.session.add(game_archive) db.session.commit() cur_game(game.name) #create player pages for p in players: player_view(game.name, p) return render_template('new_game.html', form=create_game_form)
def new_game(): """Form for submitting new game""" #name,players = None,None create_game_form = NewGameForm() if create_game_form.validate_on_submit(): #split the string of player names #TODO: error handling if this is not formatted correctly players = create_game_form.players.data.split(',') #Instantiate class game = scrabble.Game(name=create_game_form.name.data) #add players game.add_players(player_names=players,num_players=len(players)) #add to database game_archive = pack_game(game) db.session.add(game_archive) db.session.commit() cur_game(game.name) #create player pages for p in players: player_view(game.name,p) return render_template('new_game.html',form=create_game_form)