示例#1
0
 def use(self):
     #just call the "use_fucntion" if it is defined
     if self.use_function is None:
         print_message('The ' + self.owner.name + ' cannot be used.')
     else:
         if self.use_function() != 'cancelled':
             g.inventory.remove(self.owner)
示例#2
0
    def unequip(self):
        """Unequip item and distract bonuses"""

        # TODO 2 If's HACKY
        # Try if Equipment self is in the first possible slot
        if g.player.fighter.equipment_slots[self.slot] == self:

            g.player.fighter.equipment_slots[self.slot] = 'unequipped'
            g.player.fighter.equipment_slots[self.slot_block] = 'unequipped'
            self.equipped = False

            # Distract bonuses
            self.set_item_bonuses(g.player, -1)

            if self.slot_block != 'nothing':
                g.player.fighter.equipment_slots[
                    self.slot_block] = 'unequipped'

            print_message("item unequipped", colors.yellow)

        # Try slot 2
        elif g.player.fighter.equipment_slots[self.slot2] == self:

            g.player.fighter.equipment_slots[self.slot2] = 'unequipped'
            self.equipped = False

            # Distract bonuses
            self.set_item_bonuses(g.player, -1)

            print_message("item unequipped", colors.yellow)
示例#3
0
def prompt(turn):
	if turn==1:
		message= "Machine Won!"
		print("Machine Won!")
		Analyses_Module.end_time=time.clock()
		if Option.opt==2:
			Analyses_Module.R4=Analyses_Module.end_time-Analyses_Module.start_time
			Analyses_Module.R5=Analyses_Module.R1/(Analyses_Module.R4*1000000)
			analyses_obj.write_minimax()
			Analyses_Module.start_time=time.clock()
			Analyses_Module.R1=0
		if Option.opt==3:
			Analyses_Module.end_time=time.clock()
			Analyses_Module.R8=Analyses_Module.end_time-Analyses_Module.start_time
			Analyses_Module.R7=float(float(503589-Analyses_Module.R6)/float(503589))
			analyses_obj.write_AB()
			Analyses_Module.start_time=time.clock()
			Analyses_Module.R6=0
	else:
		message= "You won!"
		print ("You won!")
	print_message(message)
	choice=bottom_screen()
	screen=turtle.Screen()
	screen.onclick(decide)
示例#4
0
    def take_turn(self):
        if self.num_turns > 0:  # still confused...
            # move in a random direction, and decrease the number of turns confused
            self.owner.move(randint(-1, 1), randint(-1, 1))
            self.num_turns -= 1

        else:  # restore the previous AI (this one will be deleted because it's not referenced anymore)
            self.owner.ai = self.old_ai
            print_message('The ' + self.owner.name + ' is no longer confused!',
                          colors.red)
示例#5
0
    def drop(self, new_x=None, new_y=None):
        # TODO Use new_x, new_y?
        # Drop Item

        self.owner.x = g.player.x
        self.owner.y = g.player.y

        g.item_group.add(self.owner)
        g.inventory.remove(self.owner)

        print_message(self.owner.name + " dropped!", colors.darkest_turquoise)
示例#6
0
    def pick_up(self):
        #add to the player's inventory and remove from the map
        if len(g.inventory) >= 26:
            print_message(
                'Your inventory is full, cannot pick up ' + self.owner.name +
                '.', colors.red)
        else:
            g.inventory.add(self.owner)
            g.item_group.remove(self.owner)

            print_message('You picked up a ' + self.owner.name + '!',
                          colors.green)
示例#7
0
    def attack(self, target):
        # a simple formula for attack damage
        # TODO damage_calc
        damage = self.power - target.fighter.defense

        if damage > 0:
            # make the target take some damage
            print_message(self.owner.name.capitalize() + ' attacks ' +
                          target.name + ' for ' + str(damage) + ' hit points.')
            target.fighter.take_damage(damage)
        else:
            print_message(self.owner.name.capitalize() + ' attacks ' +
                          target.name + ' but it has no effect!')
