Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #83 from CSC207-2022F-UofT/features/facelift
Browse files Browse the repository at this point in the history
Make the game a little bit prettier
  • Loading branch information
6167656e74323431 authored Dec 4, 2022
2 parents ef9e93c + 831bb73 commit be3dfee
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 45 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/mg105/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ public void start(Stage primaryStage) {
roomUpdater.addObserver(minimapInterpreter);

CharacterMover characterMover = new CharacterMover(state, roomUpdater);
ChestInteractor chestInteractor = new ChestInteractor(state, inventoryInteractor);
ChestInteractor chestInteractor = new ChestInteractor(state, inventoryInteractor, roomUpdater);
InputInterpreter inputInterpreter = new InputInterpreter(characterMover, sceneController, textChanger, chestInteractor,
opponentInteractor);
InputListener inputListener = new InputListener(inputInterpreter);
primaryStage.addEventFilter(KeyEvent.KEY_TYPED, inputListener);
sceneController.toggle(Toggler.ToggleableComponent.MAIN_MENU);
primaryStage.setTitle("Mountain Group 105");
primaryStage.setResizable(false);
primaryStage.show();
}
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/com/mg105/interface_adapters/RoomInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,49 @@ public TileType[][] getCurrentRoom() {
}

for (int i = 0; i < MapConstants.ROOM_SIZE; i++) {
canvas[0][i] = TileType.WALL;
canvas[i][0] = TileType.WALL;
canvas[MapConstants.ROOM_SIZE - 1][i] = TileType.WALL;
canvas[i][MapConstants.ROOM_SIZE - 1] = TileType.WALL;
canvas[i][0] = TileType.WALL;
}
for (int i = 1; i < MapConstants.ROOM_SIZE - 1; i++) {
canvas[MapConstants.ROOM_SIZE - 1][i] = TileType.WALL_WITH_FACE;
canvas[0][i] = TileType.WALL_WITH_FACE;
}
canvas[MapConstants.ROOM_SIZE - 1][0] = TileType.WALL_WITH_FACE;
canvas[MapConstants.ROOM_SIZE - 1][MapConstants.ROOM_SIZE - 1] = TileType.WALL_WITH_FACE;

RoomLayout room = getter.getCurrentRoomLayout();

for (Point doorway : room.getDoorways()) {
canvas[doorway.y][doorway.x] = TileType.EXIT;
if (doorway.x == 0 || doorway.x == MapConstants.ROOM_SIZE - 1) {
canvas[doorway.y - 1][doorway.x] = TileType.WALL_WITH_FACE;
}
}

for (Point chest : room.getChests()) {
for (Point chest : room.getClosedChests()) {
canvas[chest.y][chest.x] = TileType.CHEST;
}

for (Point chest : room.getOpenChests()) {
canvas[chest.y][chest.x] = TileType.CHEST_OPEN;
}

for (Point opponents : room.getOpponents()) {
canvas[opponents.y][opponents.x] = TileType.OPPONENT_SET;
}

canvas[room.getPlayer().y][room.getPlayer().x] = TileType.PLAYER;

return canvas;
}

/**
* Get the current player position in the room.
*
* @return the current player position in the room.
*/
public @NotNull Point getPlayer() {
return getter.getCurrentRoomLayout().getPlayer();
}

/**
* Retrieves the sprite String currently associated with the WalkingCharacter.
* @return a file name/location as a String for the desired character sprite.
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/mg105/interface_adapters/TileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ public enum TileType {
FLOOR,
/** Wall that cannot be walked on. Mainly used for the border */
WALL,
/** A wall where you can see the side */
WALL_WITH_FACE,
/** A doorway */
EXIT,
/** A treasure chest */
CHEST,
/** The player/walking character */
PLAYER,
/** A treasure chest that has been opened */
CHEST_OPEN,
/** A potential battle */
OPPONENT_SET,
}
16 changes: 11 additions & 5 deletions src/main/java/com/mg105/use_cases/ChestInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
import com.mg105.entities.Room;
import com.mg105.entities.TreasureChest;
import com.mg105.use_cases.inventory.InventoryInteractor;
import org.jetbrains.annotations.NotNull;

