From cff41293366cf924dcca1c6c82b5eb0fa5989db9 Mon Sep 17 00:00:00 2001 From: Cory Date: Sat, 18 May 2024 20:24:36 -0400 Subject: [PATCH] Installed retro and got a cursor that moves... Need to do: -Populate 10 mines randomly -Have the game end when a mine is selected (figure out how to select something) -Figure out an algorithm to reveal squares -Figure out how to show numbers in revealed squares -Add flag functionality? --- __pycache__/cursor.cpython-312.pyc | Bin 0 -> 1388 bytes cursor.py | 28 ++++++++++++++++++++++++++++ minesweeper_game.py | 12 ++++++++++++ poetry.lock | 7 +++++++ pyproject.toml | 2 ++ 5 files changed, 49 insertions(+) create mode 100644 __pycache__/cursor.cpython-312.pyc create mode 100644 cursor.py create mode 100644 minesweeper_game.py create mode 100644 poetry.lock diff --git a/__pycache__/cursor.cpython-312.pyc b/__pycache__/cursor.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7e3f3c7e22d20d4a4c16da6d445d54765af4b045 GIT binary patch literal 1388 zcmaJ=&rcgy5Polem^C&v)TofC1yd2J8!Ee~ic~3pRFx#q5~r#XRk4ts+}#B)#=GY2 zy42P>;=sWiD&P<~N9WX3`~&?TatSDh)jLJXDK``!D&^FfwH>9XbS%%#?94YaZ}xl7 zM@EJT$l>kPjps5UuhAKZ(l@%3V6=%u?hupg6O*1uy-0!7C0#ZK`S_%Lr<(zzO)OHN zCMifJEy$)+P)vEB6jW0I9jmK)OvJvcanI!!cYM&$y!4$-F6 zlmjT)06T!P4LHJv6c83cP}PYp=igwVH#m?^g;sSv+qYduSA^nO+Z$r|7q`ew=GhHP zBzpF)ZTcmV>^UXN-YoeZE+GT*ZYB4?v$&Ttj8e_n%q?49*>|hCO0jG^n{3ziOU!Uh zD_7Yy=5sa2_P@?mxw~Z9d0uacJg!4r-5tv)NN^ zrjPeq;{5oU|{cnaAsQ=~(AaLmym6r_%zzX@6wNypk{0~&iV$V6UdGW;V1jh2dzxoxrc*v3Sk zTo(f)kna5f3P_epA2tt~2TF^!=EKDJ;nKm3sWC z?d&{h94EuEtL>@dsm{%_vFv{azBwC<5c8d#r#BGs3gCU`DB17$Wc_98dYGPQFCH&; zK7E(}g=XKgc%_0;hiYmR+7J7p$@oVr7iRfX=bD2{5_wWRreoH__fPVmW-9>Hy literal 0 HcmV?d00001 diff --git a/cursor.py b/cursor.py new file mode 100644 index 0000000..f8c48da --- /dev/null +++ b/cursor.py @@ -0,0 +1,28 @@ +# cursor.py +# ------------ +# By MWC Contributors +# This module defines a spaceship agent class. +class Cursor: + name = "cursos" + character = 'O' + + def __init__(self, board_size): + board_width, board_height = board_size + self.position = (board_width // 2, board_height - 1) + + def handle_keystroke(self, keystroke, game): + x, y = self.position + if keystroke.name in ("KEY_LEFT", "KEY_RIGHT", "KEY_UP", "KEY_DOWN"): + if keystroke.name == "KEY_LEFT": + new_position = (x - 1, y) + elif keystroke.name == "KEY_RIGHT": + new_position = (x + 1, y) + elif keystroke.name == "KEY_UP": + new_position = (x, y - 1) + else: + new_position = (x, y + 1) + if game.on_board(new_position): + if game.is_empty(new_position): + self.position = new_position + else: + game.end() \ No newline at end of file diff --git a/minesweeper_game.py b/minesweeper_game.py new file mode 100644 index 0000000..1841ef8 --- /dev/null +++ b/minesweeper_game.py @@ -0,0 +1,12 @@ +# minesweeper_game.py +# ------------ +# By Cory +# This class implements a simple minesweeper game on a 9x9 gird. +from retro.game import Game +from cursor import Cursor + +board_size = (9, 9) +cursor = Cursor(board_size) +# spawner = AsteroidSpawner(board_size) +game = Game([cursor], {"score": 0}, board_size=board_size) +game.play() \ No newline at end of file diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..86a4a80 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +package = [] + +[metadata] +lock-version = "2.0" +python-versions = "^3.11" +content-hash = "81b2fa642d7f2d1219cf80112ace12d689d053d81be7f7addb98144d56fc0fb2" diff --git a/pyproject.toml b/pyproject.toml index 1e94b25..351c89a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,8 @@ packages = [{include = "project_game"}] [tool.poetry.dependencies] python = "^3.11" +retro-games = "^0.1.2" + [build-system]