generated from mwc/project_game
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
|
|
|
|
class Shooter:
|
|
name = "shooter"
|
|
character = 'I'
|
|
display = False
|
|
|
|
def __init__(self):
|
|
self.position = (0, 0)
|
|
|
|
def handle_keystroke(self, keystroke, game):
|
|
if keystroke == ' ' and not self.display:
|
|
ship = game.get_agent_by_name('ship')
|
|
if ship is None:
|
|
return
|
|
|
|
x, y = ship.position
|
|
new_position = (x, y - 1)
|
|
|
|
if game.on_board(new_position):
|
|
self.position = new_position
|
|
self.display = True
|
|
|
|
def play_turn(self, game):
|
|
if not self.display:
|
|
return
|
|
|
|
x, y = self.position
|
|
new_position = (x, y - 1)
|
|
|
|
|
|
if not game.on_board(new_position):
|
|
self.display = False
|
|
return
|
|
|
|
agents_by_position = game.get_agents_by_position()
|
|
agents_here = agents_by_position.get(new_position, [])
|
|
|
|
for agent in agents_here:
|
|
if getattr(agent, "character", None) == 'A':
|
|
game.end()
|
|
return
|
|
|
|
self.position = new_position
|
|
|