From 5b2166aea31ebbec3eb8186f781a95b0a133fd50 Mon Sep 17 00:00:00 2001 From: sotiris sapakos Date: Fri, 13 Jul 2018 09:39:03 +0300 Subject: [PATCH 1/3] Subrooms class Create subrooms class --- SubRooms.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 SubRooms.py diff --git a/SubRooms.py b/SubRooms.py new file mode 100644 index 0000000..b533cd9 --- /dev/null +++ b/SubRooms.py @@ -0,0 +1,66 @@ +import Items + + +class GenericSubroom: + + """ Generic class for subrooms """ + + items = [] + + def __init__(self): + # nothing special to initialize! + pass + + +class Subroom1(GenericSubroom): + + def __init__(self): + super().__init__() + + self.items = [Items.HEALTH_POT, + Items.HEALTH_POT] + + +class Subroom2(GenericSubroom): + + def __init__(self): + super().__init__() + + self.items = [Items.HEALTH_POT, + Items.RECOVERY] + + +class Subroom3(GenericSubroom): + + def __init__(self): + super().__init__() + + self.items = [Items.IRON_SWORD, + Items.LEATHER_SHIELD] + + +class Subroom4(GenericSubroom): + + def __init__(self): + super().__init__() + + self.items = [Items.GRAND_AXE, + Items.LONG_BOW] + + +class Subroom5(GenericSubroom): + + def __init__(self): + super().__init__() + + self.items = [Items.RECOVERY, + Items.SCALE_SHIELD] + + +class Subroom6(GenericSubroom): + + def __init__(self): + super().__init__() + + self.items = [Items.HOLY_WATER, + Items.HEALTH_POT] From 0486feb4bd3cb66a9c4009d70194babff31a97ad Mon Sep 17 00:00:00 2001 From: sotiris sapakos Date: Fri, 13 Jul 2018 10:19:09 +0300 Subject: [PATCH 2/3] Added subrooms in rooms * Added subrooms in rooms * methods that only superclass uses become private --- Rooms.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Rooms.py b/Rooms.py index 64596da..1153d07 100644 --- a/Rooms.py +++ b/Rooms.py @@ -1,5 +1,6 @@ from MapEntity import Door, Barrier, SpaceObject from Characters.Enemies import Goblin, Hobgoblin, Bugbear +from SubRooms import * class Room: @@ -8,6 +9,13 @@ class Room: enemies = [] barriers = [] + # subrooms usage: + # ------------------------ + # First position of subrooms(list) is the subroom for the top placed door in the map + # Second position is the subroom for the bottom placed door in the map + # ------------------------ + subrooms = [] + def __init__(self, width, height): self.width = width self.height = height @@ -17,11 +25,11 @@ def create_room(self): """ Generate/Create the room. """ - self.place_doors() - self.place_enemies() - self.print_room() + self.__place_doors() + self.__place_enemies() + self.__print_room() - def print_room(self): + def __print_room(self): """ Print the room as string for the user to see. """ @@ -36,14 +44,14 @@ def print_room(self): print(" ".join(helper_line)) - def place_doors(self): + def __place_doors(self): """ Automatically place the doors on the map. """ for door in self.doors: self.room_table[door.position.x][door.position.y] = "=" - def place_enemies(self): + def __place_enemies(self): """ Automatically place the enemies on the map. """ @@ -63,7 +71,6 @@ def place_barriers_near_door(self, door): if door.position.x == self.width-1 or door.position.x == 0: if door.position.x == 0: # this is subroom1 door... - # TODO: add a class for subroom pass else: # this is subroom2 door... @@ -95,7 +102,10 @@ def __init__(self, width, height): self.enemies = [Goblin(10, width-2), Goblin(9, width-2)] - self.place_barriers_near_door(self.doors[2]) + self.subrooms = [Subroom1(), + Subroom2()] + + self.place_barriers_near_door(self.doors[0]) self.create_room() @@ -112,6 +122,9 @@ def __init__(self, width, height): self.enemies = [Goblin(1, 12), Goblin(height-2, 11)] + self.subrooms = [Subroom3(), + Subroom4()] + self.place_barriers_near_door(self.doors[0]) self.place_barriers_near_door(self.doors[1]) @@ -130,6 +143,9 @@ def __init__(self, width, height): self.enemies = [Hobgoblin(height-2, 11), Bugbear(10, width-2)] + self.subrooms = [Subroom5(), + Subroom6()] + self.place_barriers_near_door(self.doors[1]) self.place_barriers_near_door(self.doors[2]) From 5125836f0f50900f33595fc1a86e685654bdd691 Mon Sep 17 00:00:00 2001 From: sotiris sapakos Date: Fri, 13 Jul 2018 14:27:16 +0300 Subject: [PATCH 3/3] Character class create character class --- Characters/Heroes.py | 46 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/Characters/Heroes.py b/Characters/Heroes.py index 3a72686..6edd3a4 100644 --- a/Characters/Heroes.py +++ b/Characters/Heroes.py @@ -13,10 +13,18 @@ def __init__(self, x, y, base_speed=40, base_attack=20, base_defense=10, base_hp self.inventory = Inventory() self.equipped_items = [None] * 2 # [0] -> Primary || [1] -> Secondary - # Initial stats calculation + self.calculate_stats() + + def drop_items(self, equipped_items_number): + """ + Remove item from equipped item + :param equipped_items_number: the primary or secondary inventory (0: primary, 1: secondary) + """ + self.equipped_items.remove(self.equipped_items[equipped_items_number]) self.calculate_stats() def modify_health(self, amount): + """ Modify the players health (Heal or damage) :param amount: Amount of health points to increase/decrease @@ -25,26 +33,32 @@ def modify_health(self, amount): if self.current_hp > self.max_hp: self.current_hp = self.max_hp elif self.current_hp <= 0: - pass # TODO: Kill the Character + self.kill() # TODO: Kill the Character def attack(self, other): pass def use_item(self, item: Items.Item): + """ Uses a specific item and removes it from the inventory :param item: Item to be used """ if isinstance(item, Items.ItemHealing): self.modify_health(item.value) - self.inventory.rem_item(item, 1) # TODO: Remove item from inventory + self.inventory.rem_item(item, 1) # TODO: Remove item from inventory (Κατάργηση στοιχείου από το απόθεμα) else: - pass # TODO: Check for other items that can be used from the inventory + # TODO: Check for other items that can be used from the inventory + pass def calculate_stats(self): """ Calculate attack and speed statistics for the hero. """ + + self.current_attack = self.base_attack + self.current_speed = self.base_speed + for item in self.equipped_items: if item is None: continue @@ -67,6 +81,17 @@ def __init__(self, x, y): self.calculate_stats() +class Dwarves(GenericHero): + name = "Dwarves" + + def __init__(self, x, y): + super.__init__(x, y, 20, 30, 30, 30) + self.inventory.add_item(Items.HEALTH_POT, 2) + self.equipped_items[0] = Items.HUNTERS_AXE + self.equipped_items[1] = Items.WOODEN_SHIELD + self.calculate_stats() + + class Elf(GenericHero): name = "Elf" @@ -76,4 +101,15 @@ def __init__(self, x, y): self.inventory.add_item(Items.MEDICAL_HERB, 2) self.equipped_items[0] = Items.STANDARD_BOW self.equipped_items[1] = Items.WOODEN_SHIELD - self.calculate_stats() \ No newline at end of file + self.calculate_stats() + + +class Orcs(GenericHero): + name = "Orcs" + + def __init__(self, x, y): + super.__init__(x, y, 30, 35, 25, 35) + self.inventory.add_item(Items.MEDICAL_HERB, 3) + self.equipped_items[0] = Items.OLD_AXE + self.equipped_items[1] = Items.RUSTED_SHIELD + self.calculate_stats()