예제 #1
0
    def processAndSend(self, char, pos):
        position = []
        if char == 'white:soldier' or char == 'black:soldier':
            sold = Soldier(char, pos)
            position = sold.getPositions()

        elif char == 'white:eleph' or char == 'black:eleph':
            elephant = Elephant(char, pos)
            position = elephant.getPositions()

        elif char == 'white:camel' or char == 'black:camel':
            cam = Camel(char, pos)
            position = cam.getPositions()

        elif char == 'white:horse' or char == 'black:horse':
            hors = Horse(char, pos)
            position = hors.getPositions()

        elif char == 'white:queen' or char == 'black:queen':
            qun = Queen(char, pos)
            position = qun.getPositions()

        elif char == 'white:king' or char == 'black:king':
            kin = King(char, pos)
            position = kin.getPositions()
        dataString = pickle.dumps(position)
        self.client.send(dataString)
예제 #2
0
 def __init__(self, master, name='Demon'):
     Soldier.__init__(self, name)
     self.weapon = Axe(self)
     self.current_state.is_undead = True
     self.current_state.title = 'Undead'
     self.master = master
     master.set_slave(self)
예제 #3
0
def craete_class_from_json(file):
    armies = []
    with open(file, 'r') as f:
        data = json.load(f)

    for army in data['armies']:
        squads = []

        for squad in army['squads']:

            if squad['type'] == 'soldiers':
                units = []
                for unit in squad['units']:
                    unit = Soldier(health=unit['health'],
                                   recharge=unit['recharge'])
                    units.append(unit)
                squads.append(Squad(squad['type'], units))

            elif squad['type'] == 'vehicles':
                units = []
                for unit in squad['units']:
                    operators = []
                    for operator in unit['operators']:
                        operators.append(
                            Soldier(operator['health'], operator['recharge']))
                    units.append(
                        Vehicle(unit['health'], unit['recharge'], operators))
                squads.append(Squad(squad['type'], units))

        army = Army(army['name'], army['strategy'], squads)
        armies.append(army)
    return armies
예제 #4
0
class TestEligibility(unittest.TestCase):
    candidate1 = Soldier(23)
    candidate2 = Soldier(17)
    candidate3 = Soldier(24)
    candidate4 = Soldier(18)

    def test_one(self):
        self.assertEqual(self.candidate1.checkagelimit(), True)
예제 #5
0
def creat_soldier():
    data = Soldier()

    data.x = soldier_data['x']
    data.y = soldier_data['y']
    data.hit_point = soldier_data['hit_point']

    return data
예제 #6
0
 def insert_after(self, x, n):
     '''a method that can insert soldiers into the linked list at any point in the linked list that takes a soldier to insert after and the number of a new soldier as parameter.'''
     y = Soldier(n)  # makes the new soldier
     z = x.next  # stores the soldier after the soldier that is going to be inserted after.
     y.prev = x  # makes the 4 new connections with the new soldier in order to add it to the linked list.
     y.next = z
     x.next = y
     z.prev = y
예제 #7
0
class TestEligibility(unittest.TestCase):
	candidate1=Soldier(23)
	candidate2=Soldier(17)
	candidate3=Soldier(25)
	candidate4=Soldier(18)
	
	def test_one(self):
		self.assertEqual(self.candidate1.checkagelimit(),True)
	def test_two(self):
		self.assertEqual(self.candidate2.checkagelimit(),False)	
	def test_three(self):
		self.assertEqual(self.candidate3.checkagelimit(),True)
	def test_four(self):
		self.assertEqual(self.candidate4.checkagelimit(),False)
예제 #8
0
def enter():
    global soldier, space_world, soldier_bullet_team, tower, ship_bullet_team, alien_team

    space_world = Space_World()
    soldier = Soldier()
    tower = Tower()
    soldier_bullet_team = [Soldier_Bullet() for i in range(10)]
    ship_bullet_team = [Ship_Bullet() for i in range(30)]
    alien_team = [Alien() for i in range(30)]

    soldier.get_space(space_world)
    tower.get_space(space_world)

    for alien in alien_team:
        alien.get_tower(tower)
예제 #9
0
class Army:
    def __init__(self, soldiers, medics):
        self.soldiers = Soldier(soldiers)
        self.medics = Medic(medics)

    def health(self):
        return self.soldiers.health() + self.medics.health()
예제 #10
0
def enter():
    clear_canvas()
    global soldier, space, tutorial

    soldier = Soldier()
    space = Space()
    tutorial = Tutorial()
