Skip to content

Commit

Permalink
lint lint lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Franr committed Nov 14, 2016
1 parent aacbc3a commit f884e42
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 42 deletions.
27 changes: 12 additions & 15 deletions client/bala.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,30 @@ class HandlerBalas(object):

""" Clase que almacena las balas que dibuja el cliente """

def __init__(self, juego):
self.juego = juego
self.balas = []
def __init__(self, game):
self.game = game
self.bullets = []
self.clean_loop()

def get_balas(self):
return self.balas

def add_bullet(self, bala):
self.balas.append(bala)
def add_bullet(self, bullet):
self.bullets.append(bullet)

def clean_loop(self):
[self.balas.remove(b) for b in self.balas if not b.alive]
if self.juego.on:
self.bullets = [b for b in self.bullets if b.alive]
if self.game.on:
reactor.callLater(0.1, self.clean_loop)


class Bala(Positionable):
class Bullet(Positionable):

def __init__(self, uid, x, y, direction, equipo, juego):
def __init__(self, uid, x, y, direction, equipo, game):
Positionable.__init__(self, x, y)
self.uid = uid
self.dir = direction
self.equipo = equipo
self.juego = juego
self.game = game
self.alive = True
self.mapa = juego.conexion.cf.protocol.mapa # horrible
self.mapa = game.conexion.cf.protocol.mapa # horrible
self.delay = 0.05
# go for it!
self.loop()
Expand All @@ -54,7 +51,7 @@ def loop(self):
self.x += mx
self.y += my
self.collision()
if self.juego.on and not self.collision():
if self.game.on and not self.collision():
reactor.callLater(self.delay, self.loop)
else:
self.alive = False
Expand Down
9 changes: 2 additions & 7 deletions client/criaturas.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def del_creature_by_id(self, uid):
print("Id invalida:" + str(uid))

def reset_all(self):
[j.reset() for j in self.jugadores.values()]
for j in self.jugadores.values():
j.reset()

def set_score(self, azul, rojo):
self.azul = azul
Expand Down Expand Up @@ -77,9 +78,6 @@ def reset(self):
self.vivo = True
self.vida.llenar()

def es_principal(self):
return False

def esta_vivo(self):
return self.vivo

Expand All @@ -99,9 +97,6 @@ def __init__(self, uid, x, y, vida, vida_max, team):
super(Player, self).__init__(uid, x, y, vida, vida_max, team)
self.es_principal = False

def es_principal(self):
return self.es_principal


class Vida(object):

Expand Down
4 changes: 2 additions & 2 deletions client/protocolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Move, MoveObject, SendMap, CreateObject, CreateObjects, Login, PlayerShoot, Shoot, PlayerHit,
PlayerRevive, LogoutPlayer, UpdateScore, RestartRound, AddBot, DeleteBot)

from bala import Bala
from bala import Bullet
from bloqueos import FireBlock, MoveBlock


Expand Down Expand Up @@ -65,7 +65,7 @@ def player_shoot(self, uid, direction, x, y):
# disparo
jug = self.hcriat.get_creature_by_uid(uid)
if jug:
self.juego.add_bullet(Bala(uid, x, y, direction, jug.get_equipo(), self.juego))
self.juego.add_bullet(Bullet(uid, x, y, direction, jug.get_equipo(), self.juego))
return {'ok': 1}

@PlayerHit.responder
Expand Down
2 changes: 1 addition & 1 deletion generic_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_players(self):
return self.hcriat.get_players()

def get_bullets(self):
return self.balas.get_balas()
return self.balas.bullets

def get_score(self):
return self.hcriat.azul, self.hcriat.rojo
6 changes: 3 additions & 3 deletions ia/ia.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ def shoot_enemy(bot, enemies, connection):
connection.cf.protocol.fire(direction)


def move(bot, connection):
def move(_, connection):
if connection.cf.protocol:
connection.cf.protocol.move(random.choice(pos_letter.values()))


def get_all_empty_place(mapa, x, y):
def get_all_empty_place(map_obj, x, y):
positions = (0, -1), (-1, 0), (1, 0), (0, 1)
empties = []
for pos in positions:
nx = x + pos[0]
ny = y + pos[1]
if not mapa.is_blocking_position(nx, ny):
if not map_obj.is_blocking_position(nx, ny):
empties.append(pos)
return empties

Expand Down
2 changes: 1 addition & 1 deletion server/src/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def id_generator():
num += 1


class CreaturesHandler:
class CreaturesHandler(object):

