Esempio n. 1
0
 def setUp(self):
     self.tom = Character('Tom', {'HP': 10, 'AD': 5, 'DF': 3})
     self.dick = Character('Dick', {'HP': 10, 'AD': 5, 'DF': 3})
     self.decr_act = ModAttribute(
         "Punch", {
             'in': "{performer} punched {target}!",
             'done': "{target}'s {attr} reduced by {value}!"
         }, 'HP', -4)
Esempio n. 2
0
 def setUp(self):
     self.tom = Character('Tom', {'HP': 10, 'AD': 5, 'DF': 3})
     self.dick = Character('Dick', {'HP': 10, 'AD': 5, 'DF': 3})
     self.decr_act = ModAttribute("Punch",
                                     {'in': "{performer} punched {target}!",
                                      'done': "{target}'s {attr} reduced by {value}!"},
                                     'HP', -4)
Esempio n. 3
0
class decorator_test(unittest.TestCase):
    def setUp(self):
        self.tom = Character('Tom', {'HP': 10, 'AD': 5, 'DF': 3})
        self.dick = Character('Dick', {'HP': 10, 'AD': 5, 'DF': 3})
        self.decr_act = ModAttribute(
            "Punch", {
                'in': "{performer} punched {target}!",
                'done': "{target}'s {attr} reduced by {value}!"
            }, 'HP', -4)

    def testUndecoratedAttack(self):
        #print 'ModAttribute.execute(Tom, Dick) \n'

        results = self.decr_act.execute(self.tom, self.dick)

        self.assertEqual(results[1], 'Tom punched Dick!')
        self.assertEqual(results[2], 'Dick\'s HP reduced by 4!')

    def testDecoratedAttack(self):
        self.assertEqual(self.dick.attributes_dict['HP'], 10)
        self.assertEqual(self.tom.attributes_dict['HP'], 10)

        print 'ModAttribute.execute(Tom, Dick) \n'
        act_with_backfire = WithBackfire(self.decr_act)
        results = self.decr_act.execute(self.tom, self.dick)

        print 'Results: \n'
        for res in results[1:]:
            print '\t' + res + '\n'

        self.assertEqual(self.dick.attributes_dict['HP'], 6)
        self.assertEqual(self.tom.attributes_dict['HP'], 10)

        print 'Decorating.. WithBackfire(ModAttribute)\n'
        results = act_with_backfire.execute(self.tom, self.dick)
        print 'Results: \n'
        for res in results[1:]:
            print '\t' + res + '\n'

        self.assertEqual(self.dick.attributes_dict['HP'], 2)
        self.assertEqual(self.tom.attributes_dict['HP'], 8)
Esempio n. 4
0
class decorator_test(unittest.TestCase):

    def setUp(self):
        self.tom = Character('Tom', {'HP': 10, 'AD': 5, 'DF': 3})
        self.dick = Character('Dick', {'HP': 10, 'AD': 5, 'DF': 3})
        self.decr_act = ModAttribute("Punch",
                                        {'in': "{performer} punched {target}!",
                                         'done': "{target}'s {attr} reduced by {value}!"},
                                        'HP', -4)

    def testUndecoratedAttack(self):
        #print 'ModAttribute.execute(Tom, Dick) \n'
        
        results = self.decr_act.execute(self.tom, self.dick)

        self.assertEqual(results[1], 'Tom punched Dick!')
        self.assertEqual(results[2], 'Dick\'s HP reduced by 4!')

    def testDecoratedAttack(self):
        self.assertEqual(self.dick.attributes_dict['HP'], 10)
        self.assertEqual(self.tom.attributes_dict['HP'], 10)
        
        print 'ModAttribute.execute(Tom, Dick) \n'
        act_with_backfire = WithBackfire(self.decr_act)
        results = self.decr_act.execute(self.tom, self.dick)
        
        print 'Results: \n'
        for res in results[1:]:
            print '\t' + res + '\n'
        
        self.assertEqual(self.dick.attributes_dict['HP'], 6)
        self.assertEqual(self.tom.attributes_dict['HP'], 10)

        print 'Decorating.. WithBackfire(ModAttribute)\n'
        results = act_with_backfire.execute(self.tom, self.dick)
        print 'Results: \n'
        for res in results[1:]:
            print '\t' + res + '\n'
            
        self.assertEqual(self.dick.attributes_dict['HP'], 2)
        self.assertEqual(self.tom.attributes_dict['HP'], 8)