예제 #11
0
 def add_unit(self, unit):
     if unit['unit_type'] == 'Soldier':
         self.units.append(
             Soldier(self._clock, unit['name'], unit['health']))
     elif unit['unit_type'] == 'Vehicle':
         self.units.append(
             Vehicle(self._clock, unit['name'], unit['health'],
                     unit['operators']))
예제 #12
0
class TestEligibility2(unittest.TestCase):
    candidate11 = Soldier(23)
    candidate12 = Soldier(17)
    candidate13 = Soldier(25)
    candidate14 = Soldier(18)
    candidate15 = Soldier(26)
    candidate16 = Soldier(24)
    candidate17 = Soldier(19)

    def test_one_abc(self):
        self.assertEqual(self.candidate11.checkagelimit(), True)

    def test_two_abc(self):
        self.assertEqual(self.candidate12.checkagelimit(), False)

    def test_three_abc(self):
        self.assertEqual(self.candidate13.checkagelimit(), True)

    def test_four_abc(self):
        self.assertEqual(self.candidate14.checkagelimit(), False)

    def test_five_abc(self):
        self.assertEqual(self.candidate15.checkagelimit(), False)

    def test_six_abc(self):
        self.assertEqual(self.candidate16.checkagelimit(), True)

    def test_seven_abc(self):
        self.assertEqual(self.candidate17.checkagelimit(), False)
예제 #13
0
class TestEligibility1(unittest.TestCase):
    candidate1 = Soldier(23)
    candidate2 = Soldier(17)
    candidate3 = Soldier(25)
    candidate4 = Soldier(18)
    candidate5 = Soldier(26)
    candidate6 = Soldier(24)
    candidate7 = Soldier(19)

    def test_one(self):
        self.assertEqual(self.candidate1.checkagelimit(), True)

    def test_two(self):
        self.assertEqual(self.candidate2.checkagelimit(), False)

    def test_three(self):
        self.assertEqual(self.candidate3.checkagelimit(), True)

    def test_four(self):
        self.assertEqual(self.candidate4.checkagelimit(), False)

    def test_five(self):
        self.assertEqual(self.candidate5.checkagelimit(), False)

    def test_six(self):
        self.assertEqual(self.candidate6.checkagelimit(), True)

    def test_seven(self):
        self.assertEqual(self.candidate7.checkagelimit(), False)
예제 #14
0
def enter():
    clear_canvas()
    global soldier, space, tutorial, soldier_bullet_team, alien_team

    soldier = Soldier()
    space = Space()
    tutorial = Tutorial()
    soldier_bullet_team = creat_soldier_bullet_team()
    alien_team = creat_alien_team()
예제 #15
0
class SoldierBuilder:
    def __init__(self, name_weapon_factory):
        self.__weapon_factory = name_weapon_factory
        self.__soldier = None

    def reset(self, military_unit_number: int, name: str):
        self.__soldier = Soldier(military_unit_number, name)

    @property
    def soldier(self):
        soldier = self.__soldier
        return soldier

    def create_new_soldier(self, military_unit_number: int, name: str):
        self.__soldier = Soldier(military_unit_number, name)
        return self

    def add_strategy_kill(self, strategy):
        self.__soldier.set_strategy_kill(strategy)
        return self

    def add_knife(self):
        knife = self.__weapon_factory.create_knife()
        self.__soldier.add_weapon(knife)
        return self

    def add_sapper(self):
        sapper = self.__weapon_factory.create_sapper()
        self.__soldier.add_weapon(sapper)
        return self

    def add_pistol(self):
        pistol = self.__weapon_factory.create_pistol()
        self.__soldier.add_weapon(pistol)
        return self

    def add_automatic(self):
        automatic = self.__weapon_factory.create_automatic()
        self.__soldier.add_weapon(automatic)
        return self
예제 #16
0
 def __init__(self):
     self.soldier = Soldier(400, 400)
     self.health = 100
     self.screen = self.setup_pygame()
     self.font = self.setup_font()
     self.screen_rect = self.screen.get_rect()
     self.soldier_group = self.create_digimon()
     self.enemy_group = self.create_bullet()
     self.cannon_group = self.create_cannon()
     self.bullet_group = self.create_bullet()
     self.player_bullet_group = self.create_bullet()
     self.clock = pygame.time.Clock()
     self.fps = 60
     self.done = False
     self.current_time = 0.0
     self.speed = 5
     self.mode = "main_menu"
     self.play = pygame.Rect(150, 450, 100, 50)
     self.exit = pygame.Rect(550, 450, 100, 50)
