def test_clear(self): test_dice = dice.initialize_dice(3,'0') dice.insert_dice_into_db(test_dice, self.db) test_player = player.Player (*TEST_PLAYER_VALUES1) player.insert_player_into_db(test_player, self.db) assert len(player.get_players_from_db(test_player.game_id, self.db)) > 0 assert len(dice.get_dice_from_db(test_dice.game_id, self.db).dice_dic) > 0 clear_tables(self.db) assert len(player.get_players_from_db(test_player.game_id, self.db)) == 0 assert dice.get_dice_from_db(test_dice.game_id, self.db) == None
def test_dice(self): """ Testsing dice functions dice.get_dice_from_db dice.insert_dice_into_db dice.get_dice_from_db """ clear_tables(self.db) num_players = 4 test_dice = dice.initialize_dice(num_players,'0') total = 0 for key in test_dice.dice_dic: total += test_dice.dice_dic[key] assert (total == 4 * num_players) # insert dice dice.insert_dice_into_db(test_dice, self.db) # get dice db_dice = dice.get_dice_from_db(test_dice.game_id, self.db) assert(db_dice == test_dice)
def play(): player_names = player.get_player_names_from_db(GAME_ID, get_db()) cur_player_name = game_control.player_name_check(request.args.get('player',''), session['player'], player_names) if cur_player_name: session['player'] = cur_player_name else: return render_template('select_player.html', players=player_names) if status.get_round_from_db(GAME_ID, get_db()) == -1: game_control.initialize_game(GAME_ID, get_db()) cur_player = player.get_player_from_db_by_name(cur_player_name, GAME_ID, get_db()) pd = playset.parse_playset('/Users/danielsprechman/development/projects/fiasco/playset_main_st.txt') return render_template('play.html', player=session['player'], playset_name='Main St.', dice_html=view.get_dice_html(dice.get_dice_from_db(GAME_ID, get_db()).dice), neighbors=[cur_player.p_left_name, cur_player.p_right_name], playset_html = view.get_playset_html(pd, get_db(), cur_player_name, GAME_ID))
def set_relationship(rel1_role, rel1_option, rel1_player, rel2_role, rel2_option, rel2_player, cur_player_name, pset, game_id, db): """ Updates the database - sets the relationships for one of the neighbor pairs """ rel_indices = playset.get_relationship_indices(rel1_role, rel2_role, rel1_option, rel2_option, pset) if not rel_indices: return ERROR_INVALID_RELATIONSHIP_VALUES # check if dice are ok game_dice = dice.get_dice_from_db(game_id, db) if game_dice.dice_dic[rel_indices[1]+1] <= 0: return ERROR_NOT_ENOUGH_DICE p1 = player.get_player_from_db_by_name(rel1_player, game_id, db) p2 = player.get_player_from_db_by_name(rel2_player, game_id, db) if not p1 or not p2: return ERROR_INVALID_PLAYERS if not rel1_player == cur_player_name and not rel2_player == cur_player_name: return ERROR_CURRENT_PLAYER_NOT_IN_RELATIONSHIP if rel1_player == rel2_player: return ERROR_PLAYERS_MUST_BE_DIFFERENT if p1.p_left_name == p2.name: # neighor is to the left set_left_relationship(rel1_role, rel1_option, playset.get_relationship_id_from_indices( rel_indices, flip_a_b=False), p1, db) set_right_relationship(rel2_role, rel2_option, playset.get_relationship_id_from_indices( rel_indices, flip_a_b=True), p2, db) elif p1.p_right_name == p2.name: # neighbor is to the right set_right_relationship(rel1_role, rel1_option, playset.get_relationship_id_from_indices( rel_indices, flip_a_b=False), p1, db) set_left_relationship(rel2_role, rel2_option, playset.get_relationship_id_from_indices( rel_indices, flip_a_b=True), p2, db) player.update_player_by_name(p1, db) player.update_player_by_name(p2, db) return NO_ERROR
def get_setup_status(): dice_html = view.get_dice_html(dice.get_dice_from_db(GAME_ID, get_db()).dice) data = {'dice_html' : dice_html} #data = {'test1' : 'a', 'test2' : 'b'} #print "RETURNING: " + str(jsonify(data)) return jsonify(data)