VIDA_MAX = 100
pw_map = None
Expand Down
2 changes: 1 addition & 1 deletion server/src/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def login(self, team):
@Shoot.responder
def player_shoot(self, uid, direction):
try:
jug, shoot_handler = shoot_action(uid, direction, self.hcriat, self.hit, self.die)
jug, _ = shoot_action(uid, direction, self.hcriat, self.hit, self.die)
except exceptions.CantShoot:
pass
else:
Expand Down
24 changes: 12 additions & 12 deletions server/tests_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_multiple_players_red(self):
self.assertEqual(len(others), 1)

def test_full_team_base(self):
for i in range(9):
for _ in range(9):
create_player(Team.RED, self.hcriat)
self.assertRaises(TeamBasePositionNotFound, create_player, Team.RED, self.hcriat)

Expand All @@ -136,35 +136,35 @@ def test_shoot_bad_direction(self):

def test_shoot_update(self):
player, _, _, _ = create_player(Team.BLUE, self.hcriat)
player, shoot_handler = shoot_action(player.get_uid(), 'n', self.hcriat, None, None)
_, shoot_handler = shoot_action(player.get_uid(), 'n', self.hcriat, None, None)
before_y = shoot_handler.bala.y
shoot_handler.loop()
self.assertEqual(before_y - 1, shoot_handler.bala.y)

def test_shoot_hit_wall(self):
player, _, _, _ = create_player(Team.BLUE, self.hcriat)
player, shoot_handler = shoot_action(player.get_uid(), 'o', self.hcriat, None, None)
for i in range(3):
_, shoot_handler = shoot_action(player.get_uid(), 'o', self.hcriat, None, None)
for _ in range(3):
self.assertTrue(shoot_handler.update())
self.assertFalse(shoot_handler.update())

def test_shoot_friend(self):
player1, _, _, pw_map = create_player(Team.BLUE, self.hcriat)
player2, _, _, pw_map = create_player(Team.BLUE, self.hcriat)
pw_map.move_player(player2, player1.x+2, player1.y)
player, shoot_handler = shoot_action(player1.get_uid(), 'e', self.hcriat, None, None)
for i in range(3):
_, shoot_handler = shoot_action(player1.get_uid(), 'e', self.hcriat, None, None)
for _ in range(3):
self.assertTrue(shoot_handler.update())

def test_shoot_enemy(self):
player1, _, _, pw_map = create_player(Team.BLUE, self.hcriat)
player2, _, _, pw_map = create_player(Team.RED, self.hcriat)
pw_map.move_player(player2, player1.x+2, player1.y)
player, shoot_handler = shoot_action(player1.get_uid(), 'e', self.hcriat, callback, None)
healt_before = player2.vida
_, shoot_handler = shoot_action(player1.get_uid(), 'e', self.hcriat, callback, None)
health_before = player2.vida
self.assertTrue(shoot_handler.update()) # move 1 sqm
self.assertFalse(shoot_handler.update()) # hit the enemy
self.assertLess(player2.vida, healt_before)
self.assertLess(player2.vida, health_before)

def test_cant_shoot_exception(self):
player1, _, _, _ = create_player(Team.BLUE, self.hcriat)
Expand All @@ -176,7 +176,7 @@ def test_kill_and_revive_enemy(self):
player1, _, _, pw_map = create_player(Team.BLUE, self.hcriat)
player2, _, _, pw_map = create_player(Team.RED, self.hcriat)
pw_map.move_player(player2, player1.x+1, player1.y)
player, shoot_handler = shoot_action(
_, shoot_handler = shoot_action(
player1.get_uid(), 'e', self.hcriat, callback, callback)
player2.vida = 1
shoot_handler.loop()
Expand All @@ -193,7 +193,7 @@ def die_callback(uid):
return increase_score(uid, self.hcriat)

pw_map.move_player(player2, player1.x+1, player1.y)
player, shoot_handler = shoot_action(
_, shoot_handler = shoot_action(
player1.get_uid(), 'e', self.hcriat, callback, die_callback)
player2.vida = 1
self.assertEqual(self.score.blue_score, 0)
Expand All @@ -208,7 +208,7 @@ def die_callback(uid):
return increase_score(uid, self.hcriat)

pw_map.move_player(player2, player1.x+1, player1.y)
player, shoot_handler = shoot_action(
_, shoot_handler = shoot_action(
player1.get_uid(), 'e', self.hcriat, callback, die_callback)
player2.vida = 1
self.assertEqual(self.score.red_score, 0)
Expand Down

0 comments on commit f884e42

Please sign in to comment.