def army_v_army():

    a = 0
    b = 0
    for x in range(1):

        a1 = Army([Unit(6, "Human", "Veteran", "Heavy", "Cavalry")], 0,
                  RandomChoice())
        a2 = Army([
            Unit(6, "Bugbear", "Green", "Light", "Infantry"),
            Unit(6, "Bugbear", "Green", "Light", "Archers"),
            Unit(4, "Human", "Levies")
        ], 0, UserChoice())

        battle = Battle([a1, a2])

        battle.fight()

        if SHOULD_PRINT():
            for i in battle.armies:
                print(i)
                print()

        if a1.alive:
            print(a1)
            a += 1

        if a2.alive:
            print(a2)
            b += 1

    print(a)
    print(b)
Example #2
0
 def __init__(self, prefix, unit):
     symbol = f"{prefix.symbol}{unit.symbol}"
     notation = f"{prefix.prefix}{unit.notation}"
     plurality = f"{prefix.prefix}{unit.plurality}"
     Unit.__init__(self, symbol, notation, plurality)
     self.prefix = prefix
     self.unit = unit
Example #3
0
	def load_file( self ) :
		# 1. Load file contents into memory
		file_lines = []

		with open( self.filename ) as instream :
			for line in instream :
				line = line.strip()
				file_lines.append( line )
		print >> sys.stdout, len(file_lines), "lines loaded from", self.filename
		
		idx = 1
		vloc_count = 0
		fortloc_count = 0
		# 2. Process lines
		for line in file_lines :
			if self.oob_db is None :
				if ".oob" in line : # oob file reference found
					print >> sys.stdout, "Found reference to OOB file:", line
					self.oob_db = OrderOfBattle( line )
				if idx == 9 : # Side A losses
					self.side_A_casualties.load_losses( line )
				if idx == 10 : # Side A loss vp's
					self.side_A_casualties.load_losses_vp( line )
				if idx == 11 : # Side B losses
					self.side_B_casualties.load_losses( line )
				if idx == 12 : # Side B loss vp's
					self.side_B_casualties.load_losses_vp( line )
				idx +=1
				continue
			tokens = [ tok.strip() for tok in line.split( " " )]
			if self.oob_db is not None and tokens[0] == "1" : # Unit reference found
				u = Unit()
				u.load( tokens, self.oob_db )
				self.units.append( u )
				self.units_db[u.ID] = u
				try :
					self.units_locs[ (u.X, u.Y) ] += [ u ]
				except KeyError :
					self.units_locs[ (u.X, u.Y) ] = [ u ]
			if self.oob_db is not None and tokens[0] == "6" : # Victory Location
				loc = VictoryLocation()
				loc.load( tokens )
				self.vp_locs[ (loc.X, loc.Y) ] = loc
				vloc_count += 1
			if self.oob_db is not None and tokens[0] == "10" : # Fortified Location
				loc = FortifiedLocation()
				if loc.load( tokens ) :
					self.fort_locs[ (loc.X, loc.Y) ] = loc
					fortloc_count += 1
			idx += 1
			
		print >> sys.stdout, len(self.units), "units loaded from", self.filename
		print >> sys.stdout, vloc_count, "victory locations loaded from", self.filename
		print >> sys.stdout, fortloc_count, "fortified locations loaded from", self.filename
Example #4
0
    def molecular_weight(self):
        """ Calculate molecular weight based on stuff """

        if len(self.sequence) == 0:
            return 0

        # get the material type
        if 'DNA' in self.material: seq_type = 'DNA'
        elif 'RNA' in self.material: seq_type = 'RNA'
        elif 'protein' in self.material: seq_type = 'protein'

        # get double stranded state
        if 'ds' in self.material: double_stranded = True
        else: double_stranded = False

        # get circular state
        circular = (self.shape == 'circular')

        # find MW value
        mw = molecular_weight(self.sequence,
                              seq_type=seq_type,
                              double_stranded=double_stranded,
                              circular=circular)

        # create unit object
        self._molecular_weight = Unit('{} g/mol'.format(mw))

        # return value with unit
        return self._molecular_weight
