From 0876b4c7732d1f5651eb51fc87b51b6cb7db0dbe Mon Sep 17 00:00:00 2001 From: Valentin Lucas <21901740@etu.unicaen.fr> Date: Thu, 2 Dec 2021 19:56:37 +0100 Subject: [PATCH 1/7] Ajouts d'images et quelques modification de cell et Gui --- .../java/fr/lnl/game/client/view/Cell.java | 26 +++++++++++++++--- .../java/fr/lnl/game/client/view/GUI.java | 16 ++++++++--- .../main/resources/images/bottomLeftWall.PNG | Bin 0 -> 6059 bytes .../main/resources/images/bottomRightWall.PNG | Bin 0 -> 6136 bytes .../src/main/resources/images/bottomWall.PNG | Bin 0 -> 4777 bytes .../src/main/resources/images/rightWall.PNG | Bin 0 -> 6101 bytes .../src/main/resources/images/topLeftWall.PNG | Bin 0 -> 5623 bytes .../main/resources/images/topRightWall.PNG | Bin 0 -> 6346 bytes client/src/main/resources/images/topWall.PNG | Bin 0 -> 4741 bytes 9 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 client/src/main/resources/images/bottomLeftWall.PNG create mode 100644 client/src/main/resources/images/bottomRightWall.PNG create mode 100644 client/src/main/resources/images/bottomWall.PNG create mode 100644 client/src/main/resources/images/rightWall.PNG create mode 100644 client/src/main/resources/images/topLeftWall.PNG create mode 100644 client/src/main/resources/images/topRightWall.PNG create mode 100644 client/src/main/resources/images/topWall.PNG diff --git a/client/src/main/java/fr/lnl/game/client/view/Cell.java b/client/src/main/java/fr/lnl/game/client/view/Cell.java index 7028f9d..fa51585 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Cell.java +++ b/client/src/main/java/fr/lnl/game/client/view/Cell.java @@ -5,6 +5,7 @@ import fr.lnl.game.server.games.grid.EnergyBall; import fr.lnl.game.server.games.grid.Mine; import fr.lnl.game.server.games.grid.Wall; import fr.lnl.game.server.games.player.Player; +import fr.lnl.game.server.utils.Cardinal; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.StackPane; @@ -37,17 +38,34 @@ public class Cell extends Rectangle { if(object instanceof Player){ image = new Image("file:resources/images/player.png"); } - if(object instanceof EnergyBall){ + else if(object instanceof EnergyBall){ image = new Image("file:resources/images/energyBall.png"); } - if(object instanceof Bomb){ + else if(object instanceof Bomb){ image = new Image("file:resources/images/bomb.jpg"); } - if(object instanceof Mine){ + else if(object instanceof Mine){ image = new Image("file:resources/images/mine.webp"); } else{ - image = new Image("file:resources/images/wall.jpg"); + //test + if(((Wall)object).getCardinal()== Cardinal.NORTH){ + image = new Image("file:resources/topWall.png"); + }else if(((Wall)object).getCardinal()== Cardinal.SOUTH) { + image = new Image("file:resources/bottomWall.png"); + }else if(((Wall)object).getCardinal()== Cardinal.EAST) { + image = new Image("file:resources/rightWall.png"); + }else if(((Wall)object).getCardinal()== Cardinal.WEST) { + image = new Image("file:resources/leftWall.png"); + }else if(((Wall)object).getCardinal()== Cardinal.NORTH_EAST) { + image = new Image("file:resources/topRightWall.png"); + }else if(((Wall)object).getCardinal()== Cardinal.NORTH_WEST) { + image = new Image("file:resources/topLeftWall.png"); + }else if(((Wall)object).getCardinal()== Cardinal.SOUTH_EAST) { + image = new Image("file:resources/bottomRightWall.png"); + }else{ + image = new Image("file:resources/bottomLeftWall.png"); + } } ImageView iv = new ImageView(image); diff --git a/client/src/main/java/fr/lnl/game/client/view/GUI.java b/client/src/main/java/fr/lnl/game/client/view/GUI.java index 175918f..95ec317 100644 --- a/client/src/main/java/fr/lnl/game/client/view/GUI.java +++ b/client/src/main/java/fr/lnl/game/client/view/GUI.java @@ -52,9 +52,8 @@ public class GUI { private Parent createContent() { Pane principalPane = new Pane(); principalPane.setPrefSize(width * cellSize, height * cellSize); - //PARTIE1 - //à définir avec n pour moduler la taille du plateau + //à définir avec n pour moduler la taille du plateau for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { Cell cell = new Cell(i, j); @@ -62,7 +61,6 @@ public class GUI { } } - //PARTIE2 board = grid.getBoard(); for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { @@ -71,11 +69,20 @@ public class GUI { addToPrincipalPanel(value.getA(), principalPane, i, j); } if (value.getB() instanceof Wall || value.getB() instanceof EnergyBall || value.getB() instanceof Mine || value.getB() instanceof Bomb) { + System.out.println(value.getB()); addToPrincipalPanel(value.getB(), principalPane, i, j); } } } - //PARTIE3 + + Rectangle shape = new Rectangle(); + shape.setX(700); + shape.setY(20); + shape.setWidth(200); + shape.setHeight(600); + shape.setFill(javafx.scene.paint.Color.WHITE); + + Button followingButton = new Button("SUIVANT"); followingButton.setLayoutX(775); followingButton.setLayoutY(600); @@ -84,6 +91,7 @@ public class GUI { //add un eventListener au button principalPane.getChildren().add(followingButton); + //pas compris le principe return principalPane; } diff --git a/client/src/main/resources/images/bottomLeftWall.PNG b/client/src/main/resources/images/bottomLeftWall.PNG new file mode 100644 index 0000000000000000000000000000000000000000..af2c6309af8867c5dff1b5e07154af0efbf33b7c GIT binary patch literal 6059 zcmeAS@N?(olHy`uVBq!ia0y~yVEh8Y9Be?5)7S2I0V&4fAa^H*b?0PW0y!?J5uRzj zz6@GGHU|S^dnN-5NC^;20Wkvu^8!W&W+2T75?jColV$v}fEmFCDJ;)B*TBFaF6!yx z7*fIb_U^%~SW5<%gB2(K|Nk`mq~7$Kku5Lg={X;W(g+LJpXJW<@7Kr2$Di-Fzq)>X zmcdRA0R@MK1Mivs|Ec?6%gDq6}pQ1an1)8*jvazjJ9Uw`DI=GISXR6fWZrXK6YwZ z^Wgd8FYSEu&;PG?etmuV{hVLzJN|A3dBH&Af$*<{mrBAw*E#qfSn%CyY6r*%Y(U41 z3Xg`#Xo48c4WmWDXz@5&H;h({qpgC`Cedg!akPy*+CdoY9gX%FN4v|TV+ErFC8MK6 zkddH3$HFFr3Uf{gM7GS0uS_-L0aXv8m?iLG{ZekN$ZPeChTBnyA|od5J!ja~g~ z_uo4~gO3gmyc*Z9U!TAKwECC)%R4NJu z)i$<*6ExZ?@MGJ7_4T#i_g~(3_PG*RWQX$s^)J>{AGpAyrUfbq7y5t1Kt^E8IV479 d@Pxr1?nf;=uNPc;n++N$_jL7hS?83{1ONxq>ZJex literal 0 HcmV?d00001 diff --git a/client/src/main/resources/images/bottomRightWall.PNG b/client/src/main/resources/images/bottomRightWall.PNG new file mode 100644 index 0000000000000000000000000000000000000000..3e87801394b12e783ff2b3e76a37259cd524c7ba GIT binary patch literal 6136 zcmeAS@N?(olHy`uVBq!ia0y~yVEh8Y9Be?5)7S2I0V&4fAa^H*b?0PW0y!?J5uRzj zz6@GGHU|S^dnN-5NC^;20Wkvu^8!W&W+2T75?jColV$v}fEmFCDJ;)B*TBFap5*D` z7*fIb_O4@Jh@k+hqtw~I>+ftx_gw0|srm1f!ym<0PMq-L&!=_UeqFgg zzjj8spn^jKL*sN7mcL8azg^41A)rvOwqZg1?@ZeskkU9IfiKhdZQCvcRCZu1Q&ZjB z>OWp=eT$f6i+g%{WBqWG1m zV#%MF-$r1g7@4@4?!Vvv-}&|P&nN$@)j6N< z7f02~*JhxBL;(vGg%|A$&O%1{f*dY*$8P5YaSkXlI@+`3wt>g_rZ6?dz1rmq&c1w{ z9KRGZjKK+cfr!ADpzFC{Lkm0{F7P|fRs`F&v|+*YU3tRbp+jfj=qAT49 zrL)0?$^eHzoiC(;O2q~TO@$Xr*WCsi`d~uC0{JF0XRvKvjE=PS!jGTxAK!ofy}s_w zdC+Jq&~47ZfRk@3f%rWKI0n0HAHA&R^mE^L4D7VNY}M@C2aBPCs6MLEETn6@Vt9QXzr3NM;x_(2Apb%73>wA~vV zer&8PwE~wl!HPDhD!hpPR0fIO1q}=MldN39ing(^)Oz331G`TG7^RLr%fYd7U|Pch dntS38<4zBr=YDsqHiJgpJzf1=);T3K0RZE?nf(9& literal 0 HcmV?d00001 diff --git a/client/src/main/resources/images/bottomWall.PNG b/client/src/main/resources/images/bottomWall.PNG new file mode 100644 index 0000000000000000000000000000000000000000..328719693a63ee845a398f2e03904d287c2d0823 GIT binary patch literal 4777 zcmeAS@N?(olHy`uVBq!ia0y~yVEh8Y9Be?5)7S2I0V&4fAa^H*b?0PW0y!?J5uRzj zz6@GGHU|S^dnN-5NC^;20Wkvu^8!W&W+2T75?jColV$v}fEmFCDJ;)B*TBFaB<$(p z7*fIb_LgIo6C)2xfbQP^Q**ufA2j&PI9i-tCln`k*j=7qo{5D+K*6DbfpL^E8VI8) zVKf(v=7P~&Fq#WSbHQjX7|jKvxnMLGjOK#TTripom{_!!&fj0R-Yeag6C4_i#*OPY zd$I{a`p%||jd6>w&H(qK?{IQ_vCf_h?p8baIxM)JVX6l1V3#v7{XKU}1)QM*gauxh zM)iWtIxx4vVgF{cPO$DPEG$*MVaZ@c1?mbH-mmdh0_z^aR($w-a>e!6Ur#=srwSQq zxW{2L|Gc^A|M+U>{uv_RFl@|aY}{8Xe;dN_a9H5((*+K~1KS!L?(ge=3kgq^58u6a z*KczTfl97xF#mG*_KhBJ*d1YFvRxMB0nV>wtSrCY<>t77IZ2F-a>1G^V9R$iG1Y!I zGgAh0Ha0l)uM`miMPg$t&;ixbvmp+Ma9D6WgbNZq>wpf}+j|z`03C%3$y%-8L6d}V zhXwEN9ZLgq6vPBx7*2Hp$J+*Ng$w2R$;M!g05`{%8D5Iu@s%5*0xx!N-zW*@bg;5i m`7E6PcKI7F4%&O;0Ds#f*4*8@kK2NVi9B8XT-G@yGywo58Mo8` literal 0 HcmV?d00001 diff --git a/client/src/main/resources/images/rightWall.PNG b/client/src/main/resources/images/rightWall.PNG new file mode 100644 index 0000000000000000000000000000000000000000..f2f5278ddc04ddbe187b500e3dbe0641478dc5ff GIT binary patch literal 6101 zcmeAS@N?(olHy`uVBq!ia0y~yVEh8Y9Be?5)7S2I0V&4fAa^H*b?0PW0y!?J5uRzj zz6@GGHU|S^dnN-5NC^;20Wkvu^8!W&W+2T75?jColV$v}fEmFCDJ;)B*TBFaZtv;h z7*fIb_U^%4Wk&%P$F&asW8)+j>^`>#e`m!T{c--&YRB`c7&6%0 z(y(BDz;;jYFl`$vORdC}=b%C8h69|8j`j=lCWD4=Ie54^ei^JdF9;sM6=rIxbGoYr z9<`Ma6Zn!CFdsA=&B&w<9FK0<}cyV}vojcfEKMsyxoTanD7A8bETxfT! z?E{-TM?m0<@GCP;u!S2M7VtO!k^!4*p{Vde{Yoxq$eW=tvC)14H^=jM`QF{2A$3nz KKbLh*2~7ZQfL}KN literal 0 HcmV?d00001 diff --git a/client/src/main/resources/images/topLeftWall.PNG b/client/src/main/resources/images/topLeftWall.PNG new file mode 100644 index 0000000000000000000000000000000000000000..73a2dd5178939c38af150674c9e257a20b1586c9 GIT binary patch literal 5623 zcmeAS@N?(olHy`uVBq!ia0y~yVEh8Y9Be?5)7S2I0V&4fAa^H*b?0PW0y!?J5uRzj zz6@GGHU|S^dnN-5NC^;20Wkvu^8!W&W+2T75?jColV$v}fEmFCDJ;)B*TBFan&|1` z7*fIb_SQu&CPs;tK=Yda;rDcQeaT|JnD2MNH{so!pNSK!^0wdp`Qw{w0|O%y3rEd{ z1J~K@ce|@QfcgJecy5^3JDkPf>jG}a7cV{=u{E_D`|em29$GX zaBw)VfZa=^5v)X_#2jK26BC~mIF>Vm4N?F)g;})=Vgt`EX=*w3dw7b)`Ol*Hk8Q#B z9dPHCIbQhlXRXtIpXaS$n;+D&@cjB+^3W5aAeFJXZss{|PLKx<{04@~_m_tzLws|Z zN&n~a9qInx=iC3W|6N<>2KLW1)*7eyy!bLuFq{CY_nF!R*1M^}aRdt=u$BAQ@m#nc zoOJ$h{b+e701n?_kferC>K}C~Ey|S9P#q1`p;G^irq$83I+|9g-mDzWR-@T!G+T{k zD^QYP7H#Ev!f^tSsbM(q}wWpRW%d;F}=+fzvjAV*_Z+Yy)txPCRPb kM9|>QC*Ww{kQe^I`<<8L!;POoput-PPgg&ebxsLQ0HOZ;CIA2c literal 0 HcmV?d00001 diff --git a/client/src/main/resources/images/topRightWall.PNG b/client/src/main/resources/images/topRightWall.PNG new file mode 100644 index 0000000000000000000000000000000000000000..74ff2dcb07920c32bc3b560292d793bd97e9f489 GIT binary patch literal 6346 zcmeAS@N?(olHy`uVBq!ia0y~yVEh8Y9Be?5)7S2I0V&4fAa^H*b?0PW0y!?J5uRzj zz6@GGHU|S^dnN-5NC^;20Wkvu^8!W&W+2T75?jColV$v}fEmFCDJ;)B*TBFaVdClH z7*fIb_LgIwjJtrVi)V&>hO6PaxUzFl7*zklEVKdGfH8d>v%?qL#8rfM`{x&NA zVgc({cu~g;F^7@SvHn4aT_Z>*2gk1aU|OKU!Qq0u#Ug)@PDY^7=0n8j2jxH8-oJlu zls66Rk3ae>`}Xa#`#1NW(|?PN;*fwi&&~1cdGB6`k85HaF4+6MVTA<7XQrlqmC5-K zU(1Vo{13k4|Hu7bKX(NqD0l=cGzwnVOMDmqbx^rV1T3;cRpG_ z&J`RDd7K=-bSvMhf+c@H4nbePp_4&nFkGo)W-KupPtJ5=cHei1__Cdh6VjHhorzEv4Df4 z>Y}kXI3V3vSZbdLT!Tc4tHXuvd6D1%GEh=@q1?WK4IB>|OigiL&Ip0SSCG+B-m=9M zocjwhopuc4vt?Z6xTR{P3>w}Aa1)EY*~Vf!v%M~L|(9|0W2(gU(AHWnle+9 zT@gn%B-sFMb3LyEwoC$O=tSp;W^km7FglKUVKf#%sckeNjpl{X5^1zh9jzAx6h>?3 z(FVq78)>wqI@;Lg5E$(*jP}|_JD#I`XYf$a=m^H>Ak64E(twQS#Vc1s2kri}9Qf|P z=gBeaKdp7ncda1doNuCd$bo^sNTF$5@HXlNR?0O1aPQ*;nEleRzQ*)*r$*< z0Eapx=|Ex}93qfZGpcwrphi=|Xf7Dd1*5rOG#8BKg3(+snhQpA!DucR%>|>mVA$t^ c2hUmF9h}da+Y Date: Thu, 2 Dec 2021 19:59:53 +0100 Subject: [PATCH 2/7] Add placement rules for walls, energyballs and players --- .../java/fr/lnl/game/server/games/Game.java | 12 +-- .../fr/lnl/game/server/games/grid/Grid.java | 100 +++++++++++++++--- 2 files changed, 86 insertions(+), 26 deletions(-) diff --git a/server/src/main/java/fr/lnl/game/server/games/Game.java b/server/src/main/java/fr/lnl/game/server/games/Game.java index 993219d..97cd161 100644 --- a/server/src/main/java/fr/lnl/game/server/games/Game.java +++ b/server/src/main/java/fr/lnl/game/server/games/Game.java @@ -29,27 +29,19 @@ public class Game { private final Object lock = new Object(); public Game(Grid grid, List players, ModelListener viewUpdate, ModelListener gameFinishEvent) throws IllegalArgumentException { - if(players.size() < 2) + if(players.size() < 2 || grid.getNumberNeutralBox() < players.size()) throw new IllegalArgumentException("The game need 2 or more player to start"); this.players = players; this.currentPlayer = players.get(0); this.grid = grid; this.viewUpdateEvent = viewUpdate; this.gameFinishEvent = gameFinishEvent; - placePlayersBRUT(); - + grid.initPlacePlayers(); } /** * @deprecated utiliser pour le moment, nécessite une meilleure implémentation pour savoir ou placé les joueurs */ - @Deprecated - public void placePlayersBRUT(){ - grid.getBoard().get(new Point(7,7)).setA(grid.getPlayers().get(0)); - grid.getPlayers().get(0).setPosition(new Point(7, 7)); - grid.getBoard().get(new Point(7,8)).setA(grid.getPlayers().get(1)); - grid.getPlayers().get(1).setPosition(new Point(7, 8)); - } public void play() { while(!isOver()) { diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java b/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java index 4f0f11e..175f6c3 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java @@ -1,5 +1,6 @@ package fr.lnl.game.server.games.grid; +import fr.lnl.game.server.games.player.AbstractPlayer; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Cardinal; import fr.lnl.game.server.utils.Pair; @@ -7,6 +8,7 @@ import fr.lnl.game.server.utils.Point; import java.util.HashMap; import java.util.List; +import java.util.Random; public class Grid { @@ -15,12 +17,18 @@ public class Grid { private final int column; private final List players; - public Grid(int row, int column, List players) { + public Grid(int row, int column, List players, float wallProbability, float energyProbability) { this.row = row; this.column = column; this.players = players; board = new HashMap<>(); + initBoard(wallProbability, energyProbability); + } + + public void initBoard(float wallProbability, float energyProbability){ initGrid(); + initPlaceInternWall(wallProbability); + initPlaceEnergyBall(energyProbability); } public void initGrid(){ @@ -51,21 +59,54 @@ public class Grid { } } - public void placePlayersBRUT(){ - board.get(new Point(1,1)).setA(players.get(0)); - board.get(new Point(14,14)).setA(players.get(1)); + public void initPlacePlayers(){ + Random random = new Random(); + Box boxTargeted; + Player playerTargeted; + Point point; + for (Player player: players) { + do{ + int i = random.nextInt(1,getRow() - 1); + int j = random.nextInt(1,getColumn() - 1); + point = new Point(i,j); + Pair pairTargeted = getBoard().get(point); + boxTargeted = pairTargeted.getB(); + playerTargeted = pairTargeted.getA(); + }while(playerTargeted != null || !isNeutralBox(boxTargeted)); + getBoard().get(point).setA(player); + player.setPosition(point); + } } - public void placeEnergyBallBRUT(){ - board.get(new Point(2,3)).setB(new EnergyBall()); - board.get(new Point(7,10)).setB(new EnergyBall()); + + public void initPlaceEnergyBall(float probability){ + for (int i = 1; i < row - 1; i++) { + for (int j = 1; j < column - 1; j++) { + if(Math.random() >= probability){ + Point point = new Point(i,j); + if(!(getBoard().get(point).getB() instanceof Wall)){ + getBoard().get(point).setB(new EnergyBall()); + } + } + } + } } - public void placeInternWallBRUT(){ - board.get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6)); - board.get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14)); - board.get(new Point(10,7)).setB(new Wall(Cardinal.EAST,10,7)); - board.get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2)); + public void initPlaceInternWall(float probability){ + for (int i = 1; i < row - 1; i++) { + for (int j = 1; j < column - 1; j++) { + if(Math.random() >= probability){ + Point point = new Point(i,j); + if(getIllusionNumberWallNeighbour(point) <= 3){ + getBoard().get(point).setB(new Wall(Cardinal.getRandom(),i,j)); + } + else{ + getBoard().get(point).setB(new AbstractBox()); + getBoard().get(point).getB().setLock(true); + } + } + } + } } public boolean boardPositionIsValid(int row, int deltaRow, int column, int deltaColumn){ @@ -80,12 +121,39 @@ public class Grid { return boardPositionIsValid(point.getA(), point.getB()); } - public boolean boardHorizontalIsValid(int column, int deltaColumn){ - return column + deltaColumn >= 0 && column + deltaColumn < this.column; + public int getIllusionNumberWallNeighbour(Point point){ + int countWall = 0; + for (int deltaRow = -1; deltaRow <= 1; deltaRow++){ + for (int deltaColomn = -1; deltaColomn <= 1; deltaColomn++) { + Point neighbour = new Point(point.getA() + deltaRow, point.getB() + deltaColomn); + if (boardPositionIsValid(neighbour)) { + Box box = getBoard().get(neighbour).getB(); + if (box != null) { + if (box instanceof Wall || box.isLock()) { + countWall++; + } + } + } + } + } + return countWall; } - public boolean boardVerticalIsValid(int row, int deltaRow){ - return row + deltaRow >= 0 && row + deltaRow < this.row; + public int getNumberNeutralBox(){ + int countBox = 0; + for (int i = 1; i < row - 1; i++) { + for (int j = 1; j < column - 1; j++) { + Box box = getBoard().get(new Point(i,j)).getB(); + if(isNeutralBox(box)){ + countBox++; + } + } + } + return countBox; + } + + public boolean isNeutralBox(Box box){ + return !(box instanceof Wall) && !(box instanceof EnergyBall); } public HashMap> getBoard() { From c6f4dbffe3df206108556936d6a17a3d72132a83 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Thu, 2 Dec 2021 20:00:53 +0100 Subject: [PATCH 3/7] Add random choose method in the Cardinal enum --- .../src/main/java/fr/lnl/game/server/utils/Cardinal.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/fr/lnl/game/server/utils/Cardinal.java b/server/src/main/java/fr/lnl/game/server/utils/Cardinal.java index b7dab95..3b8ff91 100644 --- a/server/src/main/java/fr/lnl/game/server/utils/Cardinal.java +++ b/server/src/main/java/fr/lnl/game/server/utils/Cardinal.java @@ -8,5 +8,11 @@ public enum Cardinal { NORTH_EAST, NORTH_WEST, SOUTH_EAST, - SOUTH_WEST + SOUTH_WEST; + + public static Cardinal getRandom() { + return values()[(int) (Math.random() * values().length)]; + } } + + From 5201e7377280dc6b1e80d29c1c20df011c2e97cf Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Thu, 2 Dec 2021 20:01:49 +0100 Subject: [PATCH 4/7] Add AbstractBox and lock case notion (to see if it is viable to keep it) --- .../java/fr/lnl/game/client/view/GUI.java | 4 +--- .../game/server/games/grid/AbstractBox.java | 21 +++++++++++++++++++ .../fr/lnl/game/server/games/grid/Box.java | 3 +++ .../game/server/games/grid/EnergyBall.java | 2 +- .../lnl/game/server/games/grid/Explosive.java | 2 +- .../fr/lnl/game/server/games/grid/Wall.java | 2 +- 6 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 server/src/main/java/fr/lnl/game/server/games/grid/AbstractBox.java diff --git a/client/src/main/java/fr/lnl/game/client/view/GUI.java b/client/src/main/java/fr/lnl/game/client/view/GUI.java index 175918f..09b4b51 100644 --- a/client/src/main/java/fr/lnl/game/client/view/GUI.java +++ b/client/src/main/java/fr/lnl/game/client/view/GUI.java @@ -101,9 +101,7 @@ public class GUI { List players = Arrays.asList(new RandomComputerPlayer(1, null, ClassPlayer.DEFAULT), new RandomComputerPlayer(2, null, ClassPlayer.DEFAULT)); Grid grid = new Grid(16, 16, players); - grid.placePlayersBRUT(); - grid.placeEnergyBallBRUT(); - grid.placeInternWallBRUT(); + //grid.placePlayersBRUT(); return grid; } diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/AbstractBox.java b/server/src/main/java/fr/lnl/game/server/games/grid/AbstractBox.java new file mode 100644 index 0000000..ebf58ee --- /dev/null +++ b/server/src/main/java/fr/lnl/game/server/games/grid/AbstractBox.java @@ -0,0 +1,21 @@ +package fr.lnl.game.server.games.grid; + +public class AbstractBox implements Box{ + + boolean lock; + + public AbstractBox(){ + lock = false; + } + + @Override + public void setLock(boolean lock) { + this.lock = lock; + } + + @Override + public boolean isLock() { + return lock; + } +} + diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/Box.java b/server/src/main/java/fr/lnl/game/server/games/grid/Box.java index 593512e..1a7186f 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/Box.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/Box.java @@ -1,4 +1,7 @@ package fr.lnl.game.server.games.grid; public interface Box { + + boolean isLock(); + void setLock(boolean lock); } diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/EnergyBall.java b/server/src/main/java/fr/lnl/game/server/games/grid/EnergyBall.java index 1fd9193..88e9ce3 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/EnergyBall.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/EnergyBall.java @@ -3,7 +3,7 @@ package fr.lnl.game.server.games.grid; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Point; -public class EnergyBall implements Box, InteractiveBox { +public class EnergyBall extends AbstractBox implements InteractiveBox{ @Override public boolean equals(Object o) { diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/Explosive.java b/server/src/main/java/fr/lnl/game/server/games/grid/Explosive.java index 8861a4b..e4c6321 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/Explosive.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/Explosive.java @@ -3,7 +3,7 @@ package fr.lnl.game.server.games.grid; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Point; -public abstract class Explosive implements Box, InteractiveBox { +public abstract class Explosive extends AbstractBox implements InteractiveBox { @Override public void interact(Grid grid, Player player, Point position) { diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/Wall.java b/server/src/main/java/fr/lnl/game/server/games/grid/Wall.java index 06d8853..dd52cec 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/Wall.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/Wall.java @@ -4,7 +4,7 @@ import fr.lnl.game.server.utils.Cardinal; import java.util.Objects; -public class Wall implements Box { +public class Wall extends AbstractBox { private final Cardinal cardinal; private final int x; From a354d4fb21ad9f78a3a5e2d1c7e65cfdf7ef1c81 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Thu, 2 Dec 2021 20:03:46 +0100 Subject: [PATCH 5/7] Mock update and import optimization --- .../src/main/java/fr/lnl/game/client/App.java | 8 +++- .../java/fr/lnl/game/client/view/Cell.java | 1 - .../game/client/view/ClientEventHandler.java | 2 +- .../java/fr/lnl/game/client/view/GUI.java | 3 -- .../java/fr/lnl/game/client/view/Window.java | 3 -- .../java/fr/lnl/game/server/games/Game.java | 1 - .../game/server/games/action/DropMine.java | 3 -- .../fr/lnl/game/server/games/grid/Grid.java | 1 - .../game/server/games/player/HumanPlayer.java | 1 - .../game/server/listener/GameFinishEvent.java | 2 - .../java/fr/lnl/game/server/GridTest.java | 38 ++++++++++++++++--- .../test/java/fr/lnl/game/server/Mock.java | 5 +-- 12 files changed, 41 insertions(+), 27 deletions(-) diff --git a/client/src/main/java/fr/lnl/game/client/App.java b/client/src/main/java/fr/lnl/game/client/App.java index 7b41864..d798d90 100644 --- a/client/src/main/java/fr/lnl/game/client/App.java +++ b/client/src/main/java/fr/lnl/game/client/App.java @@ -1,10 +1,14 @@ package fr.lnl.game.client; -import fr.lnl.game.client.view.*; -import fr.lnl.game.server.listener.GameFinishEvent; + import fr.lnl.game.client.listener.UpdateViewEvent; +import fr.lnl.game.client.view.AbstractView; +import fr.lnl.game.client.view.Terminal; +import fr.lnl.game.client.view.ViewManager; +import fr.lnl.game.client.view.Window; import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.Grid; import fr.lnl.game.server.games.player.*; +import fr.lnl.game.server.listener.GameFinishEvent; import fr.lnl.game.server.utils.CrashException; import fr.lnl.game.server.utils.Point; import javafx.application.Application; diff --git a/client/src/main/java/fr/lnl/game/client/view/Cell.java b/client/src/main/java/fr/lnl/game/client/view/Cell.java index 7028f9d..945b58d 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Cell.java +++ b/client/src/main/java/fr/lnl/game/client/view/Cell.java @@ -3,7 +3,6 @@ package fr.lnl.game.client.view; import fr.lnl.game.server.games.grid.Bomb; import fr.lnl.game.server.games.grid.EnergyBall; import fr.lnl.game.server.games.grid.Mine; -import fr.lnl.game.server.games.grid.Wall; import fr.lnl.game.server.games.player.Player; import javafx.scene.image.Image; import javafx.scene.image.ImageView; diff --git a/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java b/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java index f587948..47d8d9a 100644 --- a/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java +++ b/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java @@ -1,7 +1,7 @@ package fr.lnl.game.client.view; -import fr.lnl.game.server.listener.ModelListener; import fr.lnl.game.client.listener.ButtonListener; +import fr.lnl.game.server.listener.ModelListener; import javafx.event.ActionEvent; import javafx.event.EventHandler; diff --git a/client/src/main/java/fr/lnl/game/client/view/GUI.java b/client/src/main/java/fr/lnl/game/client/view/GUI.java index 09b4b51..46ce600 100644 --- a/client/src/main/java/fr/lnl/game/client/view/GUI.java +++ b/client/src/main/java/fr/lnl/game/client/view/GUI.java @@ -1,9 +1,7 @@ package fr.lnl.game.client.view; -import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.*; -import fr.lnl.game.server.games.player.AbstractPlayer; import fr.lnl.game.server.games.player.ClassPlayer; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.games.player.RandomComputerPlayer; @@ -14,7 +12,6 @@ import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; -import javafx.scene.shape.Rectangle; import javafx.stage.Modality; import javafx.stage.Stage; diff --git a/client/src/main/java/fr/lnl/game/client/view/Window.java b/client/src/main/java/fr/lnl/game/client/view/Window.java index 65bb4e0..58a6128 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Window.java +++ b/client/src/main/java/fr/lnl/game/client/view/Window.java @@ -3,14 +3,11 @@ package fr.lnl.game.client.view; import fr.lnl.game.client.listener.ButtonListener; import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.player.Player; -import javafx.concurrent.ScheduledService; -import javafx.concurrent.Task; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.stage.Stage; -import javafx.util.Duration; public class Window extends AbstractView { diff --git a/server/src/main/java/fr/lnl/game/server/games/Game.java b/server/src/main/java/fr/lnl/game/server/games/Game.java index 97cd161..7c16988 100644 --- a/server/src/main/java/fr/lnl/game/server/games/Game.java +++ b/server/src/main/java/fr/lnl/game/server/games/Game.java @@ -8,7 +8,6 @@ import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.listener.AwakeGame; import fr.lnl.game.server.listener.ModelListener; import fr.lnl.game.server.utils.CrashException; -import fr.lnl.game.server.utils.Point; import java.util.ArrayList; import java.util.Arrays; diff --git a/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java b/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java index 5ec88f5..6aecc67 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java @@ -3,9 +3,6 @@ package fr.lnl.game.server.games.action; import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.Mine; import fr.lnl.game.server.games.player.Player; -import fr.lnl.game.server.utils.Point; - -import java.util.List; public class DropMine extends DropObject { diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java b/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java index 175f6c3..2db43c1 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java @@ -1,6 +1,5 @@ package fr.lnl.game.server.games.grid; -import fr.lnl.game.server.games.player.AbstractPlayer; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Cardinal; import fr.lnl.game.server.utils.Pair; diff --git a/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java index 2be409c..676f572 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java @@ -1,6 +1,5 @@ package fr.lnl.game.server.games.player; -import fr.lnl.game.server.games.action.Action; import fr.lnl.game.server.utils.Point; public class HumanPlayer extends AbstractPlayer { diff --git a/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java b/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java index f09595f..183b1ea 100644 --- a/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java +++ b/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java @@ -1,7 +1,5 @@ package fr.lnl.game.server.listener; -import fr.lnl.game.server.listener.AbstractModelListening; - public class GameFinishEvent extends AbstractModelListening { private final Object lock = new Object(); diff --git a/server/src/test/java/fr/lnl/game/server/GridTest.java b/server/src/test/java/fr/lnl/game/server/GridTest.java index 244f38b..bc2bbab 100644 --- a/server/src/test/java/fr/lnl/game/server/GridTest.java +++ b/server/src/test/java/fr/lnl/game/server/GridTest.java @@ -1,20 +1,17 @@ package fr.lnl.game.server; import fr.lnl.game.server.games.Game; -import fr.lnl.game.server.games.action.*; +import fr.lnl.game.server.games.grid.Box; import fr.lnl.game.server.games.grid.EnergyBall; import fr.lnl.game.server.games.grid.Grid; import fr.lnl.game.server.games.grid.Wall; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Cardinal; +import fr.lnl.game.server.utils.Pair; import fr.lnl.game.server.utils.Point; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Random; - import static org.junit.jupiter.api.Assertions.assertEquals; public class GridTest { @@ -44,4 +41,35 @@ public class GridTest { assertEquals(new EnergyBall(), grid.getBoard().get(new Point(8, 10)).getB()); } + @Test + public void testLock() { + System.out.println("=================== GRID COMPLETE ===================="); + System.out.println(grid.toString()); + System.out.println("=================== GRID AVEC LOCK ==================="); + StringBuilder str = new StringBuilder(); + for (int i = 0; i < grid.getRow(); i++) { + str.append("\n"); + for (int j = 0; j < grid.getColumn(); j++) { + Pair value = grid.getBoard().get(new Point(i, j)); + if(value.getB() != null){ + if(value.getB().isLock()){ + str.append(" \033[0;35mL\033[0m"); + } + if(value.getB() instanceof Wall){ + str.append(" \033[0;32mW\033[0m"); + } + if(value.getB() instanceof EnergyBall){ + str.append(" \033[0;31mE\033[0m"); + } + } + else if(value.getA() != null){ + str.append(" \033[0;34mP\033[0m"); + } + else { + str.append(" \033[0;37m.\033[0m"); + } + } + } + System.out.println(str); + } } diff --git a/server/src/test/java/fr/lnl/game/server/Mock.java b/server/src/test/java/fr/lnl/game/server/Mock.java index 19e13bb..0279164 100644 --- a/server/src/test/java/fr/lnl/game/server/Mock.java +++ b/server/src/test/java/fr/lnl/game/server/Mock.java @@ -23,10 +23,7 @@ public class Mock { public Mock() { List players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); - this.grid = new Grid(16,16, players); - placePlayersBRUT(); - placeEnergyBallBRUT(); - placeInternWallBRUT(); + this.grid = new Grid(16,16, players, 0.80F,0.95F); game = new Game(grid, players, new MockViewUpdate(), new GameFinishEvent()); } From 7afd79b929ddbc81fd257c29a628f58e34a8721a Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Thu, 2 Dec 2021 20:11:23 +0100 Subject: [PATCH 6/7] Conflict resolution --- client/src/main/java/fr/lnl/game/client/App.java | 2 +- .../src/main/java/fr/lnl/game/client/view/GUI.java | 3 ++- .../main/java/fr/lnl/game/server/games/Game.java | 14 +------------- server/src/test/java/fr/lnl/game/server/Mock.java | 2 +- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/client/src/main/java/fr/lnl/game/client/App.java b/client/src/main/java/fr/lnl/game/client/App.java index 574a030..5409823 100644 --- a/client/src/main/java/fr/lnl/game/client/App.java +++ b/client/src/main/java/fr/lnl/game/client/App.java @@ -38,7 +38,7 @@ public class App extends Application { public static void startGame(ViewLambda lambda) throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { List players = parsePlayers(); - game = new Game(new Grid(12, 12, players), players, new GameFinishEvent()); + game = new Game(new Grid(12, 12, players, 0.80F,0.95F), players, new GameFinishEvent()); for (Player player : game.getPlayers()) { playerList.put(player, new ClientPlayer(player, lambda.createViewLambda(player))); } diff --git a/client/src/main/java/fr/lnl/game/client/view/GUI.java b/client/src/main/java/fr/lnl/game/client/view/GUI.java index 2a33bb6..917913c 100644 --- a/client/src/main/java/fr/lnl/game/client/view/GUI.java +++ b/client/src/main/java/fr/lnl/game/client/view/GUI.java @@ -12,6 +12,7 @@ import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; +import javafx.scene.shape.Rectangle; import javafx.stage.Modality; import javafx.stage.Stage; @@ -105,7 +106,7 @@ public class GUI { private Grid getGrid() { List players = Arrays.asList(new RandomComputerPlayer(1, null, ClassPlayer.DEFAULT), new RandomComputerPlayer(2, null, ClassPlayer.DEFAULT)); - Grid grid = new Grid(16, 16, players); + Grid grid = new Grid(16, 16, players, 0.80F, 0.95F); //grid.placePlayersBRUT(); return grid; } diff --git a/server/src/main/java/fr/lnl/game/server/games/Game.java b/server/src/main/java/fr/lnl/game/server/games/Game.java index 0966e38..58b918f 100644 --- a/server/src/main/java/fr/lnl/game/server/games/Game.java +++ b/server/src/main/java/fr/lnl/game/server/games/Game.java @@ -23,27 +23,15 @@ public class Game { private Action selectedAction = null; public Game(Grid grid, List players, ModelListener gameFinishEvent) throws IllegalArgumentException { - if(players.size() < 2) + if(players.size() < 2 || players.size() > grid.getNumberNeutralBox()) throw new IllegalArgumentException("The game need 2 or more player to start"); this.players = players; this.currentPlayer = players.get(0); this.grid = grid; this.gameFinishEvent = gameFinishEvent; - placePlayersBRUT(); currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer)); } - /** - * @deprecated utiliser pour le moment, nécessite une meilleure implémentation pour savoir ou placé les joueurs - */ - @Deprecated - public void placePlayersBRUT(){ - grid.getBoard().get(new Point(7,7)).setA(grid.getPlayers().get(0)); - grid.getPlayers().get(0).setPosition(new Point(7, 7)); - grid.getBoard().get(new Point(7,8)).setA(grid.getPlayers().get(1)); - grid.getPlayers().get(1).setPosition(new Point(7, 8)); - } - public void play() { if (currentPlayer instanceof ComputerPlayer player) { selectedAction = player.choseAction(); diff --git a/server/src/test/java/fr/lnl/game/server/Mock.java b/server/src/test/java/fr/lnl/game/server/Mock.java index 89aa984..a7f5526 100644 --- a/server/src/test/java/fr/lnl/game/server/Mock.java +++ b/server/src/test/java/fr/lnl/game/server/Mock.java @@ -22,7 +22,7 @@ public class Mock { public Mock() { List players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); - this.grid = new Grid(16,16, players); + this.grid = new Grid(16,16, players,0.80F, 0.95F); placePlayersBRUT(); placeEnergyBallBRUT(); placeInternWallBRUT(); From 3066ecf2116e1fcf6d02454bded53abadf509f57 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Fri, 3 Dec 2021 15:22:00 +0100 Subject: [PATCH 7/7] Fix critical bug --- server/src/main/java/fr/lnl/game/server/games/Game.java | 6 +++++- .../fr/lnl/game/server/games/player/AbstractPlayer.java | 3 +++ server/src/test/java/fr/lnl/game/server/Mock.java | 3 --- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/fr/lnl/game/server/games/Game.java b/server/src/main/java/fr/lnl/game/server/games/Game.java index 58b918f..1406c89 100644 --- a/server/src/main/java/fr/lnl/game/server/games/Game.java +++ b/server/src/main/java/fr/lnl/game/server/games/Game.java @@ -23,12 +23,16 @@ public class Game { private Action selectedAction = null; public Game(Grid grid, List players, ModelListener gameFinishEvent) throws IllegalArgumentException { - if(players.size() < 2 || players.size() > grid.getNumberNeutralBox()) + if(players.size() < 2) throw new IllegalArgumentException("The game need 2 or more player to start"); + if(players.size() > grid.getNumberNeutralBox()){ + throw new IllegalArgumentException("There are too many players for the number of box available"); + } this.players = players; this.currentPlayer = players.get(0); this.grid = grid; this.gameFinishEvent = gameFinishEvent; + this.grid.initPlacePlayers(); currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer)); } diff --git a/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java index 7f85b36..41dcfdd 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java @@ -87,6 +87,9 @@ public abstract class AbstractPlayer implements Player { @Override public void setPosition(Point position){ + if(position == null){ + throw new IllegalArgumentException("Position is null"); + } this.position = position; } diff --git a/server/src/test/java/fr/lnl/game/server/Mock.java b/server/src/test/java/fr/lnl/game/server/Mock.java index a7f5526..98644cb 100644 --- a/server/src/test/java/fr/lnl/game/server/Mock.java +++ b/server/src/test/java/fr/lnl/game/server/Mock.java @@ -23,9 +23,6 @@ public class Mock { List players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); this.grid = new Grid(16,16, players,0.80F, 0.95F); - placePlayersBRUT(); - placeEnergyBallBRUT(); - placeInternWallBRUT(); game = new Game(grid, players, new GameFinishEvent()); }