public class ChestInteractor {

private final GameState gameState;
private final InventoryInteractor interactor;
private final @NotNull GameState gameState;
private final @NotNull InventoryInteractor interactor;
private final @NotNull RoomUpdater updater;

/**
* Creates a ChestInteractor to interact with chests in a GameState.
*
* @param gameState the game state.
* @param gameState the game state.
* @param interactor the inventory interactor.
* @param updater the room updater that will be called when the room changes.
*/
public ChestInteractor(GameState gameState, InventoryInteractor interactor) {
public ChestInteractor(@NotNull GameState gameState,
@NotNull InventoryInteractor interactor,
@NotNull RoomUpdater updater) {
this.gameState = gameState;
this.interactor = interactor;
this.updater = updater;
}

/**
Expand Down Expand Up @@ -65,11 +71,11 @@ public TreasureChest verifyChest() {

public void getChestItem() {
TreasureChest chest = verifyChest();
gameState.getCurrentRoom().getChests().remove(chest);
if (chest != null) {
if (!chest.isOpened()) {
Item reward = chest.open();
interactor.addItem(reward.getName());
updater.updateRoom();
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/mg105/use_cases/RoomGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ public RoomGetter(@NotNull GameState state) {
* @return the current room.
*/
public @NotNull RoomLayout getCurrentRoomLayout() {
List<Point> chests = new ArrayList<>(state.getCurrentRoom().getChests().size());
List<Point> closedChests = new ArrayList<>();
List<Point> openChests = new ArrayList<>();
for (TreasureChest chest : state.getCurrentRoom().getChests()) {
chests.add(chest.getPosition());
if (chest.isOpened()) {
openChests.add(chest.getPosition());
} else {
closedChests.add(chest.getPosition());
}
}

List<Point> opponents = new ArrayList<>(state.getCurrentRoom().getOpponents().size());
Expand All @@ -49,7 +54,7 @@ public RoomGetter(@NotNull GameState state) {
doorways.add(doorway.getPosition());
}

return new RoomLayout(chests, opponents, doorways, state.getWalkingCharacter().getCharPosition());
return new RoomLayout(closedChests, openChests, opponents, doorways, state.getWalkingCharacter().getCharPosition());
}

/**
Expand Down
35 changes: 24 additions & 11 deletions src/main/java/com/mg105/use_cases/outputds/RoomLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,49 @@
* Note: There is an implicit, assumed, border around the edge.
*/
public class RoomLayout {
private final @NotNull List<Point> chests;
private final @NotNull List<Point> closedChests;
private final @NotNull List<Point> openChests;
private final @NotNull List<Point> opponents;
private final @NotNull List<Point> doorways;
private final @NotNull Point player;

/**
* Create a room given some number of chests, opponents, and doorways.
*
* @param chests the chests in this room.
* @param opponents the opponents in this room.
* @param doorways the doorways in this room leading to other rooms.
* @param player the player's position.
* @param closedChests the closed chests in the room.
* @param openChests the open chests in the room.
* @param opponents the opponents in this room.
* @param doorways the doorways in this room leading to other rooms.
* @param player the player's position.
*/
public RoomLayout(@NotNull List<Point> chests,
public RoomLayout(@NotNull List<Point> closedChests,
@NotNull List<Point> openChests,
@NotNull List<Point> opponents,
@NotNull List<Point> doorways,
@NotNull Point player) {
this.chests = chests;
this.closedChests = closedChests;
this.openChests = openChests;
this.opponents = opponents;
this.doorways = doorways;
this.player = player;
}

/**
* Get the treasure chests in this room.
* Get the closed treasure chests in this room.
*
* @return the treasure chest positions in this room.
* @return the closed treasure chest positions in this room.
*/
public @NotNull List<Point> getChests() {
return chests;
public @NotNull List<Point> getClosedChests() {
return closedChests;
}

/**
* Get the open treasure chests in this room.
*
* @return the open treasure chest positions in this room
*/
public @NotNull List<Point> getOpenChests() {
return openChests;
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/mg105/user_interface/MapDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.image.ImageView;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
Expand All @@ -25,6 +26,7 @@ public class MapDrawer implements PropertyChangeListener, Toggleable {
private final @NotNull Group group;
private final @NotNull Map<TileType, Image> tiles;
private final @NotNull Map<String, Image> playerSprites;
private final @NotNull Image missingTile;
private boolean isVisible;

/**
Expand All @@ -43,12 +45,15 @@ public MapDrawer(@NotNull RoomInterpreter interpreter) {
);
isVisible = false;

missingTile = new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/missing.png")));

tiles = new HashMap<>(6);
tiles.put(TileType.FLOOR, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/floor.png"))));
tiles.put(TileType.WALL, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/wall.png"))));
tiles.put(TileType.WALL_WITH_FACE, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/wall_face.png"))));
tiles.put(TileType.EXIT, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/exit.png"))));
tiles.put(TileType.CHEST, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/chest.png"))));
tiles.put(TileType.PLAYER, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/sprites/A.png"))));
tiles.put(TileType.CHEST_OPEN, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/chest_open.png"))));
tiles.put(TileType.OPPONENT_SET, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/battle.png"))));

playerSprites = new HashMap<>(4);
Expand Down Expand Up @@ -79,8 +84,7 @@ public MapDrawer(@NotNull RoomInterpreter interpreter) {
public void toggle(boolean isVisible) {
this.isVisible = isVisible;

if (isVisible) { //Maybe four Image objects should be saved on a file somewhere else instead?
tiles.put(TileType.PLAYER, playerSprites.get(interpreter.updateCharacterSprite()));
if (isVisible) {
updateRoom();
}
}
Expand All @@ -96,7 +100,7 @@ public void updateRoom() {

for (int y = 0; y < MapConstants.ROOM_SIZE; y++) {
for (int x = 0; x < MapConstants.ROOM_SIZE; x++) {
ImageView tile = new ImageView(tiles.get(room[y][x]));
ImageView tile = new ImageView(tiles.getOrDefault(room[y][x], missingTile));

tile.setPreserveRatio(true);
tile.setX(x * MapConstants.TILE_SIZE);
Expand All @@ -107,6 +111,15 @@ public void updateRoom() {
group.getChildren().add(tile);
}
}

Point player = interpreter.getPlayer();
ImageView playerTile = new ImageView(playerSprites.getOrDefault(interpreter.updateCharacterSprite(), missingTile));
playerTile.setPreserveRatio(true);
playerTile.setX(player.x * MapConstants.TILE_SIZE);
playerTile.setY(player.y * MapConstants.TILE_SIZE);
playerTile.setFitHeight(MapConstants.TILE_SIZE);
playerTile.setFitWidth(MapConstants.TILE_SIZE);
group.getChildren().add(playerTile);
}

/**
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/mg105/user_interface/MinimapDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public class MinimapDrawer implements Toggleable {
private final @NotNull Scene scene;
private final @NotNull Group group;

private static final @NotNull Color PATH_COLOR = Color.rgb(135, 160, 227);
private static final @NotNull Color ROOM_COLOR = Color.rgb(205, 220, 255);
private static final @NotNull Color CURRENT_ROOM_COLOR = Color.rgb(200, 150, 61);
private static final @NotNull Color BACKGROUND_COLOR = Color.rgb(38, 44, 68);

/**
* Create a new MinimapDrawer.
*
Expand All @@ -31,6 +36,7 @@ public MinimapDrawer(@NotNull MinimapInterpreter interpreter) {

group = new Group();
scene = new Scene(group, CANVAS_SIZE, CANVAS_SIZE);
scene.setFill(BACKGROUND_COLOR);
}

/**
Expand Down Expand Up @@ -71,7 +77,7 @@ public void toggle(boolean isVisible) {
r.setY(topPadding + y * cellDimension);
r.setWidth(cellDimension);
r.setHeight(cellDimension);
r.setFill(Color.GREEN);
r.setFill(CURRENT_ROOM_COLOR);
group.getChildren().add(r);
}

Expand All @@ -83,6 +89,7 @@ public void toggle(boolean isVisible) {
r.setY(topPadding + innerCellPadding + y * cellDimension);
r.setWidth(cellDimension - 2 * innerCellPadding);
r.setHeight(cellDimension - 2 * innerCellPadding);
r.setFill(ROOM_COLOR);
group.getChildren().add(r);

// Now we draw the lines that sick out
Expand All @@ -96,8 +103,9 @@ public void toggle(boolean isVisible) {
Line l = new Line();
l.setStartX(xMidpoint);
l.setEndX(xMidpoint);
l.setStartY(topPadding + y * cellDimension + innerCellPadding);
l.setStartY(topPadding + y * cellDimension + innerCellPadding - strokeWidthCorrection);
l.setEndY(topPadding + y * cellDimension + strokeWidthCorrection);
l.setStroke(PATH_COLOR);
l.setStrokeWidth(strokeWidth);
group.getChildren().add(l);
}
Expand All @@ -107,30 +115,33 @@ public void toggle(boolean isVisible) {
Line l = new Line();
l.setStartX(xMidpoint);
l.setEndX(xMidpoint);
l.setStartY(topPadding + y * cellDimension + cellDimension - innerCellPadding);
l.setStartY(topPadding + y * cellDimension + cellDimension - innerCellPadding + strokeWidthCorrection);
l.setEndY(topPadding + y * cellDimension + cellDimension - strokeWidthCorrection);
l.setStroke(PATH_COLOR);
l.setStrokeWidth(strokeWidth);
group.getChildren().add(l);
}

// Line coming out the left
if (x > 0 && map[y][x-1] != null) {
Line l = new Line();
l.setStartX(leftPadding + x * cellDimension + innerCellPadding);
l.setStartX(leftPadding + x * cellDimension + innerCellPadding - strokeWidthCorrection);
l.setEndX(leftPadding + x * cellDimension + strokeWidthCorrection);
l.setStartY(yMidpoint);
l.setEndY(yMidpoint);
l.setStroke(PATH_COLOR);
l.setStrokeWidth(strokeWidth);
group.getChildren().add(l);
}

// Line coming out the right
if (x < map[0].length - 1 && map[y][x+1] != null) {
Line l = new Line();
l.setStartX(leftPadding + x * cellDimension + cellDimension - innerCellPadding);
l.setStartX(leftPadding + x * cellDimension + cellDimension - innerCellPadding + strokeWidthCorrection);
l.setEndX(leftPadding + x * cellDimension + cellDimension - strokeWidthCorrection);
l.setStartY(yMidpoint);
l.setEndY(yMidpoint);
l.setStroke(PATH_COLOR);
l.setStrokeWidth(strokeWidth);
group.getChildren().add(l);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void toggle(@NotNull ToggleableComponent component) {

components.get(activeComponents.peek()).toggle(true);
primaryStage.setScene(components.get(activeComponents.peek()).getScene());
primaryStage.setTitle("Mountain Group 105: " + activeComponents.peek());
}

/**
Expand Down
Binary file modified src/main/resources/sprites/A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/sprites/B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/sprites/C.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/sprites/D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/tiles/battle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/tiles/chest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/tiles/chest_open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/tiles/exit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/tiles/floor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/tiles/missing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/tiles/wall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/tiles/wall_face.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/test/java/com/mg105/entities/ChestTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mg105.entities;
import com.mg105.entities.items.HealthPotion;
import com.mg105.entities.items.MegaPotion;
import com.mg105.use_cases.RoomUpdater;
import com.mg105.use_cases.outputds.ItemDetails;
import com.mg105.use_cases.ChestInteractor;
import com.mg105.use_cases.inventory.InventoryInteractor;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void inventoryDetails(ItemDetails[] allItemsDetails) {
}
};
private static final InventoryInteractor inventoryInteractor = new InventoryInteractor(game, pres);
private static final ChestInteractor chestInteractor = new ChestInteractor(game, inventoryInteractor);
private static final ChestInteractor chestInteractor = new ChestInteractor(game, inventoryInteractor, new RoomUpdater());
private static final ArrayList<TreasureChest> chestList1 = new ArrayList<>();
private static final ArrayList<TreasureChest> chestList2 = new ArrayList<>();
private static final ArrayList<OpponentSet> opponents = new ArrayList<>();
Expand Down
Loading

0 comments on commit be3dfee

Please sign in to comment.