generated from mwc/project_game
66 lines
1.9 KiB
Python
66 lines
1.9 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.blocks = {}
|
|
for shape 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.state['Score'] -= 3
|
|
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)
|
|
|
|
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.state['Score'] -= 3
|
|
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 |