Ejemplo n.º 1
0
    def setUp(self):
        #instantiate all the army
        self.fighter_solider = soldier()
        self.fighter_archer = archer()
        self.fighter_cavalry = cavalry()
        #get the price of each type of army
        self.cost_solider = self.fighter_solider.getCost()
        self.cost_archer = self.fighter_archer.getCost()
        self.cost_cavalry = self.fighter_cavalry.getCost()

        while True:
            # Here we need to validate if the input is not integer
            try:
                self.n_soldier = int(input("S: "))
                self.n_archer = int(input("A: "))
                self.n_cavalry = int(input("C: "))
            except:
                print("Please Enter valid input.")
                pass
            # Here we need to validate the total cost if it is greater than the budget
            try:
                print("")
                self.n_soldier = int(self.n_soldier)
                self.n_archer = int(self.n_archer)
                self.n_cavalry = int(self.n_cavalry)
                # to find out the total cost
                total_cost = (self.n_soldier * self.cost_solider + self.n_archer * self.cost_archer +
                          self.n_cavalry * self.cost_cavalry)
                # check if the inputs are positive number
                if self.n_soldier < 0 or self.n_archer < 0 or self.n_cavalry < 0:
                   raise IndexError
                # check if the total cost is greater than the budget
                elif total_cost > self.cost:
                    raise ValueError
                break
            except ValueError:
                
                print("Dude! You don't have enough money to build up the army.")
                
                
            except IndexError:
                
                print("You cannot buy negative number of military.")
                
                
        # push each army object on the stack
        if self.n_cavalry > 0:
            for i in range(int(self.n_cavalry)):
                # instantiate an cavalry object and push to the stack
                self.stack.push(cavalry())
        if self.n_archer > 0:
            for j in range(int(self.n_archer)):
                # instantiate an archer object and push to the stack
                self.stack.push(archer())
        if self.n_soldier > 0:
            for k in range(int(self.n_soldier)):
                # instantiate an soldier object and push to the stack
                self.stack.push(soldier())

        return self.stack
Ejemplo n.º 2
0
 def test_defend_fail_cavalry(self):
     damage = 1
     test_object = cavalry()
     test_object.exp = 2
     test_object = test_object.defend(damage)
     self.assertEqual(0,test_object)
Ejemplo n.º 3
0
 def test_defend_success_cavalry(self):
     damage = 1
     test_object = cavalry().defend(damage)
     self.assertEqual(1,test_object)
Ejemplo n.º 4
0
 def test_getSpeed_cavalry(self):
     test_object = cavalry().getSpeed()
     self.assertEqual(2,test_object)
Ejemplo n.º 5
0
 def test_getCost_cavalry(self):
     test_object = cavalry().getCost()
     self.assertEqual(3,test_object)
Ejemplo n.º 6
0
 def test_attack_2_cavalry(self):
     test_object = cavalry()
     test_object.exp = 2
     test_object = test_object.attack()
     self.assertEqual(5,test_object)
Ejemplo n.º 7
0
 def test_attack_1_cavalry(self):
     test_object = cavalry().attack()
     self.assertEqual(1,test_object)
Ejemplo n.º 8
0
 def test_getExp_cavalry(self):
     test_object = cavalry().gainExperience(3)
     self.assertEqual(3,test_object)
Ejemplo n.º 9
0
 def test_lostLife_cavalry(self):
     test_object = cavalry().loseLive(2)
     self.assertEqual(2,test_object)
Ejemplo n.º 10
0
 def test_isAlive_False_cavalry(self):
     test_object = cavalry()
     test_object.life = 0
     test_object = test_object.isAlive()
     self.assertFalse(test_object)
Ejemplo n.º 11
0
 def test_isAlive_True_cavalry(self):
     test_object = cavalry().isAlive()
     self.assertTrue(test_object)
Ejemplo n.º 12
0
 def test_initialise_exp_cavalry(self):
     test_object = cavalry().exp
     self.assertEqual(0,test_object)
Ejemplo n.º 13
0
 def test_initialise_life_cavalry(self):
     test_object = cavalry().life
     self.assertEqual(4,test_object)
Ejemplo n.º 14
0
            raise ValueError("Your Balance is less than 2")
        # create an object of archer
        A1 = archer()
        # after each purchasing, reduce the money from the wallet
        money -= A1.getCost()
        # append the army in the list, which consisted of your military.
        army_list.append(str("soldier"))

    if command == 3:
        # here we do exception handling if the budget is not enough for buying an cavalry
        while True:
            try:
                if money < 3:
                    raise ValueError
                break
            except ValueError:
                raise ValueError("Your Balance is less than 3")
        # create an object of cavalry
        C1 = cavalry()
        # After each purchasing, reduce the money from the wallet
        money -= C1.getCost()
        # append the army in the list, which consisted of your military.
        army_list.append(str("cavalry"))

    if command == 4:
        quit = False

    if command < 1 or command > 4:
        print("please enter an valid number.")