Example #5
0
    def draw_polygon_arc(self, center_point, radius, edge_count, start_angle,
                         end_angle, direction):
        """Draw a polygon."""
        if isinstance(edge_count, tuple):
            edge_count, arc_angle = edge_count
        else:
            arc_angle = end_angle - start_angle

        print 'draw_polygon_arc with {} edges, centered on {} with radius of {}, between {} and {}'.format(
            edge_count, center_point, radius, start_angle, end_angle)

        edge_count = int(math.ceil(edge_count))
        if edge_count < 3:
            raise ValueError('draw_polygon needs a minimum of 3 edges.')

        Display.debug_circle(center_point, radius)
        Display.debug_point(center_point, 'green')

        delta_step = Unit(arc_angle / float(edge_count))
        if direction == CW:
            delta_step = -abs(delta_step)
        elif direction == CCW:
            delta_step = abs(delta_step)

        polar = Polar(radius, start_angle)

        turtle.up()
        self.setpos(center_point + polar.cartesian())
        Display.debug_point(center_point + polar.cartesian(), 'pink')

        turtle.down()
        # direction = sign(delta_step)
        for i in range(int(edge_count)):
            polar.t += delta_step
            self.setpos(center_point + polar.cartesian())
Example #6
0
    def volume(self, value):
        """ Volume Setter Property """
        # set volume of object
        if not isinstance(value, Unit):
            value = Unit(value)

        self._volume = value
Example #7
0
    def count(self,value):
        """ Mass Setter Property """
        # set moles of object 
        if not isinstance(value,Unit):  
            value = Unit(value)

        self._count = value
def army_test():

    a1 = Army([Unit(6, "Ghoul", "Veteran", "Light", "Cavalry")], 0)
    a2 = Army([
        Unit(6, "Bugbear", "Green", "Heavy", "Infantry"),
        Unit(4, "Human", "Archers")
    ], 0)

    battle = Battle([a1, a2])

    print(a2.units[0].getOrders(battle))

    # battle.fight()

    if SHOULD_PRINT():
        for i in battle.armies:
            print(i)
            print()
Example #9
0
    def total_volume(self,value):
        """ Solution Volume Setter Property """
        self._total_volume = Unit(value)

        # check if any of these exist
        for key in ('moles','mass'):
            if getattr(self,key) != None:
                self.refresh_attributes(key)
                return None
def army_v_army_test():

    u1 = Unit(4, "Human", "Regular", "Medium", "Cavalry")
    u2 = Unit(12, "Dwarf", "Seasoned", "Heavy", "Infantry")

    u3 = Unit(12, "Dwarf", "Seasoned", "Heavy", "Infantry")
    u4 = Unit(4, "Gnome", "Veteran", "Medium", "Cavalry")

    a1 = Army([u1, u2], 0, UserChoice())
    a2 = Army([u3, u4], 0, UserChoice())

    battle = Battle([a1, a2])

    battle.fight()

    if SHOULD_PRINT():
        for i in battle.armies:
            print(i)
            print()
Example #11
0
def CreateUnit(**kwargs):
    """Function used to create a Unit object from a json dictionary"""
    # Import this here to avoid cyclical dependencies....
    # TODO: Fix these dependencies.
    from units import Hero, Unit

    # Special case for Heroes, who need to use a subclass that doesn't check abilities for actions
    if kwargs.get('type', None) == "Hero":
        return Hero(**kwargs)
    else:
        return Unit(**kwargs)
def army_v_army_2():

    a = 0
    b = 0
    turns = 0
    Iterations = 1
    for x in range(Iterations):

        u1 = Unit(6, "Orc", "Veteran", "Light", "Flying")
        u2 = Unit(6, "Human", "Regular", "Medium", "Cavalry")
        u3 = Unit(6, "Dwarf", "Seasoned", "Heavy", "Infantry")
        u4 = Unit(6, "Dragonborn", "Seasoned", "Medium", "Infantry")

        u5 = Unit(6, "Human", "Veteran", "Heavy", "Infantry")
        u6 = Unit(12, "Human", "Levies")
        u7 = Unit(6, "Elf", "Seasoned", "Light", "Archers")
        u8 = Unit(6, "Gnome", "Veteran", "Medium", "Cavalry")

        a1 = Army([u1, u2, u3, u4], 0, UserChoice())
        a2 = Army([u5, u6, u7, u8], 0, UserChoice())

        battle = Battle([a1, a2])

        battle.fight()

        turns += battle.turnNumber

        if SHOULD_PRINT():
            for i in battle.armies:
                print(i)
                print()

        if a1.alive:
            if SHOULD_PRINT():
                print(a1)
            a += 1

        if a2.alive:
            if SHOULD_PRINT():
                print(a2)
            b += 1

    print(turns / Iterations)
    print(a)
    print(b)
