I will finish the rest of the project at home

This commit is contained in:
kdang
2026-01-16 09:36:38 -05:00
parent 267fffa9b0
commit 98f6f2716c
8 changed files with 32 additions and 24 deletions

View File

@@ -23,8 +23,8 @@ class Fruit:
def __init__(self, position, game, shape_offsets):
self.position = position
self.blocks = {}
for shape in shape_offsets:
self.pieces = {}
for offset in shape_offsets:
self.create_shape(game, offset)
def play_turn(self, game):
@@ -32,22 +32,17 @@ class Fruit:
x, y = self.position
if y == 29:
game.remove_agent(self)
game.state['Score'] -= 3
game.end()
else:
catcher = game.get_agent_by_name("catcher")
new_position = (x, y + 1)
if new_position == catcher.position:
game.remove_agent(self)
game.state['Score'] += 1
else:
self.position = new_position
def create_shape(self, game, offset):
x, y = self.position
ox, oy = offset
fruit = Fruit((x + ox, y + oy))
self.fruits[offset] = fruit
game.add_agent(fruit)
piece = FruitPiece((x + ox, y + oy))
self.pieces[offset] = piece
game.add_agent(piece)
def update_piece_positions(self):
if game.turn_number % 3 == 0:
@@ -55,12 +50,7 @@ class Fruit:
x, y = self.position
if y == 29:
game.remove_agent(self)
game.state['Score'] -= 3
game.end()
else:
catcher = game.get_agent_by_name("catcher")
new_position = (x, y + 1)
if new_position == catcher.position:
game.remove_agent(self)
game.state['Score'] += 1
else:
self.position = new_position
new_position = (x, y + 1)