Files
project_game/fruit.py

56 lines
1.4 KiB
Python

from random import randint
SHAPE_DEFINITIONS = [
[(0,0)],
[(0, 0), (1, 0), (0, 1), (1, 1)],
]
class FruitPiece:
character = "@"
color = "green_on_indigo"
display = True
def __init__(self, position):
self.position = position
class Fruit:
width = 2
height = 1
display = False
pieces = []
name = "fruit"
character = "@"
color = "green_on_indigo"
def __init__(self, position, game, shape_offsets):
self.position = position
self.pieces = {}
for offset in shape_offsets:
self.create_shape(game, offset)
def play_turn(self, game):
if game.turn_number % 3 == 0:
x, y = self.position
if y == 29:
game.remove_agent(self)
game.end()
else:
catcher = game.get_agent_by_name("catcher")
new_position = (x, y + 1)
def create_shape(self, game, offset):
x, y = self.position
ox, oy = offset
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:
self.set_color()
x, y = self.position
if y == 29:
game.remove_agent(self)
game.end()
else:
catcher = game.get_agent_by_name("catcher")
new_position = (x, y + 1)