diff --git a/__pycache__/path.cpython-312.pyc b/__pycache__/path.cpython-312.pyc new file mode 100644 index 0000000..5ac2573 Binary files /dev/null and b/__pycache__/path.cpython-312.pyc differ diff --git a/__pycache__/person.cpython-312.pyc b/__pycache__/person.cpython-312.pyc new file mode 100644 index 0000000..7d36530 Binary files /dev/null and b/__pycache__/person.cpython-312.pyc differ diff --git a/__pycache__/spawner.cpython-312.pyc b/__pycache__/spawner.cpython-312.pyc new file mode 100644 index 0000000..88fd063 Binary files /dev/null and b/__pycache__/spawner.cpython-312.pyc differ diff --git a/new.py b/new.py new file mode 100644 index 0000000..5846492 --- /dev/null +++ b/new.py @@ -0,0 +1,9 @@ +from retro.game import Game +from person import Spaceship +from spawner import AsteroidSpawner + +board_size = (25, 25) +ship = Spaceship(board_size) +spawner = AsteroidSpawner() +game = Game([ship, spawner], {"score": 0,"lives":5}, board_size=board_size) +game.play() \ No newline at end of file diff --git a/path.py b/path.py new file mode 100644 index 0000000..547fef0 --- /dev/null +++ b/path.py @@ -0,0 +1,41 @@ +class Asteroid: + character = 'O' + + def __init__(self, position): + self.position = position + + #def play_turn(self, game): + # lives = 5 + # 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: + # lives = lives-1 + # game.state["lives"] -=1 + # if game.state["lives"] == 0: + # game.end() + #else: + # self.position = new_position + + def play_turn(self, game): + lives = 5 + 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: + lives = lives-1 + game.state["lives"] -=1 + if game.state["lives"] == 0: + game.end() + else: + self.position = new_position \ No newline at end of file diff --git a/person.py b/person.py new file mode 100644 index 0000000..a473abf --- /dev/null +++ b/person.py @@ -0,0 +1,24 @@ +class Spaceship: + name = "ship" + character = '^' + + def __init__(self, board_size): + board_width, board_height = board_size + self.position = (board_width // 2, board_height - 1) + + def handle_keystroke(self, keystroke, game): + x, y = self.position + if keystroke.name in ("KEY_LEFT", "KEY_RIGHT","KEY_UP", "KEY_DOWN"): + if keystroke.name == "KEY_LEFT": + new_position = (x - 1, y) + if keystroke.name == "KEY_RIGHT": + new_position = (x + 1, y) + if keystroke.name == "KEY_UP": + new_position = (x, y - 1) + if keystroke.name == "KEY_DOWN": + new_position = (x, y + 1) + if game.on_board(new_position): + if game.is_empty(new_position): + self.position = new_position + else: + game.end() \ No newline at end of file diff --git a/spawner.py b/spawner.py new file mode 100644 index 0000000..884e579 --- /dev/null +++ b/spawner.py @@ -0,0 +1,15 @@ +from random import randint +from path 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