Example #13
0
 def getScalar(self,name,unit=None):
   node = self.file.getNode("/estimators",name)
   try:
     unitName = node.getAttr("unit")
     dataUnit = Unit.getByName(unitName[0])
   except:
     if unit == None:
       dataUnit = None
     else:
       dataUnit = unit.native
   nstep = self.file.getNodeAttr("/estimators","nstep")[0]
   if unit == None:
     data = node.read()[:nstep]
   else:
     data = unit.convert(node.read()[:nstep],dataUnit)
   scalar = Scalar(name,data,unit)
   return scalar
Example #14
0
    def _c_config(self, lines):
        for line in lines:
            unit = line.replace('\n', '').split(':')
            conf = unit[1][1:].split(",")
            unit = unit[0]

            # Setup Cache
            if unit == 'I-Cache':
                self._cache[unit].config(int(conf[0]), int(conf[1]))
            elif unit == 'D-Cache':
                self._cache[unit].config(int(conf[0]), int(conf[1]), 2)
            # Setup fp Units
            else:
                for i in range(0, int(conf[0])):
                    self._units[unit].append(
                        Unit(uType=unit + str(len(self._units[unit])),
                             regs=self.registers,
                             mem=self._cache['D-Cache'],
                             execTime=int(conf[1])))
Example #15
0
    def draw_arc(self,
                 center_point,
                 radius,
                 start_angle,
                 end_angle,
                 direction=CCW,
                 arc_angle=None):
        """Draw an arc."""
        print 'draw_arc centered on {} with radius of {}, between {} and {}'.format(
            center_point, radius, start_angle, end_angle)

        if arc_angle is None:
            arc_angle = abs(end_angle - start_angle)
        arc_length = radius * Unit(arc_angle)
        edges_per_mm = 0.5
        edge_count = arc_length * float(edges_per_mm)
        edge_count = max(3, int(math.ceil(edge_count)))

        return self.draw_polygon_arc(center_point, radius,
                                     (edge_count, arc_angle), start_angle,
                                     end_angle, direction)
Example #16
0
    def unit_create(self, owner_id, level, spec, target_id, direction):
        player = self.get_player(owner_id)

        if player == None:
            return None

        board = self.board_get(target_id)

        if board == None:
            return None

        retUnit = Unit.purchaseUnit(level, spec, player)

        self.log_action(
            "unit_create", owner_id=owner_id, level=level, spec=spec, target_id=target_id, direction=direction
        )

        if retUnit != None:
            if board.queueUnit(retUnit, direction):
                return retUnit

        return None
Example #17
0
    def volume(self, new_volume):
        """ Setting volume changes contents! """
        # get scalar to change absolute values of contents
        if not isinstance(new_volume, Unit):
            new_volume = Unit(new_volume)

        # find scalar to modify contents
        scalar = new_volume / self.volume

        # check to see if division worked correctly
        if not scalar.is_unitless():
            raise TypeError('New volume does not have compatible units!')

        # iterate through contents and modify
        for content in self.contents:
            if hasattr(content, 'volume'):
                content.volume = scalar * content._volume
            elif hasattr(content, 'mass'):
                content.mass = scalar * content._mass
                content.total_volume = new_volume
            elif hasattr(content, 'count'):
                content.count = scalar * content._count
            else:
                raise AttributeError('Object missing mass/volume attributes!')
Example #18
0
 def __init__(self):
     Unit.__init__(self, "s", "second", "seconds")