Esempio n. 5
0
    def setUp(self):
        tom = Character('Tom', {'HP': 10, 'AD': 5, 'DF': 3})
        dick = Character('Dick', {'HP': 10, 'AD': 5, 'DF': 3})
        decr_act = ModAttribute(
            "Punch", {
                'in': "{performer} punched {target}!",
                'done': "{target}'s {attr} reduced by {value}!"
            }, 'HP', -4)
        partA = PoliticalParty('Pirate Party')
        partA.add_member(tom)
        partA.add_member(dick)
        partA.set_active_member(tom)

        self.vars = GameplayVariables()
        self.vars.parties = [partA]
        self.vars.active_party = 0
        self.vars.actions_dict = {'Punch': decr_act}
Esempio n. 6
0
    def setup_data(self):
        """
         Sets up data for ElectionGame

        @return  :
        @author
        """
        # setup subject and observer
        self.vars = GameplayVariables()
        self.db = DBManager(self.vars)
        self.vars.attach(self.db)

        partyA = self.create_party("Republicans")
        charA = partyA.create_character("Mitt Romney", {
            'popularity': 50,
            'entourage': 500,
            'investment': 1000
        }, ["Appeal", "Defame", "Lie"])
        partyA.add_member(charA)
        partyA.set_active_member(charA)

        partyB = self.create_party("Democrats")
        charB = partyB.create_character("Barack Obama", {
            'popularity': 50,
            'entourage': 500,
            'investment': 1000
        }, ["Legislate", "Publish Birth Certificate", "Respond To Disaster"])
        partyB.add_member(charB)
        partyB.set_active_member(charB)

        self.vars.parties.append(partyA)
        self.vars.parties.append(partyB)

        self.vars.active_party = 1

        action1 = ModAttribute(
            "Appeal", {
                'in':
                "{performer} is appealing to the rich!",
                'done':
                "{performer} appealed to the rich! His {attr} has increased by {value}!"
            }, 'popularity', 10, False)
        action2 = ModAttribute(
            "Defame", {
                'in': "{performer} is insulting {target} publicly!",
                'done': "{target}'s {attr} has fallen by {value}!"
            }, 'popularity', -10, True)
        action3 = ModAttribute(
            "Lie", {
                'in':
                "{performer} is lying to the public about {target}'s policy!",
                'done':
                "{performer} lied to the public about {target}! {target}\'s {attr} has decreased by {value}!"
            }, 'entourage', -50, True)
        action4 = ModAttribute(
            "Legislate", {
                'in':
                "{performer} is legislating to make {target} and his rich friends pay for everyone's healthcare!",
                'done':
                "{performer} appealed to the middle classes! His {attr} has increased by {value}!"
            }, 'popularity', 10, True)
        action5 = ModAttribute(
            "Publish Birth Certificate", {
                'in':
                "{performer} is showing {target} up by proving he's American!",
                'done': "{target}'s {attr} has fallen by {value}!"
            }, 'popularity', -10, True)
        action6 = ModAttribute(
            "Respond To Disaster", {
                'in':
                "{performer} is responding to Hurricane Sandy by volunteering to help with relocation!",
                'done':
                "{performer} impressed the public, but his {attr} have less to do so they have decreased by {value}!"
            }, 'entourage', -50, False)

        # decorate the Lie action
        action3 = WithBackfire(action3)

        actions = {
            'Appeal': action1,
            'Defame': action2,
            'Lie': action3,
            'Legislate': action4,
            'Publish Birth Certificate': action5,
            'Respond To Disaster': action6
        }
        self.vars.actions_dict = actions

        self.vars.notify()