diff --git a/__pycache__/person.cpython-312.pyc b/__pycache__/person.cpython-312.pyc new file mode 100644 index 0000000..318f7a6 Binary files /dev/null and b/__pycache__/person.cpython-312.pyc differ diff --git a/__pycache__/player.cpython-312.pyc b/__pycache__/player.cpython-312.pyc new file mode 100644 index 0000000..f559b39 Binary files /dev/null and b/__pycache__/player.cpython-312.pyc differ diff --git a/__pycache__/questioner.cpython-312.pyc b/__pycache__/questioner.cpython-312.pyc new file mode 100644 index 0000000..0bc5d06 Binary files /dev/null and b/__pycache__/questioner.cpython-312.pyc differ diff --git a/__pycache__/starfall.cpython-312.pyc b/__pycache__/starfall.cpython-312.pyc new file mode 100644 index 0000000..9a84faf Binary files /dev/null and b/__pycache__/starfall.cpython-312.pyc differ diff --git a/__pycache__/starfall_spawner.cpython-312.pyc b/__pycache__/starfall_spawner.cpython-312.pyc new file mode 100644 index 0000000..44b3bbc Binary files /dev/null and b/__pycache__/starfall_spawner.cpython-312.pyc differ diff --git a/person.py b/person.py new file mode 100644 index 0000000..8656e70 --- /dev/null +++ b/person.py @@ -0,0 +1,23 @@ +class Person: + name = "Person" + 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 == "KEY_LEFT": + new_position = (x - 1, y) + elif keystroke.name == "KEY_RIGHT": + new_position = (x + 1, y) + elif keystroke.name == "KEY_UP": + new_position = (x, y - 1) + elif keystroke.name == "KEY_DOWN": + new_position = (x, y + 1) + else: + return + + if game.on_board(new_position) and game.is_empty(new_position): + self.position = new_position \ No newline at end of file diff --git a/player.py b/player.py new file mode 100644 index 0000000..cdee868 --- /dev/null +++ b/player.py @@ -0,0 +1,25 @@ +class Person: + name = "Person" + 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) + else: + new_position =(x,y) + + if game.on_board(new_position): + if game.is_empty(new_position): + self.position = new_position \ No newline at end of file diff --git a/questioner.py b/questioner.py new file mode 100644 index 0000000..354ac1b --- /dev/null +++ b/questioner.py @@ -0,0 +1,30 @@ +class Questioner: + name = "Questioner" + character = '?' + + def __init__(self, board_size): + board_width, board_height = board_size + self.position = (board_width // 2, board_height // 2) + + def play_turn(self,game): + person = game.get_agent_by_name('Person') + if person: + personx, persony = person.position + questionerx, questionery = self.position + if personx == questionerx and persony == questionery +1: + prompt = input("Questioner: Are you ready to start the game? [[Y/N]] \n") + if prompt.strip().upper() == "Y": + print("Questioner: Well then, the rules are as follows... \n 1. You have 3 lives. \n 2. For every 200 points you accumulate during Starfall, you receive a question. \n 3. Each wrong answer costs you a life. You must answer 3 questions to escape this terminal. \n") + + begin = input("Questioner: Shall we begin? [[Y/N]] \n" ) + if begin.strip().upper() == "Y": + print("Questioner: Well then, good luck player! \n") + game.state["begin"] = True + + + elif prompt.strip().upper() == "N": + print("Questioner: I'll be here when you're ready. \n") + else: + print("Questioner: What now?) \n") + + diff --git a/starfall.py b/starfall.py new file mode 100644 index 0000000..eb7a9a4 --- /dev/null +++ b/starfall.py @@ -0,0 +1,19 @@ +class Star: + character = '*' + + 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: + person = game.get_agent_by_name('Person') + new_position = (x, y + 1) + if new_position == person.position: + game.end() + else: + self.position = new_position \ No newline at end of file diff --git a/starfall_game.py b/starfall_game.py new file mode 100644 index 0000000..8062f59 --- /dev/null +++ b/starfall_game.py @@ -0,0 +1,11 @@ +from retro.game import Game +from person import Person +from questioner import Questioner +from starfall_spawner import StarfallSpawner + +board_size = (50, 30) +player = Person(board_size) +questioner = Questioner(board_size) +spawner = StarfallSpawner() +game = Game([player, questioner, spawner], {"score": 0, "begin": False}, board_size=board_size) +game.play() diff --git a/starfall_spawner.py b/starfall_spawner.py new file mode 100644 index 0000000..0c55f93 --- /dev/null +++ b/starfall_spawner.py @@ -0,0 +1,17 @@ +from random import randint +from starfall import Star + +class StarfallSpawner: + display = False + + def play_turn(self, game): + if not game.state.get("begin"): + return + width, height = game.board_size + game.state['score'] += 1 + if self.should_spawn_star(game.turn_number): + star = Star((randint(0, width - 1), 0)) + game.add_agent(star) + + def should_spawn_star(self, turn_number): + return randint(0, 1000) < turn_number \ No newline at end of file