Example #19
0
    def __init__(self):
        self.scoreBoard = []
        self.termPC = None
        self.registers = {}

        for i in range(0, 32):
            self.registers['R' + str(i)] = {
                'value': 0,
                'result': None,
                'source': []
            }

        for i in range(0, 32):
            self.registers['F' + str(i)] = {
                'value': 0.0,
                'result': None,
                'source': []
            }

        self._units = {
            'FP adder': [],
            'FP Multiplier': [],
            'FP divider': [],
            'Integer': [],
            'Branch': [],
            'mAccess': []
        }

        self.memory = Memory()
        self._cache = {
            'I-Cache': Icache(self.memory),
            'D-Cache': Dcache(self.memory)
        }

        self._cache['I-Cache'].config(4, 4, 1)
        self._cache['D-Cache'].config(4, 4, 2)

        self._units['Integer'].append(
            Unit(uType='Integer',
                 regs=self.registers,
                 mem=self._cache['D-Cache'],
                 execTime=1))

        self._units['Branch'].append(
            Unit(uType='Branch',
                 regs=self.registers,
                 execTime=0,
                 continuePipeline=self._continuePipeline))
        self._units['mAccess'].append(
            Unit(uType='mAccess',
                 regs=self.registers,
                 mem=self._cache['D-Cache'],
                 execTime=1))

        self.clock = 0
        self.PC = 0
        self.branchPC = None
        self.halt = False
        self.IcacheLookAhead = False
        self.instructionHit = 0
        self._fetchQ = []
Example #20
0
 def __init__(self):
     Unit.__init__(self, "px", "pixel", "pixels")
Example #21
0
 def __init__(self):
     Unit.__init__(self, "f", "frame", "frames")
Example #22
0
    def draw(self,mouse_position,surface,color=GREEN,size=2):
        '''Draws the selection box on a given surface'''

        # Determine the min and max so that the x_len/y_len always draw correctly
        x1 = min(self.initial_position.x,mouse_position.x)
        y1 = min(self.initial_position.y,mouse_position.y)
        x2 = max(self.initial_position.x,mouse_position.x)
        y2 = max(self.initial_position.y,mouse_position.y)
        x_len = (x2 - x1)
        y_len = (y2 - y1)
        pygame.draw.rect(surface,color,[x1,y1,x_len,y_len],size)

        self.update((x1,y1,x2,y2))
       
soliders = [Unit(Vector(width/2,height/2)) for i in range(1)]

def game_loop():
    gameExit = False
    
    mouse_left_pressed = False
    selection_object   = None

    shift = False
    move_click = None
    
    while not gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True
Example #23
0
def transform_to_utils(inputVector):
    return [Unit(x, 0.0) for x in inputVector]
def test_targeting():
    a1 = Army([Unit(8, "Elf", "Veteran", "Heavy", "Flying")])
    a2 = Army([
        Unit(6, "Bugbear", "Green", "Light", "Infantry"),
        Unit(4, "Human", "Levies")
    ])
Example #25
0
 def molecular_weight(self,value):
     """ Molecular Weight Setter Property """
     self._molecular_weight = Unit(value) 
Example #26
0
 def mass(self,value):
     """ Mass Setter Property """
     self._mass = Unit(value)
     self.refresh_attributes('mass')
Example #27
0
 def moles(self,value):
     """ Moles Setter Property """
     self._moles = Unit(value)
     self.refresh_attributes('moles')
Example #28
0
 def concentration(self,value):
     """ Moles Setter Property """
     self._concentration = Unit(value)
     self.refresh_attributes('concentration')
Example #29
0
 def molarity(self,value):
     """ Molarity Setter Property """
     self._molarity = Unit(value)
     self.refresh_attributes('molarity')
Example #30
0
    def distance_to_steps(self, distance):
        """Return steps for the given distance.

		Note, returns float values that may have parital steps.
		"""
        return Unit(distance / float(self.effective_step_distance))