예제 #17
0
def deathCheck():  # Used for checking if an ant should die
    from enemy import enemies
    from soldier import soldiers, Soldier
    enemylocations = set((enemy.x, enemy.y) for enemy in enemies)
    overlaps = [ant for ant in ants if (ant.x, ant.y) in enemylocations]
    for overlap in overlaps:
        antDeathStack.push(overlap.x)
        antDeathStack.push(overlap.y)
        list(map(lambda Soldier: Soldier.target(antDeathStack), soldiers))
        overlap.death()
        if deathmessages:
            print("Enemy killed ant", overlap.id)
    #soldierlocations = set((soldier.x,soldier.y) for soldier in soldiers)
    #print(enemylocations.intersection(soldierlocations))
    #list(map(lambda enemy:enemy.death(),enemylocations.intersection(soldierlocations)))
    for soldier in soldiers:
        for index, enemy in enumerate(enemies):
            if soldier.x == enemy.x and soldier.y == enemy.y:
                if deathmessages:
                    print("soldier", soldier.id, "has killed enemy ", enemy.id,
                          "Good job lilguy!")
                enemy.death(index)  #calls enemy death func
예제 #18
0
    def take_turn(self, offensive_units):  #[Unit] => void
        all_enemies = self.gc.sense_nearby_units_by_team(
            bc.MapLocation(self.gc.planet(), 0, 0), 1000000,
            Helper.get_opposing_team(self.gc.team()))

        if len(all_enemies) > 0:
            self.rally_point = all_enemies[0].location.map_location()
            self.on_alert = True
        else:
            self.rally_point = self.get_default_rally_point()
            self.on_alert = False

        for unit in offensive_units:
            soldier = self.unit_info.get(unit.id)
            if soldier is None:
                if unit.unit_type == bc.UnitType.Knight:
                    soldier = Knight(self.gc, self.intel_map, self.mov,
                                     self.astro, Role.Attack, unit)
                elif unit.unit_type == bc.UnitType.Ranger:
                    soldier = Ranger(self.gc, self.intel_map, self.mov,
                                     self.astro, Role.Attack, unit)
                elif unit.unit_type == bc.UnitType.Mage:
                    soldier = Mage(self.gc, self.intel_map, self.mov,
                                   self.astro, Role.Attack, unit)
                elif unit.unit_type == bc.UnitType.Healer:
                    soldier = Healer(self.gc, self.intel_map, self.mov,
                                     self.astro, Role.Attack, unit, self)
                else:
                    soldier = Soldier(self.gc, self.intel_map, self.mov,
                                      self.astro, Role.Scout, unit)
            soldier.set_rally_point(self.rally_point)
            self.unit_info[unit.id] = soldier
            if self.gc.planet() == bc.Planet.Mars:
                soldier.set_role(Role.Scout)
            soldier.set_rally_point(self.rally_point)
            soldier.take_turn(unit, self.on_alert)
            #Carry out soldier move
            soldier.move_and_attack()
예제 #19
0
 def __init__(self, game, pos):
     Soldier.__init__(self, game, pos)
     self.shield = 2
     self.shield_component = None
예제 #20
0
 def create_new_soldier(self, military_unit_number: int, name: str):
     self.__soldier = Soldier(military_unit_number, name)
     return self
예제 #21
0
 def army_pass_time(self):
     for i in self.units:
         if self.data[i]:
             Soldier.update_time(self.data[i], self.top_age)
예제 #22
0
                    self.operators[n].damage_received(damage * 0.3)
                else:
                    self.operators[n].damage_received(damage * 0.1)
            elif self.count_operator == 1:
                self.operators[n].damage_received(damage * 0.4)

        self.time_recharge = clock.set_time(self.recharge)
        print("health of vehicle: {}".format(self.health))
        for n, operator in enumerate(self.operators):
            print("health of operator {}: {}".format(n, operator.health))

        self.check_operators()


operators = []
oper1 = Soldier()
oper2 = Soldier()
oper3 = Soldier()
operators.append(oper1)
operators.append(oper2)
operators.append(oper3)

vehicle = Vehicle(100, 2, 100, operators)
vehicle.damage_received(100)

for n in range(vehicle.count_operator):
    print(vehicle.operators[n].health)

vehicle.damage_received(100)

for n in range(vehicle.count_operator):
예제 #23
0
 def __init__(self, name, team, fireteam, posx, posy, orientation, aggression):
     # subclass specific arguments go here
     Soldier.__init__(self, name, team, fireteam, posx, posy, orientation, aggression)
