Exemple #1
0
 def setrelationship():
     pd = playset.parse_playset('/Users/danielsprechman/development/projects/fiasco/playset_main_st.txt')
     result = game_control.set_relationship(request.form['rel1_name'],
                                            request.form['rel1_option'],
                                            request.form['rel1_player'],
                                            request.form['rel2_name'],
                                            request.form['rel2_option'],
                                            request.form['rel2_player'],
                                            session['player'],
                                            pd,
                                            GAME_ID,
                                            get_db())
     return ''
Exemple #2
0
    def test_parse_playset(self):
        """ Testing playset functions
        playset.parse_playset
        """
        test_playset = playset.parse_playset(TEST_PLAYSET)
        assert(test_playset.name == 'Main Street')
        assert(len(test_playset.relationships) == 6)
        assert(len(test_playset.needs) == 6)
        assert(len(test_playset.locations) == 6)
        assert(len(test_playset.objects) == 6)

        for entry in test_playset.relationships:
            assert(len(entry.entries) == 6)
        for entry in test_playset.needs:
            assert(len(entry.entries) == 6)
        for entry in test_playset.locations:
            assert(len(entry.entries) == 6)
        for entry in test_playset.objects:
            assert(len(entry.entries) == 6)
Exemple #3
0
 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))
Exemple #4
0
    def test_game_control(self):
        """ Testing game_control functions
        game_control.initialize_game
        """
        clear_tables(self.db)
        p1 = player.Player(*TEST_PLAYER_VALUES1)
        p2 = player.Player(*TEST_PLAYER_VALUES2)
        p3 = player.Player(*TEST_PLAYER_VALUES3)
        # insert players into db
        player.insert_player_into_db(p1, self.db)
        player.insert_player_into_db(p2, self.db)
        player.insert_player_into_db(p3, self.db)
        # initialize game
        game_control.initialize_game(p1.game_id, self.db)
        # get the updated player information
        p1 = player.get_player_from_db_by_name(p1.name, p1.game_id, self.db)
        p2 = player.get_player_from_db_by_name(p2.name, p2.game_id, self.db)
        p3 = player.get_player_from_db_by_name(p3.name, p3.game_id, self.db)
        # In a 3 person game, everyone should be neighbors with eachother
        assert(p1.p_left_name in [p2.name, p3.name])
        assert(p1.p_right_name in [p2.name, p3.name])
        assert(not p1.p_left_name == p1.p_right_name)
        assert(p2.p_left_name in [p1.name, p3.name])
        assert(p2.p_right_name in [p1.name, p3.name])
        assert(not p2.p_left_name == p2.p_right_name)
        assert(p3.p_left_name in [p1.name, p2.name])
        assert(p3.p_right_name in [p1.name, p2.name])
        assert(not p3.p_left_name == p3.p_right_name)

        # try setting relationships

        # first prepare the dice, so that there's enough for all the tests
        dice.insert_dice_into_db(dice.Dice({0:100,1:100,2:100,3:100,4:100,5:100,6:100},p1.game_id), self.db)
        
        test_playset = playset.parse_playset(TEST_PLAYSET)
        # p1 and p2: mayor / health commissioner
        # p1 and p3: drug dealer / drug manufacturer
        # p2 and p3: plumber / client
        p1_p2_rel_opt = ('elected official', 'mayor')
        p2_p1_rel_opt = ('elected official', 'health commissioner')
        p1_p3_rel_opt = ('drug person', 'dealer')
        p3_p1_rel_opt = ('drug person', 'manufacturer')
        p2_p3_rel_opt = ('tradesman', 'plumber')
        p3_p2_rel_opt = ('client', '')
        retval = game_control.set_relationship(p1_p2_rel_opt[0], p1_p2_rel_opt[1], p1.name,
                                               p2_p1_rel_opt[0], p2_p1_rel_opt[1], p2.name,
                                               p1.name, test_playset, p1.game_id, self.db)
        assert (retval == game_control.NO_ERROR)
        retval = game_control.set_relationship(p1_p3_rel_opt[0], p1_p3_rel_opt[1], p1.name,
                                               p3_p1_rel_opt[0], p3_p1_rel_opt[1], p3.name,
                                               p3.name, test_playset, p1.game_id, self.db)
        assert (retval == game_control.NO_ERROR)
        retval = game_control.set_relationship(p2_p3_rel_opt[0], p2_p3_rel_opt[1], p2.name,
                                               p3_p2_rel_opt[0], p3_p2_rel_opt[1], p3.name,
                                               p3.name, test_playset, p1.game_id, self.db)
        assert (retval == game_control.NO_ERROR)
        # get the updated player information
        p1 = player.get_player_from_db_by_name(p1.name, p1.game_id, self.db)
        p2 = player.get_player_from_db_by_name(p2.name, p2.game_id, self.db)
        p3 = player.get_player_from_db_by_name(p3.name, p3.game_id, self.db)

        #print_player_info(p1)
        #print_player_info(p2)
        #print_player_info(p3)
        
        # In a 3 person game, everyone should be neighbors with eachother
        if p1.p_left_name == p2.name:
            # for player 1: left is p2, right is p3
            assert p1_p2_rel_opt == (p1.rel_l_role, p1.rel_l_option)
            assert p1_p3_rel_opt == (p1.rel_r_role, p1.rel_r_option)
            # for player 3: left is p1, right is p2
            assert p3_p1_rel_opt == (p3.rel_l_role, p3.rel_l_option)
            assert p3_p2_rel_opt == (p3.rel_r_role, p3.rel_r_option)
            # for palyer 2: left is p3, right is p1
            assert p2_p3_rel_opt == (p2.rel_l_role, p2.rel_l_option)
            assert p2_p1_rel_opt == (p2.rel_r_role, p2.rel_r_option)
        elif p1.p_left_name == p3.name:
            # for player 1: left is p3, right is p2
            assert p1_p3_rel_opt == (p1.rel_l_role, p1.rel_l_option)
            assert p1_p2_rel_opt == (p1.rel_r_role, p1.rel_r_option)
            # for player 3: left is p2, right is p1
            assert p3_p2_rel_opt == (p3.rel_l_role, p3.rel_l_option)
            assert p3_p1_rel_opt == (p3.rel_r_role, p3.rel_r_option)
            # for palyer 2: left is p1, right is p3
            assert p2_p1_rel_opt == (p2.rel_l_role, p2.rel_l_option)
            assert p2_p3_rel_opt == (p2.rel_r_role, p2.rel_r_option)
        else:
            # this should not happen
            assert False