generated from mwc/project_game
Fixing game to working state
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
fruit_catcher/__pycache__
|
||||||
|
|||||||
0
fruit_catcher/__init__.py
Normal file
0
fruit_catcher/__init__.py
Normal file
@@ -6,11 +6,6 @@ class CatcherPiece:
|
|||||||
def __init__(self, position):
|
def __init__(self, position):
|
||||||
self.position = position
|
self.position = position
|
||||||
|
|
||||||
def play_turn(self, game):
|
|
||||||
fruit = game.get_agent_by_name("fruit")
|
|
||||||
if self.position == fruit.position:
|
|
||||||
game.state['Score'] += 1
|
|
||||||
|
|
||||||
class Catcher:
|
class Catcher:
|
||||||
width = 6
|
width = 6
|
||||||
display = False
|
display = False
|
||||||
@@ -36,14 +31,6 @@ 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
|
||||||
@@ -30,12 +30,15 @@ class Fruit:
|
|||||||
def play_turn(self, game):
|
def play_turn(self, game):
|
||||||
if game.turn_number % 3 == 0:
|
if game.turn_number % 3 == 0:
|
||||||
x, y = self.position
|
x, y = self.position
|
||||||
if y == 29:
|
if y >= 29:
|
||||||
|
for piece in self.pieces.values():
|
||||||
|
game.remove_agent(piece)
|
||||||
game.remove_agent(self)
|
game.remove_agent(self)
|
||||||
game.end()
|
game.end()
|
||||||
else:
|
else:
|
||||||
catcher = game.get_agent_by_name("catcher")
|
self.position = (x, y + 1)
|
||||||
new_position = (x, y + 1)
|
self.update_piece_positions()
|
||||||
|
self.check_catcher_collision(game)
|
||||||
|
|
||||||
def create_shape(self, game, offset):
|
def create_shape(self, game, offset):
|
||||||
x, y = self.position
|
x, y = self.position
|
||||||
@@ -45,12 +48,18 @@ class Fruit:
|
|||||||
game.add_agent(piece)
|
game.add_agent(piece)
|
||||||
|
|
||||||
def update_piece_positions(self):
|
def update_piece_positions(self):
|
||||||
if game.turn_number % 3 == 0:
|
x, y = self.position
|
||||||
self.set_color()
|
for offset, piece in self.pieces.items():
|
||||||
x, y = self.position
|
ox, oy = offset
|
||||||
if y == 29:
|
piece.position = (x + ox, y + oy)
|
||||||
|
|
||||||
|
def check_catcher_collision(self, game):
|
||||||
|
catcher = game.get_agent_by_name("catcher")
|
||||||
|
catcher_positions = {p.position for p in catcher.pieces}
|
||||||
|
for piece in self.pieces.values():
|
||||||
|
if piece.position in catcher_positions:
|
||||||
|
game.state['Score'] += 1
|
||||||
|
for p in self.pieces.values():
|
||||||
|
game.remove_agent(p)
|
||||||
game.remove_agent(self)
|
game.remove_agent(self)
|
||||||
game.end()
|
return
|
||||||
else:
|
|
||||||
catcher = game.get_agent_by_name("catcher")
|
|
||||||
new_position = (x, y + 1)
|
|
||||||
17
fruit_catcher/game.py
Normal file
17
fruit_catcher/game.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from random import randint
|
||||||
|
from retro.game import Game
|
||||||
|
from .catcher import Catcher
|
||||||
|
from .manager import FruitManager
|
||||||
|
import json
|
||||||
|
|
||||||
|
WIDTH = 27
|
||||||
|
HEIGHT = 30
|
||||||
|
|
||||||
|
def play():
|
||||||
|
agents = [
|
||||||
|
Catcher((11, 29)),
|
||||||
|
FruitManager(),
|
||||||
|
]
|
||||||
|
state = {'Score': 0}
|
||||||
|
game = Game(agents, state, board_size=(WIDTH, HEIGHT), framerate=24, color="white_on_indigo", dump_state="result.json")
|
||||||
|
game.play()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from fruit import Fruit, SHAPE_DEFINITIONS
|
from .fruit import Fruit, SHAPE_DEFINITIONS
|
||||||
from random import choice, randint
|
from random import choice, randint
|
||||||
from retro.errors import AgentNotFoundByName
|
from retro.errors import AgentNotFoundByName
|
||||||
|
|
||||||
@@ -13,6 +13,6 @@ class FruitManager:
|
|||||||
self.create_piece(game)
|
self.create_piece(game)
|
||||||
|
|
||||||
def create_piece(self, game):
|
def create_piece(self, game):
|
||||||
x = randint(0, 26)
|
x = randint(0, 25)
|
||||||
fruit = Fruit((x, 1), game, choice(SHAPE_DEFINITIONS))
|
fruit = Fruit((x, 1), game, choice(SHAPE_DEFINITIONS))
|
||||||
game.add_agent(fruit)
|
game.add_agent(fruit)
|
||||||
17
game.py
17
game.py
@@ -1,17 +0,0 @@
|
|||||||
from random import randint
|
|
||||||
from retro.game import Game
|
|
||||||
from catcher import Catcher
|
|
||||||
from manager import FruitManager
|
|
||||||
import json
|
|
||||||
|
|
||||||
WIDTH = 27
|
|
||||||
HEIGHT = 30
|
|
||||||
|
|
||||||
agents = [
|
|
||||||
Catcher((11, 29)),
|
|
||||||
FruitManager(),
|
|
||||||
]
|
|
||||||
|
|
||||||
state = {'Score': 0}
|
|
||||||
game = Game(agents, state, board_size=(WIDTH, HEIGHT), framerate=24, color="white_on_indigo")
|
|
||||||
game.play()
|
|
||||||
81
poetry.lock
generated
81
poetry.lock
generated
@@ -1,81 +0,0 @@
|
|||||||
# This file is automatically @generated by Poetry 2.2.0 and should not be changed by hand.
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ansicon"
|
|
||||||
version = "1.89.0"
|
|
||||||
description = "Python wrapper for loading Jason Hood's ANSICON"
|
|
||||||
optional = false
|
|
||||||
python-versions = "*"
|
|
||||||
groups = ["main"]
|
|
||||||
markers = "platform_system == \"Windows\""
|
|
||||||
files = [
|
|
||||||
{file = "ansicon-1.89.0-py2.py3-none-any.whl", hash = "sha256:f1def52d17f65c2c9682cf8370c03f541f410c1752d6a14029f97318e4b9dfec"},
|
|
||||||
{file = "ansicon-1.89.0.tar.gz", hash = "sha256:e4d039def5768a47e4afec8e89e83ec3ae5a26bf00ad851f914d1240b444d2b1"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "blessed"
|
|
||||||
version = "1.25.0"
|
|
||||||
description = "Easy, practical library for making terminal apps, by providing an elegant, well-documented interface to Colors, Keyboard input, and screen Positioning capabilities."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "blessed-1.25.0-py3-none-any.whl", hash = "sha256:e52b9f778b9e10c30b3f17f6b5f5d2208d1e9b53b270f1d94fc61a243fc4708f"},
|
|
||||||
{file = "blessed-1.25.0.tar.gz", hash = "sha256:606aebfea69f85915c7ca6a96eb028e0031d30feccc5688e13fd5cec8277b28d"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
jinxed = {version = ">=1.1.0", markers = "platform_system == \"Windows\""}
|
|
||||||
wcwidth = ">=0.1.4"
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
docs = ["Pillow", "Sphinx (>3)", "sphinx-paramlinks", "sphinx_rtd_theme", "sphinxcontrib-manpage"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jinxed"
|
|
||||||
version = "1.3.0"
|
|
||||||
description = "Jinxed Terminal Library"
|
|
||||||
optional = false
|
|
||||||
python-versions = "*"
|
|
||||||
groups = ["main"]
|
|
||||||
markers = "platform_system == \"Windows\""
|
|
||||||
files = [
|
|
||||||
{file = "jinxed-1.3.0-py2.py3-none-any.whl", hash = "sha256:b993189f39dc2d7504d802152671535b06d380b26d78070559551cbf92df4fc5"},
|
|
||||||
{file = "jinxed-1.3.0.tar.gz", hash = "sha256:1593124b18a41b7a3da3b078471442e51dbad3d77b4d4f2b0c26ab6f7d660dbf"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
ansicon = {version = "*", markers = "platform_system == \"Windows\""}
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "retro-games"
|
|
||||||
version = "1.1.3"
|
|
||||||
description = "A simple framework for Terminal-based games"
|
|
||||||
optional = false
|
|
||||||
python-versions = "<4.0,>=3.10"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "retro_games-1.1.3-py3-none-any.whl", hash = "sha256:4bdd27241b5cb3ee72e69a042d301ff58df2a2ade7e3c29400a538fa54e30148"},
|
|
||||||
{file = "retro_games-1.1.3.tar.gz", hash = "sha256:4f91ff725e551820aa4e30c12c0264e2da41967ed34252122b7136bc2a8ed311"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
blessed = ">=1.20.0,<2.0.0"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wcwidth"
|
|
||||||
version = "0.2.14"
|
|
||||||
description = "Measures the displayed width of unicode strings in a terminal"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.6"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "wcwidth-0.2.14-py2.py3-none-any.whl", hash = "sha256:a7bb560c8aee30f9957e5f9895805edd20602f2d7f720186dfd906e82b4982e1"},
|
|
||||||
{file = "wcwidth-0.2.14.tar.gz", hash = "sha256:4d478375d31bc5395a3c55c40ccdf3354688364cd61c4f6adacaa9215d0b3605"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[metadata]
|
|
||||||
lock-version = "2.1"
|
|
||||||
python-versions = ">=3.10,<4.0"
|
|
||||||
content-hash = "ef9faaca1f4921bdb0f3ad32c00827ffc8373223b745fd6732e8e95d90972543"
|
|
||||||
@@ -2,28 +2,35 @@
|
|||||||
name = "fruit-catcher"
|
name = "fruit-catcher"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = ""
|
description = ""
|
||||||
authors = [
|
authors = [{ name = "Kayden Dang, Connor ", email = "chris@chrisproctor.net" }]
|
||||||
{name = "Kayden Dang, Connor ",email = "chris@chrisproctor.net"}
|
|
||||||
]
|
|
||||||
license = {text = "MIT"}
|
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.10,<4.0"
|
requires-python = ">=3.10,<4.0"
|
||||||
|
license = { text = "MIT" }
|
||||||
|
classifiers = [
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Programming Language :: Python :: 3.13",
|
||||||
|
"Programming Language :: Python :: 3.14",
|
||||||
|
]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"retro-games (>=1.1.1,<2.0.0)"
|
"retro-games>=2.0.0,<3.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
play = "game:play"
|
play = "fruit_catcher.game:play"
|
||||||
|
|
||||||
|
[tool.uv.build-backend]
|
||||||
|
module-name = "fruit_catcher"
|
||||||
|
module-root = ""
|
||||||
|
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["uv_build>=0.10.0,<0.11.0"]
|
||||||
|
build-backend = "uv_build"
|
||||||
|
|
||||||
[tool.retro]
|
[tool.retro]
|
||||||
authors = "Kayden, Connor"
|
authors = "Kayden, Connor"
|
||||||
description = "Use your buttons to help the catcher catch the falling fruits. Don't drop too many fruits!"
|
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."
|
instructions = "SCore as many points as possible before losing by using the two designated buttons to move left and right."
|
||||||
result_file = "result.json"
|
result_file = "result.json"
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
||||||
build-backend = "poetry.core.masonry.api"
|
|
||||||
|
|
||||||
[tool.poetry]
|
|
||||||
package-mode = false
|
|
||||||
|
|||||||
68
uv.lock
generated
Normal file
68
uv.lock
generated
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
version = 1
|
||||||
|
requires-python = ">=3.10, <4.0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ansicon"
|
||||||
|
version = "1.89.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/b6/e2/1c866404ddbd280efedff4a9f15abfe943cb83cde6e895022370f3a61f85/ansicon-1.89.0.tar.gz", hash = "sha256:e4d039def5768a47e4afec8e89e83ec3ae5a26bf00ad851f914d1240b444d2b1", size = 67312 }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/75/f9/f1c10e223c7b56a38109a3f2eb4e7fe9a757ea3ed3a166754fb30f65e466/ansicon-1.89.0-py2.py3-none-any.whl", hash = "sha256:f1def52d17f65c2c9682cf8370c03f541f410c1752d6a14029f97318e4b9dfec", size = 63675 },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "blessed"
|
||||||
|
version = "1.33.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "jinxed", marker = "platform_system == 'Windows'" },
|
||||||
|
{ name = "wcwidth" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/68/5c/92dc10a25a4eafb4b9bef5dad522a0b7d5d5b55d2d76f9a6721b2e49ca2c/blessed-1.33.0.tar.gz", hash = "sha256:c732a1043042d84f411423a1a7b74643e1dd3a2271bd6e5955682dd4a321b0ef", size = 13980368 }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/22/04/2b4e111e0b902b1ac0b25e5e010af71c79fca093a3399bd7f8b82adcc536/blessed-1.33.0-py3-none-any.whl", hash = "sha256:1bc8ecac6d139286ea51ec1683433528ce75b0c60db77b7d881112bf9fc85b0f", size = 111519 },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fruit-catcher"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = { editable = "." }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "retro-games" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.metadata]
|
||||||
|
requires-dist = [{ name = "retro-games", specifier = ">=2.0.0,<3.0.0" }]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jinxed"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "ansicon", marker = "platform_system == 'Windows'" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/20/d0/59b2b80e7a52d255f9e0ad040d2e826342d05580c4b1d7d7747cfb8db731/jinxed-1.3.0.tar.gz", hash = "sha256:1593124b18a41b7a3da3b078471442e51dbad3d77b4d4f2b0c26ab6f7d660dbf", size = 80981 }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/27/e3/0e0014d6ab159d48189e92044ace13b1e1fe9aa3024ba9f4e8cf172aa7c2/jinxed-1.3.0-py2.py3-none-any.whl", hash = "sha256:b993189f39dc2d7504d802152671535b06d380b26d78070559551cbf92df4fc5", size = 33085 },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "retro-games"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "blessed" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/61/4d/f1f75a461f4e78d743046c906b8e9e0b609f1ed905f7c79fc8d1125acf97/retro_games-2.0.0.tar.gz", hash = "sha256:46ed67bd50139daca0577d486d23e8b8cb1c30cda45226590f9207981cf3948c", size = 14989 }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/67/05/cb166180d20f47e4644bba8e0ecf65078c3b007a5106278e1db9ea7734cd/retro_games-2.0.0-py3-none-any.whl", hash = "sha256:03882090bb19e689fdbe173ac31fdf6d5ab7d10881f9b7af21b96588ce3f695a", size = 21787 },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wcwidth"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/35/a2/8e3becb46433538a38726c948d3399905a4c7cabd0df578ede5dc51f0ec2/wcwidth-0.6.0.tar.gz", hash = "sha256:cdc4e4262d6ef9a1a57e018384cbeb1208d8abbc64176027e2c2455c81313159", size = 159684 }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/68/5a/199c59e0a824a3db2b89c5d2dade7ab5f9624dbf6448dc291b46d5ec94d3/wcwidth-0.6.0-py3-none-any.whl", hash = "sha256:1a3a1e510b553315f8e146c54764f4fb6264ffad731b3d78088cdb1478ffbdad", size = 94189 },
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user