Refactored Point.java

This commit is contained in:
Quentin Legot 2021-10-18 08:42:26 +02:00
parent c9380a229f
commit 559c590b52
4 changed files with 43 additions and 47 deletions

View File

@ -1,10 +1,7 @@
package fr.lnl.game.server.games;
import fr.lnl.game.server.games.grid.Grid;
import fr.lnl.game.server.games.player.ComputerPlayer;
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.games.weapon.Firearm;
import fr.lnl.game.server.utils.Point;
public class Game {
@ -12,12 +9,13 @@ public class Game {
Player player_One;
Player player_Two;
Player current_player;
Player[] players = {player_One,player_Two};
Player[] players;
public Game(Grid grid, Player player_One, Player player_Two){
this.player_One = player_One;
this.player_Two = player_Two;
this.current_player = player_One;
players = new Player[]{player_One, player_Two};
}

View File

@ -8,7 +8,7 @@ import java.util.HashMap;
public class Grid {
private HashMap<Point<Integer, Integer>, Triplet<Box, Box, Box>> board;
private HashMap<Point, Triplet<Box, Box, Box>> board;
private int x;
private int y;
@ -41,7 +41,7 @@ public class Grid {
} else {
box = null;
}
board.put(new Point<Integer,Integer>(i,j),new Triplet<Box, Box, Box>(box,null,null));
board.put(new Point(i,j), new Triplet<>(box, null, null));
}
}
}
@ -51,7 +51,7 @@ public class Grid {
for (int i = 0; i < x; i++) {
System.out.print("\n");
for (int j = 0; j < y; j++) {
Triplet<Box, Box, Box> value = board.get(new Point<Integer, Integer>(i, j));
Triplet<Box, Box, Box> value = board.get(new Point(i, j));
if (value.getA() instanceof Wall) {
if (((Wall) value.getA()).getCardinal() == Cardinal.NORTH) {
System.out.print(" \033[0;34m—\033[0m");

View File

@ -0,0 +1,35 @@
package fr.lnl.game.server.utils;
import java.util.Objects;
public class Pair<X,Y> {
private X x;
private Y y;
public Pair(X x, Y y){
this.x = x;
this.y = y;
}
public X getX() {
return this.x;
}
public Y getY() {
return y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair<?, ?> point = (Pair<?, ?>) o;
return Objects.equals(x, point.x) && Objects.equals(y, point.y);
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}

View File

@ -1,46 +1,9 @@
package fr.lnl.game.server.utils;
import java.util.Objects;
public class Point extends Pair<Integer, Integer> {
public class Point<X,Y> {
private X x;
private Y y;
public Point(X x, Y y){
this.x = x;
this.y = y;
public Point(int a, int b) {
super(a, b);
}
public Point(){
this(null, null);
}
public X getX() {
return this.x;
}
public Y getY() {
return y;
}
public void setX(X x) {
this.x = x;
}
public void setY(Y y) {
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point<?, ?> point = (Point<?, ?>) o;
return Objects.equals(x, point.x) && Objects.equals(y, point.y);
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}