Skip to content

Commit

Permalink
[release v1.1]merged subgroup3 && sloved movement
Browse files Browse the repository at this point in the history
  • Loading branch information
JiananAlvin committed Apr 23, 2022
1 parent 443611a commit e469e43
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 234 deletions.
23 changes: 17 additions & 6 deletions src/main/java/content/MapName.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package content;

public class MapName {
public static final String STARTER = "STARTER";
public static final String BEGINNER = "BEGINNER";
public static final String INTERMEDIATE = "INTERMEDIATE";
public static final String ADVANCED = "ADVANCED";
}
public enum MapName {

STARTER("STARTER"),
BEGINNER("BEGINNER"),
INTERMEDIATE("INTERMEDIATE"),
ADVANCED("ADVANCED");

private final String mapName;

private MapName(String mapName) {
this.mapName = mapName;
}

public String getMapName() {
return mapName;
}
}
25 changes: 18 additions & 7 deletions src/main/java/content/RobotName.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package content;

public class RobotName {
public static final String SQUASH_BOT = "SQUASH_BOT";
public static final String ZOOM_BOT = "ZOOM_BOT";
public static final String HAMMER_BOT = "HAMMER_BOT";
public static final String SPIN_BOT = "SPIN_BOT";
public static final String HULK_X90 = "HULK_X90";
public static final String TRUNDLE_BOT = "TRUNDLE_BOT";
public enum RobotName {

SQUASH_BOT("SQUASH_BOT"),
ZOOM_BOT("ZOOM_BOT"),
HAMMER_BOT("HAMMER_BOT"),
SPIN_BOT("SPIN_BOT"),
HULK_X90("HULK_X90"),
TRUNDLE_BOT("TRUNDLE_BOT");

private String name;

private RobotName(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
48 changes: 22 additions & 26 deletions src/main/java/gui/view/map/TileImageEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,38 @@

public enum TileImageEnum {

BLANK(1, "src/main/resources/images/tiles/blank.png"),
CHARGER(2, "src/main/resources/images/tiles/charger.png"),
CHECKPOINT1(3, "src/main/resources/images/tiles/check_point1.png"),
REBOOTPOINT(4, "src/main/resources/images/tiles/reboot_point.png"),
SOUTHTWO(5, "src/main/resources/images/tiles/south_two.png"),
WESTTWO(6, "src/main/resources/images/tiles/west_two.png"),
ANTENNA(7, "src/main/resources/images/tiles/priority_antenna.png"),
EASTONE(8, "src/main/resources/images/tiles/east_one.png"),
EASTTWO(9, "src/main/resources/images/tiles/east_two.png"),
STARTPOINT(10, "src/main/resources/images/tiles/start_point.png"),
NORTHTWO(11, "src/main/resources/images/tiles/north_two.png"),
WALLSOUTH(12, "src/main/resources/images/tiles/wall_south.png"),
WALLSOUTHLASER(13, "src/main/resources/images/tiles/wall_south_laser.png"),
WALLWEST(14, "src/main/resources/images/tiles/wall_west.png"),
WALLWESTLASER(15, "src/main/resources/images/tiles/wall_west_laser.png"),
WALLEAST(16, "src/main/resources/images/tiles/wall_east.png"),
WALLEASTLASER(17, "src/main/resources/images/tiles/wall_east_laser.png"),
WALLNORTH(18, "src/main/resources/images/tiles/wall_north.png"),
WALLNORTHLASER(19, "src/main/resources/images/tiles/wall_north_laser.png"),
NORTHONE(20, "src/main/resources/images/tiles/north_one.png"),
ARROW(21,"src/main/resources/images/robots/arrow.png");
BLANK("src/main/resources/images/tiles/blank.png"),
CHARGER("src/main/resources/images/tiles/charger.png"),
CHECKPOINT1("src/main/resources/images/tiles/check_point1.png"),
REBOOTPOINT("src/main/resources/images/tiles/reboot_point.png"),
SOUTHTWO("src/main/resources/images/tiles/south_two.png"),
WESTTWO("src/main/resources/images/tiles/west_two.png"),
ANTENNA("src/main/resources/images/tiles/priority_antenna.png"),
EASTONE("src/main/resources/images/tiles/east_one.png"),
EASTTWO("src/main/resources/images/tiles/east_two.png"),
STARTPOINT("src/main/resources/images/tiles/start_point.png"),
NORTHTWO("src/main/resources/images/tiles/north_two.png"),
WALLSOUTH("src/main/resources/images/tiles/wall_south.png"),
WALLSOUTHLASER("src/main/resources/images/tiles/wall_south_laser.png"),
WALLWEST("src/main/resources/images/tiles/wall_west.png"),
WALLWESTLASER("src/main/resources/images/tiles/wall_west_laser.png"),
WALLEAST("src/main/resources/images/tiles/wall_east.png"),
WALLEASTLASER("src/main/resources/images/tiles/wall_east_laser.png"),
WALLNORTH("src/main/resources/images/tiles/wall_north.png"),
WALLNORTHLASER("src/main/resources/images/tiles/wall_north_laser.png"),
NORTHONE("src/main/resources/images/tiles/north_one.png"),
ARROW("src/main/resources/images/robots/arrow.png");

private final BufferedImage image;
private final int identity;


private TileImageEnum(int identity, String fileName) {
// first assign to tempImage to meet teh final modifier of image
private TileImageEnum(String fileName) {
BufferedImage tempImage;
try {
tempImage = ImageIO.read(new File(fileName));
} catch (Exception e) {
tempImage = null;
}
this.image = tempImage;
this.identity = identity;
}

public BufferedImage getImage() {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/gui/view/widgets/game/BoardPanel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gui.view.widgets.game;

import java.awt.*;
import java.util.ArrayList;

import javax.swing.*;

Expand Down Expand Up @@ -46,7 +45,7 @@ private void loadBoard() {
}
for (Player player : game.getParticipants()) {
Robot r = player.getRobot();
board[r.getPosition().getXcoord()][r.getPosition().getYcoord()].setRobot(r.getOrientation(), player.getUserColor());
board[r.getPosition().getRow()][r.getPosition().getCol()].setRobot(r.getOrientation(), player.getUserColor());
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/gui/view/widgets/game/GamePanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gui.view.widgets.game;

import content.Application;
import content.MapName;
import content.RobotName;
import lombok.SneakyThrows;
import model.Game;
import model.Room;
Expand All @@ -18,7 +20,6 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;

/*
Expand Down Expand Up @@ -109,9 +110,9 @@ public void actionPerformed(ActionEvent e) {
}
Player currentPlayer = game.getParticipants().get(currenPlayerIndex);
Card currentRegisterCard = currentPlayer.getRegisterArea().getCard(registerIndex);
boardPanel.getBoard()[currentPlayer.getRobot().getPosition().getXcoord()][currentPlayer.getRobot().getPosition().getYcoord()].unsetRobot();
boardPanel.getBoard()[currentPlayer.getRobot().getPosition().getRow()][currentPlayer.getRobot().getPosition().getCol()].unsetRobot();
currentRegisterCard.action(currentPlayer.getRobot());
boardPanel.getBoard()[currentPlayer.getRobot().getPosition().getXcoord()][currentPlayer.getRobot().getPosition().getYcoord()].setRobot(currentPlayer.getRobot().getOrientation(), currentPlayer.getUserColor());
boardPanel.getBoard()[currentPlayer.getRobot().getPosition().getRow()][currentPlayer.getRobot().getPosition().getCol()].setRobot(currentPlayer.getRobot().getOrientation(), currentPlayer.getUserColor());

boardPanel.repaint();
// boardPanel.revalidate();
Expand Down Expand Up @@ -196,7 +197,7 @@ private Card getCardObject(String className) {

@SneakyThrows
public static void main(String[] args) {
Player user = new Player("SpongeBob", new Robot("SQUASH_BOT"));
Player user = new Player("SpongeBob", new Robot(RobotName.SQUASH_BOT));
UserController userController = new UserController();
userController.deleteUser("SpongeBob");
userController.createUser("SpongeBob");
Expand All @@ -208,7 +209,7 @@ public static void main(String[] args) {
System.out.println(roomController.createRoom(user.getName(), "STARTER"));
int roomNumber = roomController.createRoom(user.getName(), "STARTER").getInt("room_number");
userController.joinRoom("PatrickStar", roomNumber);
GameMap gameMap = new GameMap("STARTER");
GameMap gameMap = new GameMap(MapName.STARTER);
Room room = new Room(roomNumber);
Game game = new Game();
game.init(user, room, gameMap, roomController.roomInfo(roomNumber));
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/gui/view/widgets/game/MatPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gui.view.widgets.game;

import content.Application;
import content.MapName;
import content.RobotName;
import lombok.Data;
import model.Game;
import model.Room;
Expand Down Expand Up @@ -122,7 +124,7 @@ public Class getColumnClass(int column) {


public static void main(String[] args) throws IOException {
Player user = new Player("SpongeBob", new Robot("SQUASH_BOT"));
Player user = new Player("SpongeBob", new Robot(RobotName.valueOf("SQUASH_BOT")));
UserController userController = new UserController();
userController.createUser("SpongeBob");
userController.createUser("PatrickStar");
Expand All @@ -133,7 +135,7 @@ public static void main(String[] args) throws IOException {
System.out.println(roomController.createRoom(user.getName(), "STARTER"));
int roomNumber = roomController.createRoom(user.getName(), "STARTER").getInt("room_number");
userController.joinRoom("PatrickStar", roomNumber);
GameMap gameMap = new GameMap("STARTER");
GameMap gameMap = new GameMap(MapName.valueOf("STARTER"));
Room room = new Room(roomNumber);
Game game = new Game();
game.init(user, room, gameMap, roomController.roomInfo(roomNumber));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gui/view/widgets/login/LoginPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LoginPanel extends JPanel {

public LoginPanel(JFrame frame) {
this.userName = new JTextField();
JLabel lbluserName = new JLabel("Player name");
JLabel lblUserName = new JLabel("Player name");
JLabel lblRobot = new JLabel("Robot");
this.lblChosenRobot = new JLabel();
Icon iconSquashBot = new ImageIcon(new ImageIcon(PATH_TO_ROBOT_ICONS + "SQUASH_BOT.jpg").getImage().getScaledInstance(105, 142, Image.SCALE_DEFAULT));
Expand All @@ -43,7 +43,7 @@ public LoginPanel(JFrame frame) {
// Displaying the login interface
this.setLayout(null);
RobotListener robotListener = new RobotListener();
lbluserName.setBounds(100, 8, 70, 20);
lblUserName.setBounds(100, 8, 70, 20);
this.userName.setBounds(100, 36, 193, 28);
lblRobot.setBounds(100, 75, 70, 20);
this.lblChosenRobot.setBounds(200, 75, 100, 20);
Expand All @@ -62,7 +62,7 @@ public LoginPanel(JFrame frame) {
btOk.setBounds(100, 270, 80, 30);
btCancel.setBounds(300, 270, 80, 30);
this.add(this.userName);
this.add(lbluserName);
this.add(lblUserName);
this.add(lblRobot);
this.add(this.lblChosenRobot);
this.add(this.btSquashBot);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gui/view/widgets/room/RoomPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public RoomPanel(String userName, JFrame frame) {
btJoinRoom.addActionListener(e -> {
/*
fetching the room number when the "Join room" button is pressed
inserting the player info into the room through API
inserting the qplayer info into the room through API
*/
UserController userController = new UserController();
String roomNumberStr = this.roomNumber.getText();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/gui/view/widgets/waiting/WaitingPanel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gui.view.widgets.waiting;

import content.MapName;
import content.RobotName;
import gui.view.widgets.game.GamePanel;
import gui.view.widgets.room.RoomPanel;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -199,7 +201,7 @@ private void startGamePanel(int roomNumber, JSONObject roomInfoResponse, String
String mapName = roomInfoResponse.getString(RoomController.RESPONSE_MAP_NAME);
// int roomNumber = roomInfoResponse.getInt(RoomController.RESPONSE_ROOM_NUMBER);
String robotName = (String) new RobotController().getRobotInfo(userName).get(RobotController.RESPONSE_ROBOT_NAME);
game.init(new Player(userName, new Robot(robotName)), new Room(roomNumber), new GameMap(mapName), roomInfoResponse);
game.init(new Player(userName, new Robot(RobotName.valueOf(robotName))), new Room(roomNumber), new GameMap(MapName.valueOf(mapName)), roomInfoResponse);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/model/Game.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package model;

import content.RobotName;
import gui.view.widgets.game.GamePanel;
import lombok.Data;
import lombok.SneakyThrows;
import model.game.board.map.Collision;
import model.game.board.map.GameMap;
import model.game.board.map.Position;
Expand Down Expand Up @@ -91,7 +91,7 @@ public ArrayList<Player> orderOfPlayers() {
TreeMap<Integer, TreeMap<Integer, Player>> robotDistanceTree = new TreeMap<>();
for (Player p : this.participants) {
Integer dist = p.getRobot().distanceToAntenna();
Integer ycoord = p.getRobot().getPosition().getYcoord();
Integer ycoord = p.getRobot().getPosition().getCol();
if (robotDistanceTree.containsKey(dist)) {
robotDistanceTree.get(dist).put(ycoord, p);
} else {
Expand Down Expand Up @@ -131,7 +131,7 @@ public void initParticipants(JSONObject roomInfoReponse) {
List<Object> userList = users.toList();
for (Object userName : userList) {
JSONObject robotInfo = new RobotController().getRobotInfo(userName.toString());
Robot robot = new Robot((String) robotInfo.get(RobotController.RESPONSE_ROBOT_NAME));
Robot robot = new Robot(RobotName.valueOf((String) robotInfo.get(RobotController.RESPONSE_ROBOT_NAME)));
try {
// if JSONObject["x"] not found, it means there is no initial position
int x = (int) robotInfo.get(RobotController.RESPONSE_ROBOT_XCOORD);
Expand All @@ -153,7 +153,7 @@ public void generateRandomPositionsForAllParticipants() {
for (Player player : this.participants) {
StartPoint assignedStartPoint = startPoints.remove(new Random().nextInt(startPoints.size()));
player.getRobot().setPosition(assignedStartPoint.getPosition());
new RobotController().updatePosition(player.getName(), player.getRobot().getPosition().getXcoord(), player.getRobot().getPosition().getYcoord());
new RobotController().updatePosition(player.getName(), player.getRobot().getPosition().getRow(), player.getRobot().getPosition().getCol());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/model/game/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public boolean takeToken(CheckPoint checkPoint) {
* @return an arraylist of 9 cards that is 9 cards in the player's hand.
*/
public void drawCards() {
ArrayList<Card> cardsInHand = new ArrayList<>();
this.cardsInHand = new ArrayList<>();
if (this.programmingDeck.getCards().size() < ProgrammingDeck.NUMBER_OF_CARDS_DRAWN_IN_EACH_ROUND) {
this.cardsInHand = new ArrayList<>(this.programmingDeck.getCards());
//this.discardPile.getDiscards().addAll(cardsInHand);
this.programmingDeck.getCards().removeAll(this.programmingDeck.getCards());
this.replenishProgrammingDeck();
ArrayList<Card> complements = new ArrayList<>(this.programmingDeck.getCards().subList(0, ProgrammingDeck.NUMBER_OF_CARDS_DRAWN_IN_EACH_ROUND - cardsInHand.size()));
ArrayList<Card> complements = new ArrayList<>(this.programmingDeck.getCards().subList(0, ProgrammingDeck.NUMBER_OF_CARDS_DRAWN_IN_EACH_ROUND - this.cardsInHand.size()));
this.programmingDeck.getCards().subList(0, ProgrammingDeck.NUMBER_OF_CARDS_DRAWN_IN_EACH_ROUND - this.cardsInHand.size()).clear();
this.cardsInHand.addAll(complements);
//this.discardPile.getDiscards().addAll(cardsInHand);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/model/game/board/map/GameMap.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package model.game.board.map;

import io.cucumber.java.bs.A;
import content.MapName;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import model.game.board.map.element.CheckPoint;
Expand Down Expand Up @@ -29,8 +29,8 @@ public class GameMap {
*
* @param mapName the name of this map. Such as 'STARTER', 'BEGINNER' represent the map stored in 'STARTER.txt' and 'BEGINNER.txt'.
*/
public GameMap(String mapName) throws IOException {
this.mapName = mapName;
public GameMap(MapName mapName) throws IOException {
this.mapName = mapName.getMapName();
this.content = MapReader.txtToTileMatrix(mapName);
this.startPoints = new ArrayList<>();
this.rebootPoints = new ArrayList<>();
Expand Down Expand Up @@ -63,6 +63,6 @@ public RebootPoint getARandomRebootPoint() {
}

public Tile getTileWithPosition(Position position) {
return content[position.getXcoord()][position.getYcoord()];
return content[position.getRow()][position.getCol()];
}
}
Loading

0 comments on commit e469e43

Please sign in to comment.