generated from mwc/project_game
Resubmit commit 1
Re-wrote the player and board game because i kept getting stuck on creating the walls. There was an agent error so i needed to start from the begining again. I looked up resources online and used the tic tac toe and retro labs for help.
This commit is contained in:
BIN
__pycache__/maze_layout.cpython-312.pyc
Normal file
BIN
__pycache__/maze_layout.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
__pycache__/wall.cpython-312.pyc
Normal file
BIN
__pycache__/wall.cpython-312.pyc
Normal file
Binary file not shown.
25
escape_the_maze.py
Normal file
25
escape_the_maze.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from retro.game import Game
|
||||
from player import Player
|
||||
|
||||
def main():
|
||||
board_size = (100, 40)
|
||||
|
||||
player = Player(board_size)
|
||||
|
||||
state = {
|
||||
"win": False,
|
||||
}
|
||||
|
||||
game = Game(
|
||||
agents=[player],
|
||||
state=state,
|
||||
board_size=board_size,
|
||||
debug=False,
|
||||
framerate=24,
|
||||
color="white_on_black",
|
||||
)
|
||||
|
||||
game.play()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
8
game_signature.py
Normal file
8
game_signature.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from retro.game import Game
|
||||
import inspect
|
||||
|
||||
print("Game.__init__ signature:")
|
||||
print(inspect.signature(Game.__init__))
|
||||
|
||||
print("\nFull source of Game.__init__:\n")
|
||||
print(inspect.getsource(Game.__init__))
|
||||
@@ -1,8 +0,0 @@
|
||||
from retro.game import Game
|
||||
from player import Player
|
||||
|
||||
board_size = (100, 40)
|
||||
player = Player(board_size)
|
||||
|
||||
game = Game([player], {}, board_size=board_size)
|
||||
game.play()
|
||||
40
player.py
40
player.py
@@ -1,28 +1,38 @@
|
||||
class Player:
|
||||
class Player:
|
||||
"""
|
||||
Player agent for Escape the Maze.
|
||||
Moves one step at a time using the arrow keys.
|
||||
"""
|
||||
|
||||
name = "player"
|
||||
character = "🐧"
|
||||
color = "purple"
|
||||
character = "🐧" # Penguin icon
|
||||
|
||||
def __init__(self, board_size):
|
||||
# Start at bottom-left corner
|
||||
self.position = (0, board_size[1] - 1)
|
||||
# Start near the top-left corner
|
||||
width, height = board_size
|
||||
self.position = (1, 1)
|
||||
|
||||
def handle_keystroke(self, keystroke, game):
|
||||
"""
|
||||
Called once for each key pressed since the last turn.
|
||||
Moves the player using the arrow keys.
|
||||
"""
|
||||
x, y = self.position
|
||||
new_position = None
|
||||
|
||||
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":
|
||||
if keystroke.name == "KEY_UP":
|
||||
new_position = (x, y - 1)
|
||||
elif keystroke.name == "KEY_DOWN":
|
||||
new_position = (x, y + 1)
|
||||
else:
|
||||
elif keystroke.name == "KEY_LEFT":
|
||||
new_position = (x - 1, y)
|
||||
elif keystroke.name == "KEY_RIGHT":
|
||||
new_position = (x + 1, y)
|
||||
|
||||
|
||||
if new_position is None:
|
||||
return
|
||||
|
||||
# Contain penguin inside board
|
||||
if game.on_board(new_position):
|
||||
self.position = new_position
|
||||
|
||||
|
||||
if game.on_board(new_position) and game.is_empty(new_position):
|
||||
self.position = new_position
|
||||
Reference in New Issue
Block a user