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

Commit

Permalink
Merge branch 'main' into siddharthgowda-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthgowda authored Dec 1, 2022
2 parents 8acad32 + 1ab0843 commit b4289e0
Show file tree
Hide file tree
Showing 41 changed files with 1,754 additions and 491 deletions.
64 changes: 25 additions & 39 deletions src/main/java/com/mg105/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mg105;

import com.mg105.controllers.TutorialTextController;
import com.mg105.entities.*;
import com.mg105.interface_adapters.InputInterpreter;
import com.mg105.interface_adapters.MapGeneratorInterpreter;
Expand All @@ -11,8 +12,11 @@
import com.mg105.use_cases.Inventory.InventoryInteractor;
import com.mg105.use_cases.MapGenerator;
import com.mg105.use_cases.RoomGetter;
import com.mg105.use_cases.RoomUpdater;
import com.mg105.user_interface.*;
import com.mg105.utils.TutorialTexts;
import com.mg105.user_interface.inventory.InventoryDisplay;
import com.mg105.utils.PartyConstants;
import javafx.animation.AnimationTimer;
import javafx.scene.control.Label;
import javafx.scene.input.KeyEvent;
Expand All @@ -26,8 +30,6 @@
* Effectively, the main class that sets up the clean architecture mountain group 105 game!
*/
public class Application extends javafx.application.Application {
private final TutorialTextDisplay tutorialDisplay = new TutorialTextDisplay();
private Label bottomText;

/**
* Note that while this isn't our main method explicitly, we (probably) need this to effectively be our main method
Expand All @@ -40,20 +42,20 @@ public void start(Stage primaryStage) {

// Set up the initial use cases

BattleCharacter a = new BattleCharacter(30, "A", 4, 5, false,
new Move(-3, 0, "Slow swing", false),
BattleCharacter a = new BattleCharacter(30, PartyConstants.ALL_PARTY_MEMBER_NAMES[0], 4, 5,
false, new Move(-3, 0, "Slow swing", false),
new Move(0, -1, "Nullify", false));

BattleCharacter b = new BattleCharacter(20, "B", 6, 8, false,
new Move(-4, 0, "Strong swing", false),
BattleCharacter b = new BattleCharacter(20, PartyConstants.ALL_PARTY_MEMBER_NAMES[1], 6, 8,
false, new Move(-4, 0, "Strong swing", false),
new Move(3, 0, "Weak heal", true));

BattleCharacter c = new BattleCharacter(25, "C", 3, 6, false,
new Move(6, 0, "Strong heal", true),
BattleCharacter c = new BattleCharacter(25, PartyConstants.ALL_PARTY_MEMBER_NAMES[2], 3, 6,
false, new Move(6, 0, "Strong heal", true),
new Move(2, 2, "Reinforce", true));

BattleCharacter d = new BattleCharacter(15, "D", 9, 10, false,
new Move(-5, 0, "Surprise attack", false),
BattleCharacter d = new BattleCharacter(15, PartyConstants.ALL_PARTY_MEMBER_NAMES[3], 9, 10,
false, new Move(-5, 0, "Surprise attack", false),
new Move(-2, -2, "Sabotage", false));

BattleCharacter[] party = {a, b, c, d};
Expand Down Expand Up @@ -85,8 +87,19 @@ public void start(Stage primaryStage) {
drawableComponents.put(Toggler.ToggleableComponent.MAIN_MENU, mainMenu);
drawableComponents.put(Toggler.ToggleableComponent.MAP, mapDrawer);

CharacterMover characterMover = new CharacterMover(state, mapDrawer);
InputInterpreter inputInterpreter = new InputInterpreter(characterMover, sceneController);
/////Tutorial scene////
TutorialTextController textChanger = new TutorialTextController(false);
TutorialTextDisplay textDisplay = new TutorialTextDisplay();
TutorialTextWindow tutorialDisplay = new TutorialTextWindow(textChanger, textDisplay);
drawableComponents.put(Toggler.ToggleableComponent.TUTORIAL, tutorialDisplay);
//////////////////////

RoomUpdater roomUpdater = new RoomUpdater();
roomUpdater.addObserver(mapDrawer);

CharacterMover characterMover = new CharacterMover(state, roomUpdater);
InputInterpreter inputInterpreter = new InputInterpreter(characterMover, sceneController, textChanger);

InputListener inputListener = new InputListener(inputInterpreter);
primaryStage.addEventFilter(KeyEvent.KEY_TYPED, inputListener);

Expand All @@ -96,31 +109,4 @@ public void start(Stage primaryStage) {
primaryStage.show();
}

private class TutorialTimer extends AnimationTimer {
private long prevTime = 0;

/**
* This method needs to be overridden by extending classes. It is going to
* be called in every frame while the {@code AnimationTimer} is active.
*
* @param now The timestamp of the current frame given in nanoseconds. This
* value will be the same for all {@code AnimationTimers} called
* during one frame.
*/
@Override
public void handle(long now) {
long timeChange = now - prevTime;

// 5e9 is 5 seconds
if (timeChange > 4e9) {
prevTime = now;
tutorialDisplay.getController().nextPhase();
int phase_num = tutorialDisplay.getController().getTutorial().currentPhase();
String tutorialText = tutorialDisplay.getController().getTutorial().allPhases().get(phase_num);
bottomText.setText(tutorialDisplay.showBottomText(tutorialText));

}

}
}
}
35 changes: 34 additions & 1 deletion src/main/java/com/mg105/controllers/TutorialTextController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
public class TutorialTextController {

private final PlayerGetsTutorial tutorial = new PlayerGetsTutorial(TutorialTexts.PHASES, 0, new GiveTutorial(false, false, false));
private boolean changeText;
private boolean showControls = false;

public TutorialTextController() {
public TutorialTextController(boolean changeText) {
this.changeText = changeText;
}

/**
Expand All @@ -25,6 +28,36 @@ public String bottomText() {
*/
public void nextPhase() { this.tutorial.nextPhase(); }

/**
* Make text start changing
*/
public void setChangeText() {
this.changeText = !this.changeText;
}

/**
* Check if tutorial phases should advance
*
* @return if text should start changing
*/
public boolean changeText() { return this.changeText; }

/**
* Tell player the controls again
*
* @param show the text on the screen when true
*/
public void setShowControls(boolean show) {
this.showControls = show;
}

/**
* Check if player should be shown controls again
*
* @return whether player should be shown the control texts
*/
public boolean getShowControls() { return this.showControls; }

/**
* Get an instance of the PlayerGetsTutorial use case
*
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mg105/entities/Battle.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Battle {
private int battleStatus;
private final ArrayList<BattleCharacter> opponents;
private final ArrayList<BattleCharacter> playerCharacters;
private final ArrayList<BattleCharacter> moveQueue = new ArrayList<BattleCharacter>();
private final ArrayList<BattleCharacter> moveQueue = new ArrayList<>();

//not sure if numTokens should be randomly generated on creation, or after battleStatus has changed (this
// implementation will assume the latter).
Expand Down Expand Up @@ -110,7 +110,7 @@ public void removeChar(BattleCharacter fainted) {
/**
* Returns the character in the encounter based on the given name
*
* @param name
* @param name the name String of the BattleCharacter to be returned
* @return the BattleCharacter in the encounter with the given name
* @throws NoSuchElementException if no character in the party has the given name
*/
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/com/mg105/entities/BattleCharacter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class BattleCharacter implements Comparable<BattleCharacter> {
private int dmg;
private int speed;

private boolean isOpponent;
private final boolean isOpponent;

private Move[] moves = new Move[2];
private final Move[] moves = new Move[2];

//Don't know how to handle the sprite instance

Expand Down Expand Up @@ -154,12 +154,6 @@ public void modifySpeed(int speedChange) {
*/
@Override
public int compareTo(BattleCharacter other) {
if (this.speed < other.speed) {
return -1;
} else if (this.speed > other.speed) {
return 1;
} else {
return 0;
}
return Integer.compare(this.speed, other.speed);
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/mg105/entities/Doorway.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.awt.*;

/**
* A Doorway represents a single-direction connection from one room to another.
*/
public class Doorway {
private final Point position;
private final Room nextRoom;
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/mg105/entities/GameState.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mg105.entities;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.NotNull;

Expand All @@ -21,15 +22,20 @@ public class GameState {
private Battle currEncounter = null;

//Potentially useless. Keeps track of party characters who faint in battle.
private final ArrayList<BattleCharacter> fainted = new ArrayList<BattleCharacter>();
private final ArrayList<BattleCharacter> fainted = new ArrayList<>();

/**
* Create a new game state.
*
* @param inventory the player's inventory.
* @param party the player's party.
* @param walkingCharacter the player's character data.
*/
public GameState(Inventory inventory, BattleCharacter[] party, WalkingCharacter walkingCharacter) {
this.inventory = inventory;
this.party = new ArrayList<BattleCharacter>();
this.party = new ArrayList<>();

for (BattleCharacter c : party) {
this.party.add(c);
}
this.party.addAll(Arrays.asList(party));
this.walkingCharacter = walkingCharacter;
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/mg105/entities/GiveTutorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

public class GiveTutorial {

private boolean moved = false;
private boolean attacked = false;
private boolean usedItem = false;
private boolean moved;
private boolean attacked;
private boolean usedItem;

public GiveTutorial(boolean moved, boolean attacked, boolean usedItem) {
this.moved = moved;
Expand All @@ -23,11 +23,11 @@ public GiveTutorial(boolean moved, boolean attacked, boolean usedItem) {
* @param action the action that has been performed
*/
public void ActionPerformedSetter(String action) {
if (action.equalsIgnoreCase(TutorialTexts.moved)) {
if (action.equalsIgnoreCase(TutorialTexts.MOVED)) {
this.moved = true;
} else if (action.equalsIgnoreCase(TutorialTexts.attacked)) {
} else if (action.equalsIgnoreCase(TutorialTexts.ATTACKED)) {
this.attacked = true;
} else if (action.equalsIgnoreCase(TutorialTexts.usedItem)) {
} else if (action.equalsIgnoreCase(TutorialTexts.USED_ITEM)) {
this.usedItem = true;
}

Expand All @@ -42,11 +42,11 @@ public void ActionPerformedSetter(String action) {
* @return whether the player has performed each action
*/
public boolean ActionPerformedGetter(String action) {
if (action.equalsIgnoreCase(TutorialTexts.moved)) {
if (action.equalsIgnoreCase(TutorialTexts.MOVED)) {
return this.moved;
} else if (action.equalsIgnoreCase(TutorialTexts.attacked)) {
} else if (action.equalsIgnoreCase(TutorialTexts.ATTACKED)) {
return this.attacked;
} else if (action.equalsIgnoreCase(TutorialTexts.usedItem)) {
} else if (action.equalsIgnoreCase(TutorialTexts.USED_ITEM)) {
return this.usedItem;
} else {
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/mg105/entities/OpponentSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.awt.*;
import java.util.List;

/**
* OpponentSet stores a potential battle on a map.
*/
public class OpponentSet {
private final Point position;
private final List<BattleCharacter> opponents;
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/mg105/entities/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import java.util.List;

/**
* Room represents a single room in the map.
*/
public class Room {
private final @NotNull List<TreasureChest> chests;
private final @NotNull List<OpponentSet> opponents;
Expand All @@ -28,7 +31,7 @@ public Room(@NotNull List<TreasureChest> chests, @NotNull List<OpponentSet> oppo
*
* @return the treasure chests in this room.
*/
public List<TreasureChest> getChests() {
public @NotNull List<TreasureChest> getChests() {
return chests;
}

Expand All @@ -37,7 +40,7 @@ public List<TreasureChest> getChests() {
*
* @return the opponents in this room.
*/
public List<OpponentSet> getOpponents() {
public @NotNull List<OpponentSet> getOpponents() {
return opponents;
}

Expand All @@ -46,7 +49,7 @@ public List<OpponentSet> getOpponents() {
*
* @return the doorways in this room.
*/
public List<Doorway> getDoorways() {
public @NotNull List<Doorway> getDoorways() {
return doorways;
}

Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/mg105/entities/WalkingCharacter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import java.awt.*;

public class WalkingCharacter {
public Point charPosition;
private Point charPosition;
private String spriteName;

public WalkingCharacter(Point position) {
this.charPosition = position;
this.spriteName = "A";
}

/**
Expand All @@ -22,5 +24,21 @@ public void setCharPosition(Point position) {
public Point getCharPosition() {
return this.charPosition;
}

/**
* Returns the name of the character whose sprite is currently being used.
* @return a sprite name String.
*/
public String getSpriteName() {
return spriteName;
}

/**
* Sets the name of the character whose sprite is currently being used.
* @param spriteName name of the character to change the sprite to.
*/
public void setSpriteName(String spriteName) {
this.spriteName = spriteName;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mg105.interface_adapters;

/**
* This interface should be implemented by BattleMenu.
* <p>
* The methods represent calls to update data attributes and the display.
*/
public interface BattleMenuInterface {

/**
* Sets the names of the player and opponent characters participating in the active battle.
*
* @param playerNames array of name Strings representing player characters.
* @param opponentNames array of name Strings representing opponents.
*/
void setNames(String[] playerNames, String[] opponentNames);

/**
* Updates the display corresponding to the given affected character.
*
* @param character the character who needs to be updated on the screen.
*/
void updateCharacter(String character);
}
Loading

0 comments on commit b4289e0

Please sign in to comment.