add a alien target and a shooter to hit it

I am actually really proud that i was able to figure out how to make the alien move
in every direction randomly.
This commit is contained in:
tsmith37
2025-12-08 20:30:45 -05:00
parent d0c4bb8b26
commit 35ed9eb328
9 changed files with 130 additions and 16 deletions

48
proposal.md/shooter.py Normal file
View File

@@ -0,0 +1,48 @@
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