generated from mwc/project_game
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
This commit is contained in:
Binary file not shown.
Binary file not shown.
22
frog.py
22
frog.py
@@ -8,16 +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:
|
||||||
froggy = game.get_agent_by_name('froggy')
|
return
|
||||||
froggy.position = (froggy.position[0], froggy.position[1]+1)
|
if not game.on_board(new_position):
|
||||||
if game.on_board(new_position):
|
return
|
||||||
if game.is_empty(new_position):
|
if not game.is_empty(new_position):
|
||||||
self.position = new_position
|
game.end()
|
||||||
else:
|
self.position = new_position
|
||||||
game.end()
|
|
||||||
|
|
||||||
|
|
||||||
33
obstacle.py
33
obstacle.py
@@ -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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user