diff --git a/gamefiles/__pycache__/man.cpython-312.pyc b/gamefiles/__pycache__/man.cpython-312.pyc index 15a150b..0ba4669 100644 Binary files a/gamefiles/__pycache__/man.cpython-312.pyc and b/gamefiles/__pycache__/man.cpython-312.pyc differ diff --git a/gamefiles/__pycache__/mine.cpython-312.pyc b/gamefiles/__pycache__/mine.cpython-312.pyc index ee04217..1641475 100644 Binary files a/gamefiles/__pycache__/mine.cpython-312.pyc and b/gamefiles/__pycache__/mine.cpython-312.pyc differ diff --git a/gamefiles/__pycache__/score.cpython-312.pyc b/gamefiles/__pycache__/score.cpython-312.pyc new file mode 100644 index 0000000..300a288 Binary files /dev/null and b/gamefiles/__pycache__/score.cpython-312.pyc differ diff --git a/gamefiles/__pycache__/snack.cpython-312.pyc b/gamefiles/__pycache__/snack.cpython-312.pyc index 533015f..15f627e 100644 Binary files a/gamefiles/__pycache__/snack.cpython-312.pyc and b/gamefiles/__pycache__/snack.cpython-312.pyc differ diff --git a/gamefiles/helpers.py b/gamefiles/helpers.py index 3e175a1..60ff64c 100644 --- a/gamefiles/helpers.py +++ b/gamefiles/helpers.py @@ -1,12 +1,14 @@ #List of helper functions to move the man -def add(vec0, vec1): +'''def add(vec0, vec1): """Adds two vectors. Got tired of doing this by hand. """ x0, y0 = vec0 x1, y1 = vec1 return (x0 + x1, y0 + y1) +''' + def get_occupant(game, position): """Returns the agent at position, if there is one. @@ -18,7 +20,7 @@ def get_occupant(game, position): if position in positions_with_agents: agents_at_position = positions_with_agents[position] return agents_at_position[0] - +''' def distance(vec0, vec1): """Returns the distance between two vectors, using the "manhattan distance," or the distance if you can only @@ -27,4 +29,4 @@ def distance(vec0, vec1): """ x0, y0 = vec0 x1, y1 = vec1 - return abs(x1 - x0) + abs(y1 - y0) \ No newline at end of file + return abs(x1 - x0) + abs(y1 - y0)''' \ No newline at end of file diff --git a/gamefiles/man.py b/gamefiles/man.py index 7afa046..f2f3338 100644 --- a/gamefiles/man.py +++ b/gamefiles/man.py @@ -1,7 +1,11 @@ from retro.agent import ArrowKeyAgent #from retro.game import Game #from helpers import add, get_occupant - +from retro.game import Game +from random import shuffle +from snack import Snack +width=25 +height=25 direction_vectors = { "KEY_RIGHT": (1, 0), @@ -25,7 +29,10 @@ class Man: vector = direction_vectors[keystroke.name] self.try_to_move(vector, game) - '''Checks if a space is avialable to move''' + '''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.''' def try_to_move(self, vector, game): x,y = self.position vx,vy = vector @@ -43,22 +50,39 @@ class Man: if obstacle.snack: game.state['Score'] += 1 game.remove_agent(agents[0]) - + self.generate_new_snack() else: - game.state['Score'] -= 1 + game.state['Score'] -= 10 game.remove_agent(agents[0]) - + if game.state['Score'] <0: + self.die(game) + else: + pass else: self.position = future_position + '''Indicates what happens when the game is over.''' def die(self,game): game.state["message"] = "Game Over" self.color = "black" game.end() - - + def get_all_positions(self): + positions=[] + for i in range(width): + for j in range(height): + positions.append((i,j)) + return positions + '''issue here, is_empty is not generating a coordinate positon, + but I am not sure why it is not''' + def generate_new_snack(self): + all_positions=self.get_all_positions() + shuffle(all_positions) + index =0 + while Game.is_empty(all_positions[index]) == False: + index = index + 1 + Snack(all_positions[index]) ''' def __init__(self, position): self.position = position diff --git a/gamefiles/mine.py b/gamefiles/mine.py index c564caf..53573cc 100644 --- a/gamefiles/mine.py +++ b/gamefiles/mine.py @@ -6,3 +6,5 @@ class Mine: def __init__(self,position): self.position = position + + \ No newline at end of file diff --git a/gamefiles/nav_game.py b/gamefiles/nav_game.py index a725171..47a3d9e 100644 --- a/gamefiles/nav_game.py +++ b/gamefiles/nav_game.py @@ -1,19 +1,19 @@ from retro.game import Game from board import Board +from score import num_mines + width = 25 height = 25 -num_snacks = 10 -num_mines = 10 -board = Board(width,height,num_snacks,num_mines) -score = 0 state= {"Score":0} -#man = Man(board_size) +score =state["Score"] +num_snacks = 10 +num_mines = num_mines(score) +board = Board(width,height,num_snacks,num_mines) + game = Game( board.get_agents(num_snacks, num_mines), state, board_size = (width, height) ) -#print(board.get_agents()) -print(len(board.get_agents(10,10))) game.play() \ No newline at end of file diff --git a/gamefiles/score.py b/gamefiles/score.py new file mode 100644 index 0000000..f8ce62d --- /dev/null +++ b/gamefiles/score.py @@ -0,0 +1,15 @@ + + +def num_mines(score): + if score < 5: + num_mines = 10 + if 10 <= score <50: + num_mines = 20 + if 50 <= score <75: + num_mines = 30 + if 75 <= score <100: + num_mines = 40 + #else: + #num_mines = 50 + return num_mines + \ No newline at end of file diff --git a/gamefiles/snack.py b/gamefiles/snack.py index 6b75dd2..cb33e37 100644 --- a/gamefiles/snack.py +++ b/gamefiles/snack.py @@ -6,3 +6,4 @@ class Snack: def __init__(self,position): self.position = position +