Compare commits

..

2 Commits

Author SHA1 Message Date
mollychi
621a680676 I was able to solve all my bugs to get my code to look EXACTLY how i wanted to.
I used AI to help me through some issues, but all the coding I understood and worked through and typed on my own
I learned a lot about the structure and when AI would suggest something I could be like thats now going to solve my issue I need to do this which felt very motivating
2025-12-14 12:47:15 -05:00
mollychi
b2dd17e4ad im stuck as the same place as last time lol 2025-12-13 19:13:20 -05:00
4 changed files with 37 additions and 17 deletions

Binary file not shown.

Binary file not shown.

21
frog.py
View File

@@ -8,15 +8,18 @@ class Frog:
def handle_keystroke(self, keystroke, game): def handle_keystroke(self, keystroke, game):
x, y = self.position x, y = self.position
if keystroke.name in ("KEY_LEFT", "KEY_RIGHT", "KEY_UP"): if keystroke.name in ("KEY_LEFT", "KEY_RIGHT"):
if keystroke.name == "KEY_LEFT": if keystroke.name == "KEY_LEFT":
new_position = (x - 1, y) new_position = (x - 1, y)
if keystroke.name == "KEY_RIGHT": elif keystroke.name == "KEY_RIGHT":
new_position = (x + 1, y) new_position = (x + 1, y)
if keystroke.name == "KEY_UP": else:
new_position = (x, y + 1) return
if game.on_board(new_position): if not game.on_board(new_position):
if game.is_empty(new_position): return
self.position = new_position if not game.is_empty(new_position):
else: game.end()
game.end() self.position = new_position

View File

@@ -3,17 +3,34 @@ class Obstacle:
def __init__(self, position): def __init__(self, position):
self.position = position self.position = position
def handle_keystroke(self, keystroke, game):
froggy = game.get_agent_by_name('froggy')
if keystroke.name != "KEY_UP":
return
_, height = game.board_size
x, y =self.position
if y == height -1:
game.remove_agent(self)
return
new_position = (x,y + 1)
if new_position == froggy.position:
game.end()
return
if game.on_board(new_position) and game.is_empty(new_position):
self.position = new_position
def play_turn(self, game): def play_turn(self, game):
width, height = game.board_size width, height = game.board_size
if game.turn_number % 2 == 0: if game.turn_number % 2 == 0:
x, y = self.position x, y = self.position
if y == height + 1: if y >= height:
game.remove_agent(self) game.remove_agent(self)
else:
froggy = game.get_agent_by_name('froggy')
new_position = (x, y)
if new_position == froggy.position:
game.end()
else:
self.position = new_position