FINAL GAME SUBMISSION

Got the man chaser to work!
Moved all global variables to nav_game.py so easier to adjust later
This commit is contained in:
Chris Mekelburg
2024-12-14 20:55:55 -05:00
parent ba4a255ca1
commit 7e5420d8bb
14 changed files with 162 additions and 62 deletions

View File

@@ -5,8 +5,8 @@ from snack import Snack
width=25
height=25
'''Establishes keyboard arrow keys as direction vectors so each arrow key corresponds with movement
in a certain direction on the board.'''
"""Establishes keyboard arrow keys as direction vectors so each arrow key corresponds with movement
in a certain direction on the board."""
direction_vectors = {
"KEY_RIGHT": (1, 0),
"KEY_UP": (0, -1),
@@ -19,21 +19,24 @@ class Man:
color = "blue"
snack=False
mine=False
chaser=False
name= "man"
def __init__(self,position):
self.position = position
def handle_keystroke(self, keystroke, game):
'''Describes how a keystroke is received'''
"""Describes how a keystroke is received"""
if keystroke.name in direction_vectors:
vector = direction_vectors[keystroke.name]
self.try_to_move(vector, game)
def try_to_move(self, vector, game):
'''Checks if a space is avialable to move. Also adds 1 point if the space
"""Checks if a space is avialable to move. Also adds 1 point if the space
contains a snack and then removes the snack. Deducts 10 points if the
space contains a mine. Checks that the score is not negative and if it
is, ends the game. Also stores the score so it can be used to determine if more mines are needed'''
space contains a mine. Deducts 20 points if the space contains a chaser.
Checks that the score is not negative and if it is, ends the game. Also
stores the score so it can be used to determine if more mines are needed"""
x,y = self.position
vx,vy = vector
future_position = (x +vx, y+vy)
@@ -49,6 +52,13 @@ class Man:
if obstacle.snack:
game.state['Score'] += 1
game.remove_agent(agents[0])
elif obstacle.chaser:
game.state['Score'] -= 20
game.remove_agent(agents[0])
if game.state['Score'] <0:
self.die(game)
else:
pass
else:
game.state['Score'] -= 10
game.remove_agent(agents[0])
@@ -60,7 +70,7 @@ class Man:
self.position = future_position
def die(self,game):
'''Indicates what happens when the game is over.'''
"""Indicates what happens when the game is over."""
game.state["Message"] = "Game Over"
self.color = "black"
game.end()