예제 #24
0
class TestEligibility(unittest.TestCase):
    candidate3=Soldier(24)
    
    def test_three(self):
        self.assertEqual(self.candidate1.checkagelimit(),True)
예제 #25
0
 def act(self):
     Soldier.act(self)
예제 #26
0
 def displaySoldier(self):
     Soldier.displaySoldier(self)
예제 #27
0
class TestEligibility(unittest.TestCase):
    candidate4 = Soldier(18)

    def test_four(self):
        self.assertEqual(self.candidate4.checkagelimit(), True)
예제 #28
0
 def decide(self):
     Soldier.decide(self)
예제 #29
0
 def __init__(self):
     self.first_soldier = Soldier(
         1)  # sets the first soldier as a soldier numbered 1.
     self.first_soldier.next = self.first_soldier  # sets the next and previous soldier as the first soldier if none have been added.
     self.first_soldier.prev = self.first_soldier
예제 #30
0
파일: vehicle.py 프로젝트: mashbes/lesson5
 def add_operator(self, operator):
     if operator['unit type'] == Soldier:
         self.operators.append(
             Soldier(self.clock, operator['name'], operator['health']))
 def test_basic(self):
     self.assertEqual(Soldier(10).health(), 100)
예제 #32
0
 def __init__(self):
     self.soldier = Soldier(1, 1, 1, 1, 1, "1")
예제 #33
0
 def __init__(self, soldiers, medics):
     self.soldiers = Soldier(soldiers)
     self.medics = Medic(medics)
예제 #34
0
 def reset(self, military_unit_number: int, name: str):
     self.__soldier = Soldier(military_unit_number, name)
