Linting
This commit is contained in:
parent
e1918ab066
commit
0394c5d15d
|
@ -54,31 +54,32 @@ class Sunflower(FriendlyEntity):
|
||||||
"""
|
"""
|
||||||
return [_("Flower power!!"), _("The sun is warm today")]
|
return [_("Flower power!!"), _("The sun is warm today")]
|
||||||
|
|
||||||
|
|
||||||
class Familiar(FightingEntity):
|
class Familiar(FightingEntity):
|
||||||
"""
|
"""
|
||||||
A friendly familiar that helps the player defeat monsters.
|
A friendly familiar that helps the player defeat monsters.
|
||||||
"""
|
"""
|
||||||
def __init__(self, maxhealth: int = 25,
|
def __init__(self, maxhealth: int = 25,
|
||||||
*args, **kwargs) -> None:
|
*args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(maxhealth=maxhealth, *args, **kwargs)
|
||||||
self.target = None
|
self.target = None
|
||||||
def act(self, p: Player, m : Map) :
|
|
||||||
|
def act(self, p: Player, m: Map) -> None:
|
||||||
"""
|
"""
|
||||||
By default, the familiar tries to stay at distance at most 2 of the
|
By default, the familiar tries to stay at distance at most 2 of the
|
||||||
player and if a monster comes in range 3, it focuses on the monster
|
player and if a monster comes in range 3, it focuses on the monster
|
||||||
and attacks it.
|
and attacks it.
|
||||||
"""
|
"""
|
||||||
if self.target == None:
|
if self.target is None:
|
||||||
self.target = p
|
self.target = p
|
||||||
if self.target == p:
|
if self.target == p:
|
||||||
for entity in m.entities:
|
for entity in m.entities:
|
||||||
if (self.y - entity.y) ** 2 + (self.x - entity.x) ** 2 <= 9 and \
|
if (self.y - entity.y) ** 2 + (self.x - entity.x) ** 2 <= 9 and\
|
||||||
isinstance(entity, Monster):
|
isinstance(entity, Monster):
|
||||||
self.target = entity
|
self.target = entity
|
||||||
entity.paths = dict() #Allows the paths to be calculated.
|
entity.paths = dict() # Allows the paths to be calculated.
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
# Familiars move according to a Dijkstra algorithm
|
# Familiars move according to a Dijkstra algorithm
|
||||||
# that targets their target.
|
# that targets their target.
|
||||||
# If they can not move and are already close to their target,
|
# If they can not move and are already close to their target,
|
||||||
|
@ -90,9 +91,9 @@ class Familiar(FightingEntity):
|
||||||
if moved:
|
if moved:
|
||||||
break
|
break
|
||||||
if self.distance_squared(self.target) <= 1 and \
|
if self.distance_squared(self.target) <= 1 and \
|
||||||
not isinstance(self.target, Player):
|
not isinstance(self.target, Player):
|
||||||
self.map.logs.add_message(self.hit(self.target))
|
self.map.logs.add_message(self.hit(self.target))
|
||||||
if self.target.dead :
|
if self.target.dead:
|
||||||
self.target.paths = None
|
self.target.paths = None
|
||||||
self.target = None
|
self.target = None
|
||||||
break
|
break
|
||||||
|
@ -106,7 +107,8 @@ class Familiar(FightingEntity):
|
||||||
if move():
|
if move():
|
||||||
break
|
break
|
||||||
|
|
||||||
class Trumpet(Familiar) :
|
|
||||||
|
class Trumpet(Familiar):
|
||||||
"""
|
"""
|
||||||
A class of familiars.
|
A class of familiars.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -60,13 +60,15 @@ class Monster(FightingEntity):
|
||||||
for move in moves:
|
for move in moves:
|
||||||
if move():
|
if move():
|
||||||
break
|
break
|
||||||
def move(self, y: int, x:int) -> None:
|
|
||||||
|
def move(self, y: int, x: int) -> None:
|
||||||
"""
|
"""
|
||||||
Overwrites the move function to recalculate paths.
|
Overwrites the move function to recalculate paths.
|
||||||
"""
|
"""
|
||||||
super().move(y, x)
|
super().move(y, x)
|
||||||
self.recalculate_paths()
|
self.recalculate_paths()
|
||||||
|
|
||||||
|
|
||||||
class Tiger(Monster):
|
class Tiger(Monster):
|
||||||
"""
|
"""
|
||||||
A tiger monster.
|
A tiger monster.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from random import randint
|
from random import randint
|
||||||
from typing import Dict, Tuple
|
|
||||||
|
|
||||||
from ..interfaces import FightingEntity, InventoryHolder
|
from ..interfaces import FightingEntity, InventoryHolder
|
||||||
|
|
||||||
|
|
|
@ -63,9 +63,9 @@ class Map:
|
||||||
"""
|
"""
|
||||||
Registers a new entity in the map.
|
Registers a new entity in the map.
|
||||||
"""
|
"""
|
||||||
if entity.is_familiar() :
|
if entity.is_familiar():
|
||||||
self.entities.insert(1,entity)
|
self.entities.insert(1, entity)
|
||||||
else :
|
else:
|
||||||
self.entities.append(entity)
|
self.entities.append(entity)
|
||||||
entity.map = self
|
entity.map = self
|
||||||
|
|
||||||
|
@ -100,7 +100,8 @@ class Map:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(filename: str) -> "Map":
|
def load(filename: str) -> "Map":
|
||||||
"""
|
"""
|
||||||
Reads a file that contains the content of a map, and builds a Map object.
|
Reads a file that contains the content of a map,
|
||||||
|
and builds a Map object.
|
||||||
"""
|
"""
|
||||||
with open(filename, "r") as f:
|
with open(filename, "r") as f:
|
||||||
file = f.read()
|
file = f.read()
|
||||||
|
@ -162,7 +163,7 @@ class Map:
|
||||||
for entity in self.entities:
|
for entity in self.entities:
|
||||||
if entity.is_familiar():
|
if entity.is_familiar():
|
||||||
entity.act(p, self)
|
entity.act(p, self)
|
||||||
else :
|
else:
|
||||||
entity.act(self)
|
entity.act(self)
|
||||||
|
|
||||||
def save_state(self) -> dict:
|
def save_state(self) -> dict:
|
||||||
|
@ -307,7 +308,7 @@ class Entity:
|
||||||
Uses Dijkstra algorithm to calculate best paths for other entities to
|
Uses Dijkstra algorithm to calculate best paths for other entities to
|
||||||
go to this entity. If self.paths is None, does nothing.
|
go to this entity. If self.paths is None, does nothing.
|
||||||
"""
|
"""
|
||||||
if self.paths == None :
|
if self.paths is None:
|
||||||
return
|
return
|
||||||
distances = []
|
distances = []
|
||||||
predecessors = []
|
predecessors = []
|
||||||
|
@ -422,7 +423,7 @@ class Entity:
|
||||||
from squirrelbattle.entities.monsters import Tiger, Hedgehog, \
|
from squirrelbattle.entities.monsters import Tiger, Hedgehog, \
|
||||||
Rabbit, TeddyBear
|
Rabbit, TeddyBear
|
||||||
from squirrelbattle.entities.friendly import Merchant, Sunflower, \
|
from squirrelbattle.entities.friendly import Merchant, Sunflower, \
|
||||||
Trumpet
|
Trumpet
|
||||||
return [BodySnatchPotion, Bomb, Heart, Hedgehog, Rabbit, TeddyBear,
|
return [BodySnatchPotion, Bomb, Heart, Hedgehog, Rabbit, TeddyBear,
|
||||||
Sunflower, Tiger, Merchant, Trumpet]
|
Sunflower, Tiger, Merchant, Trumpet]
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ from .translations import gettext as _
|
||||||
class Settings:
|
class Settings:
|
||||||
"""
|
"""
|
||||||
This class stores the settings of the game.
|
This class stores the settings of the game.
|
||||||
Settings can be obtained by using for example settings.TEXTURE_PACK directly.
|
Settings can be obtained by using for example settings.TEXTURE_PACK
|
||||||
|
directly.
|
||||||
The comment can be obtained by using settings.get_comment('TEXTURE_PACK').
|
The comment can be obtained by using settings.get_comment('TEXTURE_PACK').
|
||||||
We can set the setting by simply using settings.TEXTURE_PACK = 'new_key'
|
We can set the setting by simply using settings.TEXTURE_PACK = 'new_key'
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue