From 3334db0c8bb68b591bca79616d1c78838014a4bc Mon Sep 17 00:00:00 2001 From: Cory Date: Sat, 18 May 2024 21:03:33 -0400 Subject: [PATCH] Figured out how to spawn a mine and end the game if the cursor is over the mine. We now have to not end the game until the user SELECTS the space the mine is at. I hadn't realized that is_empty only works if display is True? So I moved the game.end() to the mine class. --- __pycache__/cursor.cpython-312.pyc | Bin 1388 -> 1422 bytes __pycache__/mine.cpython-312.pyc | Bin 0 -> 903 bytes __pycache__/mine_spawner.cpython-312.pyc | Bin 0 -> 1224 bytes cursor.py | 9 ++++----- mine.py | 14 ++++++++++++++ mine_spawner.py | 20 ++++++++++++++++++++ minesweeper_game.py | 4 +++- 7 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 __pycache__/mine.cpython-312.pyc create mode 100644 __pycache__/mine_spawner.cpython-312.pyc create mode 100644 mine.py create mode 100644 mine_spawner.py diff --git a/__pycache__/cursor.cpython-312.pyc b/__pycache__/cursor.cpython-312.pyc index 7e3f3c7e22d20d4a4c16da6d445d54765af4b045..d0d3dc80e490efcecb5600cebd754f3502c18ccc 100644 GIT binary patch delta 171 zcmaFE)yK_ynwOW00SI>cd!}uk$lJtNv~hwfBV)?sYm9b`lP4E4iBHyHTEu8N`8<;% zpK=Xr4MRLgIS5Q*7FVoc$bxWC$kmJxE+a$bWCi9d=A8WW$-T@ujGHI_VxA&7#rKAY y#B`5|9y3Db$IgtsDx&>?l|e-R1M}qBERD>3tU8nBSsi%A7&~g;*)il7BOl~KF_2m zz){0m!w?Tr4hEHz|1pVku7>g$Cz~;6F{kFGOkT{K!?=910Lv8KslE?HB&K^z^qA`P efphX+mPTfNR{6<}tPZ^5jPjotfJBi1P&)wj*&~Pm diff --git a/__pycache__/mine.cpython-312.pyc b/__pycache__/mine.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dd3da800fbb97f5b636aea974f3878a0dd9f6302 GIT binary patch literal 903 zcmaJHV%6ujGjwg$|YNMws}G9sK#q=ltU`jRf2i9gN!ng!wU97*E70}J=83^Q`Hd3GvZJYu#CPUgz=7O#<4N3d& z)?@7?_6+Vp6!vw6I1QH))&DaLz>Q0YNluEDVCh$A63Y}u3`3S{gVmRAPixts*3fVs zS|ilvv;sRz+X1t>Uf35ikK~TqjN~BnBiVAeF8SDbq~IXqefU^yl<_)^J_~!kGgubW z{3BljbMOEF##tzy92_0Ieg1yu-OhR8_B6M0vVFAuy`+D9c&dEPf6D(@ub!2vUy5g? zjq}{2*na%vLM1EfJ~md-e)YzGS+o@uY-J!u~)rDC$=ncJHQfr+@^mW-~$l} zM7cihPJsAWXdaR2a`ABMQlaXtSxQ#R3vYCUFS!V~fl*k6NHR~~Up!v*%b>%x1_gi% QnNs>Io1x`P0w4l@17T&m1^@s6 literal 0 HcmV?d00001 diff --git a/__pycache__/mine_spawner.cpython-312.pyc b/__pycache__/mine_spawner.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..12e8251537d4a416f7a982d28501df16fa4360b8 GIT binary patch literal 1224 zcmZ8hKTH#06#u@vYbjj$V~|im4X8vL4AlUG2Azo1!6ru3(14#uzoWg<-j(mJl9G}z zFu8`H|^j9G^j;RmmBo=vY>%xvC5~;kIjEw8{ykq4eS#91hlMvlW zv4q9-NOm!CH4*R$5OuEU9I|4(&0!+TT#F;072o0L9qS#WS4`)vZCuYhMAj zLdv0Q>#b|PwKwIV;ZHAi0)uPHULdr2W4~vx0swMuSOGA2!#W0GgA{2RAq~Xo{4GL6 z%0Z+@j;}6p7--sG*ZzNVx&+5mKY|84W^JJJ_&I62wwPrJYEm1(pcbVx_S`^qFN&SC zH#~w`JdI0X;jnT!c8G}t9#A;os!m>*%*)lRmZM+=pcpF`hzMI^bc|WrkypDQoJ+?WrAM877BEf!v>0)6&9+n9uGv>B1mbG|3 zgL06ug}j!jy)<#d#ySO#R9ph~k$3^T)&#EKV>lxF0pY)!~NF+nco)=PIgLoEQ5fFjlSUq38n}?#k{4b|h0u{{#u`{YAR|Dk|+i ICcr$$e;@e}-T(jq literal 0 HcmV?d00001 diff --git a/cursor.py b/cursor.py index f8c48da..c4b5765 100644 --- a/cursor.py +++ b/cursor.py @@ -1,9 +1,9 @@ # cursor.py # ------------ -# By MWC Contributors -# This module defines a spaceship agent class. +# By Cory +# This module defines a cursor agent class. class Cursor: - name = "cursos" + name = "cursor" character = 'O' def __init__(self, board_size): @@ -24,5 +24,4 @@ class Cursor: 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 + game.log(self.position) \ No newline at end of file diff --git a/mine.py b/mine.py new file mode 100644 index 0000000..4cce7c5 --- /dev/null +++ b/mine.py @@ -0,0 +1,14 @@ +# mine.py +# ------------ +# By Cory +# This module defines a mine agent class. It doesn't do anything except exist in a position +class Mine: + display = False + + def __init__(self, position): + self.position = position + + def play_turn(self, game): + if not game.is_empty(self.position): + game.log("You hit a mine at " + str(self.position) + ".") + game.end() \ No newline at end of file diff --git a/mine_spawner.py b/mine_spawner.py new file mode 100644 index 0000000..ecdceb3 --- /dev/null +++ b/mine_spawner.py @@ -0,0 +1,20 @@ +# mine_spawner.py +# ------------ +# By Cory +# This module defines a mine spawner agent class. It spawns mines! + +from random import randint +from mine import Mine + +class MineSpawner: + display = False + + def __init__(self, board_size): + width, height = board_size + self.board_width, self.board_height = width, height + + def play_turn(self, game): + if game.turn_number == 1: + mine = Mine(((randint(0, self.board_width - 1)),(randint(0, self.board_height - 1)))) + game.log(mine.position) + game.add_agent(mine) \ No newline at end of file diff --git a/minesweeper_game.py b/minesweeper_game.py index 1841ef8..b6f99b4 100644 --- a/minesweeper_game.py +++ b/minesweeper_game.py @@ -4,9 +4,11 @@ # This class implements a simple minesweeper game on a 9x9 gird. from retro.game import Game from cursor import Cursor +from mine_spawner import MineSpawner board_size = (9, 9) cursor = Cursor(board_size) +spawner = MineSpawner(board_size) # spawner = AsteroidSpawner(board_size) -game = Game([cursor], {"score": 0}, board_size=board_size) +game = Game([cursor,spawner], {"score": 0}, board_size=board_size,debug=True) game.play() \ No newline at end of file