Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions Characters/Heroes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"

Expand All @@ -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()
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()
32 changes: 24 additions & 8 deletions Rooms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from MapEntity import Door, Barrier, SpaceObject
from Characters.Enemies import Goblin, Hobgoblin, Bugbear
from SubRooms import *


class Room:
Expand All @@ -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
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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...
Expand Down Expand Up @@ -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()

Expand All @@ -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])

Expand All @@ -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])

Expand Down
66 changes: 66 additions & 0 deletions SubRooms.py
Original file line number Diff line number Diff line change
@@ -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]