Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Characters #14

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
28 changes: 28 additions & 0 deletions server/Characters/Architect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from CharactersList import CharactersList
from server.Characters.Character import Character
from server.District import DistrictsList


class Architect(Character):

def __init__(self):
super().__init__(CharactersList.Architect)
self.choose_character = None
self.text = "After you take an action, you draw two additional district cards and put both in your hand."

def action(self, character_name):
"""The action of this character"""
self.choose_character = character_name

def get_progress_information(self, list_of_cards):
"""Print info of this action"""
return super(Architect, self).get_progress_information(self).format("You receive {} {}").format(
Copy link
Member Author

@Arrgentum Arrgentum Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chxen help me with callback in super class pls

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

", ".join([list_of_cards[i].name for i in range(len(list_of_cards) - 1)]),
str(list_of_cards[len(list_of_cards) - 1].name))

def get_info(self):
"""Print info of this character"""
return super(Architect, self).get_info(self).format(self.character_name, self.text)


# print(Architect().get_progress_information(DistrictsList.take_the_cards(3)))
3 changes: 2 additions & 1 deletion server/Characters/Assassin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ class Assassin(Character):
def __init__(self):
super().__init__(CharactersList.Assassin)
self.choose_character = None
self.text = "Choose any character and kill him"

def action(self, character_name):
"""The action of this character"""
self.choose_character = character_name

def get_progress_information(self):
def get_progress_information(self, districts_in_hand=None):
"""Print info of this action"""
return super(Assassin, self).get_progress_information(self).format("kill {}").format(self.choose_character)

Expand Down
11 changes: 6 additions & 5 deletions server/Characters/Bishop.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from CharactersList import CharactersList
from server.Characters.Character import Character
from server.District import DistrictTypeList


class Bishop(Character):

def __init__(self):
super().__init__(CharactersList.Assassin)
super().__init__(CharactersList.Bishop)
self.text = "You receive one gold for each religious (blue) district in your city."

def action(self, character_name=None):
"""The action of this character"""

def get_progress_information(self):
def get_progress_information(self, districts_in_hand):
"""Print info of this action"""
return super(Bishop, self).get_progress_information(self).format("You receive {} gold").format()
return super(Bishop, self).get_progress_information(self).format("You receive {} gold").format(len(list(filter(lambda x: x.value.type_of_district == DistrictTypeList.Religious, districts_in_hand))))

def get_info(self):
"""Print info of this character"""
return super(Bishop, self).get_info(self).format(self.character_name, "You receive one gold for each "
"religious (blue) district in your city.")
return super(Bishop, self).get_info(self).format(self.character_name, self.text)
1 change: 0 additions & 1 deletion server/Characters/CharactersList.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import random
from enum import Enum
from random import randrange


class CharactersList(Enum):
Expand Down
9 changes: 7 additions & 2 deletions server/Characters/King.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from CharactersList import CharactersList
from server.Characters.Character import Character
from server.District import DistrictTypeList, DistrictsList


class King(Character):
Expand All @@ -17,10 +18,14 @@ def action(self, character_name):
"""The action of this character"""
pass

def get_progress_information(self):
def get_progress_information(self, districts_in_hand):
"""Print info of this action"""
return super(King, self).get_progress_information(self).format("must be strong")
return super(King, self).get_progress_information(self).format("You receive {} gold").format(
len(list(filter(lambda x: x.value.type_of_district == DistrictTypeList.Noble, districts_in_hand))))

def get_info(self):
"""Print info of this character"""
return super(King, self).get_info(self).format(self.character_name, self.text)


print(King().get_progress_information(DistrictsList.take_the_cards(4)))
20 changes: 20 additions & 0 deletions server/Characters/Merchant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from CharactersList import CharactersList
from server.Characters.Character import Character
from server.District import DistrictTypeList


class Merchant(Character):

def __init__(self):
super().__init__(CharactersList.Assassin)

def action(self, character_name=None):
"""The action of this character"""

def get_progress_information(self, districts_in_hand):
"""Print info of this action"""
return super(Merchant, self).get_progress_information(self).format("You receive {} gold").format(len(list(filter(lambda x: x.value.type_of_district == DistrictTypeList.Trade, districts_in_hand))))

def get_info(self):
"""Print info of this character"""
return super(Merchant, self).get_info(self).format(self.character_name, "You receive one gold for each trade (green)district in your city")
5 changes: 3 additions & 2 deletions server/Characters/Thief.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ class Thief(Character):
def __init__(self):
super().__init__(CharactersList.Thief)
self.choose_character = None
self.text = "choose any character and rob him"