示例#8
0
    def equip(self):
        """Equip item and add bonuses"""

        # Check if Slot is unequipped and blocked slot isnt already blocked
        if g.player.fighter.equipment_slots[self.slot] == 'unequipped' and \
            g.player.fighter.equipment_slots[self.slot_block] == 'unequipped':

            g.player.fighter.equipment_slots[
                self.slot] = self  #self.owner.name
            self.equipped = True

            # Add bonuses
            self.set_item_bonuses(g.player, 1)

            # If a slot will be blocked, add self to blocked slot
            if self.slot_block != 'blocked':
                g.player.fighter.equipment_slots[self.slot_block] = self

            print_message("item equipped", colors.green)

        # Try Slot 2
        elif self.slot2 != 'nothing':
            if g.player.fighter.equipment_slots[self.slot2] == 'unequipped':
                g.player.fighter.equipment_slots[self.slot2] = self
                self.equipped = True

                # Add bonuses
                self.set_item_bonuses(g.player, 1)

                print_message("item equipped", colors.green)

        else:
            print_message("slot occupied", colors.red)
示例#9
0
def run_game():
    #Initialize game and create a screen object.
    pygame.init()
    settings = Settings()
    g.settings = Settings()

    g.settings_g = Settings()

    pygame.display.set_caption(settings.title)

    # Initialize Map
    grid = Grid(settings)
    g.tiles = Group()

    # Map Matrix initialisieren und Tiles hinzufügen
    tiles_init(settings, g.tiles)

    #Player
    fighter_comp = Fighter(hp=30,
                           defense=2,
                           power=5,
                           death_function=gf.player_death)
    g.player = GameObject(settings,
                          "player",
                          1,
                          1,
                          colors.gold,
                          img=r.player,
                          blocks=True,
                          fighter=fighter_comp)

    # Create Random Map
    make_map()

    # Initialize GUI and Inventory
    g.gui_elements = GUI(settings)
    g.inventory_menu = InventoryMenu(settings)

    #Print Welcome Message
    print_message("Welcome to the BEIDL", colors.black, colors.dark_red)

    #Initialize groups
    g.monster_group = Group()
    g.item_group = Group()
    g.dead_group = Group()
    g.inventory = Group()
    g.graphics_group = Group()
    """F**K AROUND"""
    #vvvvvvvvvvv#

    for i in range(10):
        testi_place_objects('item')

    for i in range(50):
        testi_place_objects('enemy')

    # """Test: Dummy Walls"""
    # g.map_matrix[4][5].blocked = True
    # g.map_matrix[4][5].block_sight = True
    # g.map_matrix[4][6].blocked = True
    # g.map_matrix[4][6].block_sight = True
    #
    # g.map_matrix[15][21].blocked = True
    # g.map_matrix[15][21].block_sight = True
    # g.map_matrix[16][21].blocked = True
    # g.map_matrix[16][21].block_sight = True

    #^^^^^^^^^#
    """F**K AROUND"""

    # Start the main loop for the game.
    while True:
        """MENU"""
        # Menu Screen
        #while settings.game_state == "menu":
        #gf.check_events_menu(settings, all_groups)
        #gf.update_screen_menu(settings, all_groups)
        """GAME"""
        #while g.game_state == "playing":
        while True:

            g.clock.tick(FPS)
            # ticks = pygame.time.get_ticks()

            gf.update_screen(settings)

            # Check game_state for Contol Setup
            # TODO game state control handling like this?
            if g.game_state == 'inventory':
                player_action = gf.controls_inventory(settings)
            else:
                player_action = gf.controls(settings, g.player)

            # Let Enemys take turns
            if g.game_state == 'playing' and player_action != "noturn":
                for obj in g.monster_group:
                    if obj.ai:
                        obj.ai.take_turn()

            # TODO Turn for using inventory item, redundant, use in game state?
            if player_action == "turn":
                for obj in g.monster_group:
                    if obj.ai:
                        obj.ai.take_turn()