diff --git a/proposal.md/__pycache__/asteroid.cpython-313.pyc b/proposal.md/__pycache__/asteroid.cpython-313.pyc new file mode 100644 index 0000000..f5ff054 Binary files /dev/null and b/proposal.md/__pycache__/asteroid.cpython-313.pyc differ diff --git a/proposal.md/__pycache__/asteroid_spawner.cpython-313.pyc b/proposal.md/__pycache__/asteroid_spawner.cpython-313.pyc new file mode 100644 index 0000000..3e935cf Binary files /dev/null and b/proposal.md/__pycache__/asteroid_spawner.cpython-313.pyc differ diff --git a/proposal.md/__pycache__/shooter.cpython-313.pyc b/proposal.md/__pycache__/shooter.cpython-313.pyc new file mode 100644 index 0000000..f40f04a Binary files /dev/null and b/proposal.md/__pycache__/shooter.cpython-313.pyc differ diff --git a/proposal.md/__pycache__/targets.cpython-313.pyc b/proposal.md/__pycache__/targets.cpython-313.pyc index 190cbfd..cee5b3a 100644 Binary files a/proposal.md/__pycache__/targets.cpython-313.pyc and b/proposal.md/__pycache__/targets.cpython-313.pyc differ diff --git a/proposal.md/asteroid.py b/proposal.md/asteroid.py new file mode 100644 index 0000000..add21a5 --- /dev/null +++ b/proposal.md/asteroid.py @@ -0,0 +1,19 @@ +class Asteroid: + character = 'O' + + def __init__(self, position): + self.position = position + + def play_turn(self, game): + width, height = game.board_size + if game.turn_number % 2 == 0: + x, y = self.position + if y == height - 1: + game.remove_agent(self) + else: + ship = game.get_agent_by_name('ship') + new_position = (x, y + 1) + if new_position == ship.position: + game.end() + else: + self.position = new_position \ No newline at end of file diff --git a/proposal.md/asteroid_spawner.py b/proposal.md/asteroid_spawner.py new file mode 100644 index 0000000..ed92c70 --- /dev/null +++ b/proposal.md/asteroid_spawner.py @@ -0,0 +1,15 @@ +from random import randint +from asteroid import Asteroid + +class AsteroidSpawner: + display = False + + def play_turn(self, game): + width, height = game.board_size + game.state['score'] += 1 + if self.should_spawn_asteroid(game.turn_number): + asteroid = Asteroid((randint(0, width - 1), 0)) + game.add_agent(asteroid) + + def should_spawn_asteroid(self, turn_number): + return randint(0, 1000) < turn_number \ No newline at end of file diff --git a/proposal.md/nav_game.py b/proposal.md/nav_game.py index f42aa38..003698d 100644 --- a/proposal.md/nav_game.py +++ b/proposal.md/nav_game.py @@ -1,9 +1,14 @@ from retro.game import Game from spaceship import Spaceship -from targets import Asteroid +# from asteroid_spawner import AsteroidSpawner +from targets import Alien +from shooter import Shooter +import random board_size = (100, 25) +width, height = board_size ship = Spaceship(board_size) -targets = Asteroid((board_size[0] // 2, 0)) -game = Game([ship, targets], {"score": 0}, board_size=board_size, color="white_on_blue") +shooter = Shooter() +spawner = Alien((random.randint(0, width-1), random.randint(0, height-1))) +game = Game([ship, spawner, shooter], {"score": 0}, board_size=board_size, color="white_on_blue") game.play() \ No newline at end of file diff --git a/proposal.md/shooter.py b/proposal.md/shooter.py new file mode 100644 index 0000000..e633efb --- /dev/null +++ b/proposal.md/shooter.py @@ -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 + diff --git a/proposal.md/targets.py b/proposal.md/targets.py index add21a5..391ad96 100644 --- a/proposal.md/targets.py +++ b/proposal.md/targets.py @@ -1,19 +1,46 @@ -class Asteroid: - character = 'O' +from random import randint + + +class Alien: + character = 'A' def __init__(self, position): self.position = position def play_turn(self, game): + width, height = game.board_size - if game.turn_number % 2 == 0: - x, y = self.position - if y == height - 1: - game.remove_agent(self) - else: - ship = game.get_agent_by_name('ship') - new_position = (x, y + 1) - if new_position == ship.position: - game.end() - else: - self.position = new_position \ No newline at end of file + + x, y = self.position + + directions = [ + (-1, 0), # left + (1, 0), # right + (0, -1), # up + (0, 1), # down + (-1, -1), # up-left + (-1, 1), # down-left + (1, -1), # up-right + (1, 1) # down-right + ] + + possible_positions = [] + for dx, dy in directions: + new_x = x + dx + new_y = y + dy + + if 0 <= new_x < width and 0 <= new_y < height: + possible_positions.append((new_x, new_y)) + + if not possible_positions: + return + random_index = randint(0, len(possible_positions) - 1) + new_position = possible_positions[random_index] + + ship = game.get_agent_by_name('ship') + + if ship is not None and new_position == ship.position: + game.end() + else: + + self.position = new_position