예제 #35
0
    def __init__(self):
        """
        This constructor instantiates a game board, instantiates and adds the game piece objects to the board,
        initializes the game state to "unfinished",  initializes the current turn as the red players,
        and initializes the in-check status of the players.
        """
        self._board = self._board = {
            "a1": None,
            "b1": None,
            "c1": None,
            "d1": None,
            "e1": None,
            "f1": None,
            "g1": None,
            "h1": None,
            "i1": None,
            # row 2
            "a2": None,
            "b2": None,
            "c2": None,
            "d2": None,
            "e2": None,
            "f2": None,
            "g2": None,
            "h2": None,
            "i2": None,
            # row 3
            "a3": None,
            "b3": None,
            "c3": None,
            "d3": None,
            "e3": None,
            "f3": None,
            "g3": None,
            "h3": None,
            "i3": None,
            # row 4
            "a4": None,
            "b4": None,
            "c4": None,
            "d4": None,
            "e4": None,
            "f4": None,
            "g4": None,
            "h4": None,
            "i4": None,
            # row 5
            "a5": None,
            "b5": None,
            "c5": None,
            "d5": None,
            "e5": None,
            "f5": None,
            "g5": None,
            "h5": None,
            "i5": None,
            # row 6
            "a6": None,
            "b6": None,
            "c6": None,
            "d6": None,
            "e6": None,
            "f6": None,
            "g6": None,
            "h6": None,
            "i6": None,
            # row 7
            "a7": None,
            "b7": None,
            "c7": None,
            "d7": None,
            "e7": None,
            "f7": None,
            "g7": None,
            "h7": None,
            "i7": None,
            # row 8
            "a8": None,
            "b8": None,
            "c8": None,
            "d8": None,
            "e8": None,
            "f8": None,
            "g8": None,
            "h8": None,
            "i8": None,
            # row 9
            "a9": None,
            "b9": None,
            "c9": None,
            "d9": None,
            "e9": None,
            "f9": None,
            "g9": None,
            "h9": None,
            "i9": None,
            # row 10
            "a10": None,
            "b10": None,
            "c10": None,
            "d10": None,
            "e10": None,
            "f10": None,
            "g10": None,
            "h10": None,
            "i10": None,
        }
        self._red_pieces = []
        self._black_pieces = []

        red_char_1 = Chariot("red", "a1")
        self.update_board("a1", red_char_1)
        self._red_pieces.append(red_char_1)

        black_char_1 = Chariot("Black", "a10")
        self.update_board("a10", black_char_1)
        self._black_pieces.append(black_char_1)

        red_horse_1 = Horse("red", "b1")
        self.update_board("b1", red_horse_1)
        self._red_pieces.append(red_horse_1)

        black_horse_1 = Horse("black", "b10")
        self.update_board("b10", black_horse_1)
        self._black_pieces.append(black_horse_1)

        red_ele_1 = Elephant("red", "c1")
        self.update_board("c1", red_ele_1)
        self._red_pieces.append(red_ele_1)

        black_ele_1 = Elephant("black", "c10")
        self.update_board("c10", black_ele_1)
        self._black_pieces.append(black_ele_1)

        red_adv_1 = Advisor("red", "d1")
        self.update_board("d1", red_adv_1)
        self._red_pieces.append(red_adv_1)

        black_adv_1 = Advisor("black", "d10")
        self.update_board("d10", black_adv_1)
        self._black_pieces.append(black_adv_1)

        red_gen = General("red", "e1")
        self.update_board("e1", red_gen)
        self._red_pieces.append(red_gen)

        black_gen = General("Black", "e10")
        self.update_board("e10", black_gen)
        self._black_pieces.append(black_gen)

        red_adv_2 = Advisor("Red", "f1")
        self.update_board("f1", red_adv_2)
        self._red_pieces.append(red_adv_2)

        black_adv_2 = Advisor("black", "f10")
        self.update_board("f10", black_adv_2)
        self._black_pieces.append(black_adv_2)

        red_ele_2 = Elephant("red", "g1")
        self.update_board("g1", red_ele_2)
        self._red_pieces.append(red_ele_2)

        black_ele_2 = Elephant("black", "g10")
        self.update_board("g10", black_ele_2)
        self._black_pieces.append(black_ele_2)

        red_horse_2 = Horse("red", "h1")
        self.update_board("h1", red_horse_2)
        self._red_pieces.append(red_horse_2)

        black_horse_2 = Horse("black", "h10")
        self.update_board("h10", black_horse_2)
        self._black_pieces.append(black_horse_2)

        red_char_2 = Chariot("red", "i1")
        self.update_board("i1", red_char_2)
        self._red_pieces.append(red_char_2)

        black_char_2 = Chariot("black", "i10")
        self.update_board("i10", black_char_2)
        self._black_pieces.append(black_char_2)

        red_can_1 = Cannon("red", "b3")
        self.update_board("b3", red_can_1)
        self._red_pieces.append(red_can_1)

        black_can_1 = Cannon("black", "b8")
        self.update_board("b8", black_can_1)
        self._black_pieces.append(black_can_1)

        red_can_2 = Cannon("red", "h3")
        self.update_board("h3", red_can_2)
        self._red_pieces.append(red_can_2)

        black_can_2 = Cannon("black", "h8")
        self.update_board("h8", black_can_2)
        self._black_pieces.append(black_can_2)

        red_sol_1 = Soldier("red", "a4")
        self.update_board("a4", red_sol_1)
        self._red_pieces.append(red_sol_1)

        red_sol_2 = Soldier("red", "c4")
        self.update_board("c4", red_sol_2)
        self._red_pieces.append(red_sol_2)

        red_sol_3 = Soldier("red", "e4")
        self.update_board("e4", red_sol_3)
        self._red_pieces.append(red_sol_3)

        red_sol_4 = Soldier("red", "g4")
        self.update_board("g4", red_sol_4)
        self._red_pieces.append(red_sol_4)

        red_sol_5 = Soldier("red", "i4")
        self.update_board("i4", red_sol_5)
        self._red_pieces.append(red_sol_5)

        black_sol_1 = Soldier("black", "a7")
        self.update_board("a7", black_sol_1)
        self._black_pieces.append(black_sol_1)

        black_sol_2 = Soldier("black", "c7")
        self.update_board("c7", black_sol_2)
        self._black_pieces.append(black_sol_2)

        black_sol_3 = Soldier("black", "e7")
        self.update_board("e7", black_sol_3)
        self._black_pieces.append(black_sol_3)

        black_sol_4 = Soldier("black", "g7")
        self.update_board("g7", black_sol_4)
        self._black_pieces.append(black_sol_4)

        black_sol_5 = Soldier("black", "i7")
        self.update_board("i7", black_sol_5)
        self._black_pieces.append(black_sol_5)

        self._game_state = "UNFINISHED"
        self._turn = True

        self.generate_moves()

        self._red_in_check = {"red": False}
        self._black_in_check = {"black": False}
예제 #36
0
class TestSoldier(object):
    def __init__(self):
        self.soldier = Soldier(1, 1, 1, 1, 1, "1")

    def test_age(self):
        assert self.soldier.will_retire(1)
예제 #37
0
 def observe(self):
     Soldier.observe(self)