Example #31
0
def main():
    """
    The main method there the game runs in.
    """
    pygame.mixer.pre_init(44100, 16, 2, 4096)
    pygame.init()
    pygame.mixer.music.set_volume(.3)
    pygame.mixer.music.load('bgm.wav')
    pygame.mixer.music.play(-1)

    window_size = (window_width, window_height)
    global screen, held, turn, stage, empty_space, fps, fps_clock, element, hit, orb_movement
    fps = 30
    fps_clock = pygame.time.Clock()
    timer = 180
    held = False
    turn = 1
    stage = 1
    hit = pygame.mixer.Sound('hit.wav')
    hit.set_volume(1)
    orb_movement = pygame.mixer.Sound('orb_movement.wav')
    game_over = pygame.mixer.Sound('gameover.wav')

    screen = pygame.display.set_mode(window_size)
    pygame.display.set_caption("Project")

    screen.fill(WHITE)

    empty_space = Orb('BlankOrb.png', -1)

    # making units
    unit_row1_x = 150
    unit_row1_y = [50, 110, 170]
    unit_row2_x = 90
    unit_row2_y = [80, 140]

    unit_list = []
    hp = [4534, 6236, 6082, 5125, 4300]
    attack = [2540, 2710, 3810, 2700, 2960]
    recovery = [511, 295, 191, 372, 356]
    typing = [1, 2, 3, 4, 5]
    sprite = ['unit1.png', 'unit2.png', 'unit3.png', 'unit4.png', 'unit5.png']

    for x in range(5):
        unit_list.append(Unit(hp[x], attack[x], recovery[x],
                              typing[x], sprite[x]))

    # making enemies
    enemy_list = []
    hp = [1007988, 752364, 824658, 1048752, 1289554]
    attack = [7012, 15025, 9487, 10451, 17487]
    typing = [3, 4, 2, 1, 5]
    turns = [1,2,1,1,2]
    sprite = ['enemy1.png', 'enemy2.png', 'enemy3.png', 'enemy4.png', 'enemy5.png']

    for x in range(5):
        enemy_list.append(Monsters(hp[x], attack[x], typing[x], turns[x], sprite[x], x + 1))

    # background
    stage_list = []
    background_list = ['EmbodimentSDM.png', 'SMD.png', 'SDMLobby.png']
    for enemy in enemy_list:
        # print(enemy.stage)
        if enemy.stage == 1:
            stage_list.append(Stage(enemy.stage, background_list[0]))
        elif enemy.stage == 2 or enemy.stage == 3:
            stage_list.append(Stage(enemy.stage, background_list[1]))
        elif enemy.stage == 4 or enemy.stage == 5:
            stage_list.append(Stage(enemy.stage, background_list[2]))


    gameBoard = get_blank_board()
    gameBoard = fill_board(gameBoard, orb_pic)
    current_selected_orb = None

    # multipliers
    #--------------------------------------------------------#
    combo = 0
    combo_multiplier = .5
    extra_orb_multiplier = 1
    recovery_multiplier = .25
    leader_skill_multiplier = 25

    total_hp = 0
    for unit in unit_list:
        total_hp += unit.hp
    current_hp = total_hp

    fire = 0
    water = 0
    wood = 0
    light = 0
    dark = 0
    for unit in unit_list:
        if unit.type == 1:
            fire += unit.attack
        elif unit.type == 2:
            water += unit.attack
        elif unit.type == 3:
            wood += unit.attack
        elif unit.type == 4:
            light += unit.attack
        else:
            dark += unit.attack

    total_recovery = 0
    for unit in unit_list:
        total_recovery += unit.recovery


    # game loop
    # --------------------------------------------------------------------#
    while True:
        total_attacks = [0,0,0,0,0,0]
        swapping_orb = None
        combo = 0

        screen.fill(BLACK)
        mouse_coordinates = pygame.mouse.get_pos()
        for x in range(board_width):
            if x % 2 == 0:
                for y in range(board_height):
                    if y % 2 == 0:
                        pygame.draw.rect(screen, (110, 57, 58), board_rectangles[x][y], 0)
                    else:
                        pygame.draw.rect(screen, (150, 90, 91), board_rectangles[x][y], 0)
            elif x % 2 == 1:
                for y in range(board_height):
                    if y % 2 == 1:
                        pygame.draw.rect(screen, (110, 57, 58), board_rectangles[x][y], 0)
                    else:
                        pygame.draw.rect(screen, (150, 90, 91), board_rectangles[x][y], 0)

        # display background
        for background in stage_list:
            if background.stage == stage:
                display_background(stage, stage_list)


        for event in pygame.event.get():
            if event.type == QUIT:  # QUIT event to exit the game
                pygame.quit()
                sys.exit()

            # -----------Mouse Events----------- #
            if event.type == MOUSEBUTTONUP:
                num_orbs = 0
                held = False
                element = []
                match_orbs = check_match(gameBoard)
                num_orb_list = []
                if match_orbs == []: # no matching orbs
                    dmg_taken = enemy_list[stage - 1].attack_return(turn)
                    current_hp = update_hp_dmg(current_hp, dmg_taken)
                else:
                    while match_orbs != []:
                        for orb_set in match_orbs:
                            for orb in orb_set:
                                num_orbs += 1
                                draw_board(gameBoard)
                                pygame.display.update()
                                pygame.time.delay(30)
                            num_orb_list.append(num_orbs)
                            num_orbs = 0
                        gameBoard = get_falling_orbs(gameBoard)
                        match_orbs = check_match(gameBoard)

                    #---------------------------------------------------------------#
                    index = 0
                    for typing in element:
                        combo += 1
                        if typing == '1':
                            total_attacks[0] += fire + (fire * (num_orb_list[index]
                                                                * extra_orb_multiplier))
                            index += 1
                        elif typing == '2':
                            total_attacks[1] += water + (water * (num_orb_list[index]
                                                                  * extra_orb_multiplier))
                            index += 1
                        elif typing == '3':
                            total_attacks[2] += wood + (wood * (num_orb_list[index]
                                                                * extra_orb_multiplier))
                            index += 1
                        elif typing == '4':
                            total_attacks[3] += light + (light * (num_orb_list[index]
                                                                  * extra_orb_multiplier))
                            index += 1
                        elif typing == '5':
                            total_attacks[4] += dark + (dark * (num_orb_list[index]
                                                                * extra_orb_multiplier))
                            index += 1
                        else:
                            total_attacks[5] += total_recovery + (total_recovery
                                             * (num_orb_list[index] * extra_orb_multiplier))
                            index += 1


                    for x in range(6):
                        if x == 0:
                            total_attacks[x] += (combo_multiplier * combo) * total_attacks[x]
                        elif x == 1:
                            total_attacks[x] += (combo_multiplier * combo) * total_attacks[x]
                        elif x == 2:
                            total_attacks[x] += (combo_multiplier * combo) * total_attacks[x]
                        elif x == 3:
                            total_attacks[x] += (combo_multiplier * combo) * total_attacks[x]
                        elif x == 4:
                            total_attacks[x] += (combo_multiplier * combo) * total_attacks[x]
                        else:
                            total_attacks[x] += (combo_multiplier * combo) * total_attacks[x]

                    enemy_list[stage - 1].update_hp(total_attacks)
                    current_hp = update_hp_rcv(current_hp, total_hp, total_attacks[5])
                    if enemy_list[stage - 1].current_hp != 0:
                        dmg_taken = enemy_list[stage - 1].attack_return(turn)
                        current_hp = update_hp_dmg(current_hp, dmg_taken)



                    for x in range(6):
                        print(total_attacks[x])



            elif event.type == MOUSEBUTTONDOWN:
                held = True
                timer = 180
                current_selected_orb = check_orb_clicked(mouse_coordinates)

            # ---------------------------------- #

        # if holding down mouse 1
        if held:
            timer -= 1
            if timer == 0:
                held = False # 6 seconds to make move
                gameBoard[current_selected_orb['x']][current_selected_orb['y']] = current_orb_copy

            if timer == 179:
                current_orb_copy = gameBoard[current_selected_orb['x']][current_selected_orb['y']]

            gameBoard[current_selected_orb['x']][current_selected_orb['y']] = empty_space
            current_orb_copy.update(screen)
            if current_selected_orb['x']+1 < 6 and current_selected_orb['y']+1 < 5:
                if(board_rectangles[current_selected_orb['x']+1]
                   [current_selected_orb['y']].collidepoint(mouse_coordinates[0],
                                                            mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)
                elif(board_rectangles[current_selected_orb['x']-1]
                     [current_selected_orb['y']].collidepoint(mouse_coordinates[0],
                                                              mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)
                elif(board_rectangles[current_selected_orb['x']]
                     [current_selected_orb['y']-1].collidepoint(mouse_coordinates[0],
                                                                mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)
                elif(board_rectangles[current_selected_orb['x']]
                     [current_selected_orb['y']+1].collidepoint(mouse_coordinates[0],
                                                                mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)

            elif current_selected_orb['x'] == 5 and current_selected_orb['y'] == 4:
                if(board_rectangles[current_selected_orb['x']-1]
                   [current_selected_orb['y']].collidepoint(mouse_coordinates[0],
                                                            mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)
                elif(board_rectangles[current_selected_orb['x']]
                     [current_selected_orb['y']-1].collidepoint(mouse_coordinates[0],
                                                                mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)

            elif current_selected_orb['x'] == 5:
                if(board_rectangles[current_selected_orb['x']-1]
                   [current_selected_orb['y']].collidepoint(mouse_coordinates[0],
                                                            mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)
                elif(board_rectangles[current_selected_orb['x']]
                     [current_selected_orb['y']+1].collidepoint(mouse_coordinates[0],
                                                                mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)
                elif(board_rectangles[current_selected_orb['x']]
                     [current_selected_orb['y']-1].collidepoint(mouse_coordinates[0],
                                                                mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)

            elif current_selected_orb['y'] == 4:
                if(board_rectangles[current_selected_orb['x']+1]
                   [current_selected_orb['y']].collidepoint(mouse_coordinates[0],
                                                            mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)
                elif(board_rectangles[current_selected_orb['x']-1]
                     [current_selected_orb['y']].collidepoint(mouse_coordinates[0],
                                                              mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)
                elif(board_rectangles[current_selected_orb['x']]
                     [current_selected_orb['y']-1].collidepoint(mouse_coordinates[0],
                                                                mouse_coordinates[1])):
                    swapping_orb = check_orb_clicked(mouse_coordinates)
                    gameBoard = swap_orbs(gameBoard, current_selected_orb, swapping_orb)
                    current_selected_orb = check_orb_clicked(mouse_coordinates)
                    pygame.mixer.Sound.play(orb_movement)


        # displays unit sprites on the screen
        #---------------------------------------------------------#
        k = 0
        for unit in unit_list:
            unit.update(screen, (unit_row1_x, unit_row1_y[k]))
            k += 1
            if k == 3:
                k = 0
                break

        l = 0
        m = 0
        for unit in unit_list:
            l += 1
            if l > 3:
                unit.update(screen, (unit_row2_x, unit_row2_y[m]))
                m += 1

        #---------------------------------------------------------#
        if enemy_list[stage - 1].current_hp <= 0:
            stage += 1
            font = pygame.font.SysFont('arialblack', 15)
            text = font.render(str(stage), True, BLACK)
            screen.blit(text, (window_width/2.4 , y_margin - 200))
            pygame.time.delay(60)


        display_enemy(screen, stage, turn, enemy_list)

        draw_hp(screen, current_hp, total_hp)

        draw_board(gameBoard)

        if current_hp < 0:
            pygame.mixer.Sound.play(game_over)
            pygame.mixer.music.pause()
            pygame.display.update()
            current_hp = 0

        if current_hp == 0:
            display_message()


        if held:
            font = pygame.font.SysFont('arialblack', 12)
            text = font.render(str(int(timer / 30) + 1), True, BLACK)
            screen.blit(text, (mouse_coordinates[0] - 10, mouse_coordinates[1] - 10))
        pygame.display.update()  # Update the display when all events have been processed
        fps_clock.tick(fps)
Example #32
0
 def __init__(self):
     Unit.__init__(self, "m", "meter", "meters")
Example #33
0
 def use(self, target: Unit):
     Skill.use(self, target)
     if target.hp < target.max_hp:
         target.hp += self.modification_value
     if target.hp > target.max_hp:
         target.hp = target.max_hp