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): def play_turn(self, game):
fruit = game.get_agent_by_name("fruit") fruit = game.get_agent_by_name("fruit")
if new_position == fruit.position: if self.position == fruit.position:
game.state['Score'] += 1 game.state['Score'] += 1
class Catcher: class Catcher:
@@ -36,6 +36,14 @@ class Catcher:
if x + self.width < width: if x + self.width < width:
self.position = (x+1, y) self.position = (x+1, y)
self.update_piece_positions() 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): def create_pieces(self, game):
x, y = self.position x, y = self.position

View File

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

View File

@@ -2,6 +2,7 @@ from random import randint
from retro.game import Game from retro.game import Game
from catcher import Catcher from catcher import Catcher
from manager import FruitManager from manager import FruitManager
import json
WIDTH = 27 WIDTH = 27
HEIGHT = 30 HEIGHT = 30

View File

@@ -1,5 +1,5 @@
from fruit import Fruit, SHAPE_DEFINITIONS from fruit import Fruit, SHAPE_DEFINITIONS
from random import choice from random import choice, randint
from retro.errors import AgentNotFoundByName from retro.errors import AgentNotFoundByName
class FruitManager: class FruitManager:
@@ -13,5 +13,6 @@ class FruitManager:
self.create_piece(game) self.create_piece(game)
def create_piece(self, 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) game.add_agent(fruit)

View File

@@ -1,9 +1,9 @@
[project] [project]
name = "project-game" name = "fruit-catcher"
version = "0.1.0" version = "0.1.0"
description = "" description = ""
authors = [ authors = [
{name = "Chris Proctor",email = "chris@chrisproctor.net"} {name = "Kayden Dang, Connor ",email = "chris@chrisproctor.net"}
] ]
license = {text = "MIT"} license = {text = "MIT"}
readme = "README.md" readme = "README.md"
@@ -12,6 +12,14 @@ dependencies = [
"retro-games (>=1.1.1,<2.0.0)" "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] [build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"] requires = ["poetry-core>=2.0.0,<3.0.0"]