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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -8,7 +8,7 @@ class CatcherPiece:
def play_turn(self, game):
fruit = game.get_agent_by_name("fruit")
if new_position == fruit.position:
if self.position == fruit.position:
game.state['Score'] += 1
class Catcher:
@@ -36,6 +36,14 @@ class Catcher:
if x + self.width < width:
self.position = (x+1, y)
self.update_piece_positions()
self.checkforfruitcollision(game)
def checkforfruitcollision(self, game):
for piece in self.pieces:
if piece.collision(game):
game.remove_agent(fruit)
game.state['Score'] += 1
def create_pieces(self, game):
x, y = self.position

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)

View File

@@ -2,6 +2,7 @@ from random import randint
from retro.game import Game
from catcher import Catcher
from manager import FruitManager
import json
WIDTH = 27
HEIGHT = 30
@@ -13,4 +14,4 @@ agents = [
state = {'Score': 0}
game = Game(agents, state, board_size=(WIDTH, HEIGHT), framerate=24, color="white_on_indigo")
game.play()
game.play()

View File

@@ -1,5 +1,5 @@
from fruit import Fruit, SHAPE_DEFINITIONS
from random import choice
from random import choice, randint
from retro.errors import AgentNotFoundByName
class FruitManager:
@@ -13,5 +13,6 @@ class FruitManager:
self.create_piece(game)
def create_piece(self, game):
fruit = Fruit((14, 1), game, choice(SHAPE_DEFINITIONS))
x = randint(0, 26)
fruit = Fruit((x, 1), game, choice(SHAPE_DEFINITIONS))
game.add_agent(fruit)

View File

@@ -1,9 +1,9 @@
[project]
name = "project-game"
name = "fruit-catcher"
version = "0.1.0"
description = ""
authors = [
{name = "Chris Proctor",email = "chris@chrisproctor.net"}
{name = "Kayden Dang, Connor ",email = "chris@chrisproctor.net"}
]
license = {text = "MIT"}
readme = "README.md"
@@ -12,6 +12,14 @@ dependencies = [
"retro-games (>=1.1.1,<2.0.0)"
]
[project.scripts]
play = "game:play"
[tool.retro]
authors = "Kayden, Connor"
description = "Use your buttons to help the catcher catch the falling fruits. Don't drop too many fruits!"
instructions = "SCore as many points as possible before losing by using the two designated buttons to move left and right."
result_file = "result.json"
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]