def action(self, character_name):
"""The action of this character"""
self.choose_character = character_name

def get_progress_information(self):
def get_progress_information(self, districts_in_hand=None):
"""Print info of this action"""
return super(Thief, self).get_progress_information(self).format("rob {}").format(self.choose_character)

def get_info(self):
"""Print info of this character"""
return super(Thief, self).get_info(self).format(self.character_name, "choose any character and rob him")
return super(Thief, self).get_info(self).format(self.character_name, self.text)

34 changes: 34 additions & 0 deletions server/Characters/Warlord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from CharactersList import CharactersList
from server.Characters.Character import Character
from server.District import DistrictTypeList


class Warlord(Character):

def __init__(self):
super().__init__(CharactersList.Warlord)
self.choose_character = None
self.text = """You receive one gold for each military (red)
district in your city. At the end of your turn, you
may destroy one district of your choice by paying
a number of gold equal to one less than the cost
of the district. Thus, you may destroy a cost one
district for free, a cost two district for one gold,
or a cost six district for five gold, etc. You may
destroy one of your own districts. You may not,
however, destroy a district in a city that is already
completed by having eight districts (or seven
districts when the Bell Tower is in play)."""

def action(self, character_name):
"""The action of this character"""
self.choose_character = character_name

def get_progress_information(self, districts_in_hand):
"""Print info of this action"""
return super(Warlord, self).get_progress_information(self).format("You receive {} gold").format(len(list(filter(lambda x: x.value.type_of_district == DistrictTypeList.Religious, districts_in_hand))))

def get_info(self):
"""Print info of this character"""
return super(Warlord, self).get_info(self).format(self.character_name, self.text)

48 changes: 48 additions & 0 deletions server/District.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import random
from enum import Enum


class DistrictTypeList(Enum):
Bonus = 0
Military = 1
Church = 2
Noble = 3
Trade = 4


class District(object):
"""Is a Basic character class"""

def __init__(self, name, type_of_district, price, quantity):
"""Constructor"""
self.name = name
self.type_of_district = type_of_district
self.price = price
self.quantity = quantity


class DistrictsList(Enum):
Watchtower = District("watchtower", DistrictTypeList.Military, 1, 3)
Prison = District("prison", DistrictTypeList.Military, 2, 3)
The_Field_of_Mars = District("the Field of Mars", DistrictTypeList.Military, 3, 3)
Fortress = District("fortress", DistrictTypeList.Military, 5, 2)

Temple = District("temple", DistrictTypeList.Church, 1, 3)
Church = District("church", DistrictTypeList.Church, 2, 3)
Monastery = District("monastery", DistrictTypeList.Church, 3, 3)
Cathedral = District("cathedral", DistrictTypeList.Church, 5, 2)

Estate = District("estate", DistrictTypeList.Noble, 3, 5)
Castle = District("castle", DistrictTypeList.Noble, 4, 4)
Palazzo = District("castle", DistrictTypeList.Noble, 5, 3)

Tavern = District("tavern", DistrictTypeList.Trade, 1, 5)
Market = District("market", DistrictTypeList.Trade, 2, 4)
Shop = District("shop", DistrictTypeList.Trade, 2, 3)
Port = District("port", DistrictTypeList.Trade, 3, 3)
Harbor = District("harbor", DistrictTypeList.Trade, 4, 3)
Guildhall = District("guildhall", DistrictTypeList.Trade, 5, 2)

@staticmethod
def take_the_cards(number=1, type_of_district=None):
return random.choices([i for i in DistrictsList if (type_of_district is None or i.value.type_of_district == type_of_district)], k=number)
14 changes: 12 additions & 2 deletions server/Player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@


class Player(object):

def __init__(self, player_name):
self.character = Character(None)
self.player_name = player_name
self.districts_in_hand = []
self.districts_in_table = []

def choose_character(self, character):
self.character = character
Expand All @@ -14,4 +15,13 @@ def get_info(self):
pass

def get_progress_information(self):
pass
return self.character.get_progress_information(self, self.districts_in_table)

def get_districts_in_hand(self, list_of_districts):
self.districts_in_hand.extend(list_of_districts)

def put_cards_on_the_table(self, districts):
self.districts_in_table.extend(set(districts))
for district in districts:
self.districts_in_hand.remove(district)