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 #105 from CSC207-2022F-UofT/features/forfeit
Browse files Browse the repository at this point in the history
Added forfeit option to battle
  • Loading branch information
m-grigoriu authored Dec 8, 2022
2 parents c20640a + 6a5d969 commit 15b29c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/mg105/use_cases/ReplayGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ private void inventoryClean() {
* Replay the game by interacting with the MapGenerator class
*/
public void replay() {
//Handles the forfeit case, where party is not empty yet.
state.getFainted().addAll(state.getParty());
state.setParty(new BattleCharacter[] {});

//Party is empty, fainted is full.
state.getParty().addAll(state.getFainted());
state.getFainted().removeAll(state.getParty());

this.inventoryClean();
this.attributeInheritance();

// incomplete remake, need to amend later. exactly implementation should depend
// on other use cases' implementation
MapGenerator isekai = new MapGenerator(state);
Expand Down
21 changes: 1 addition & 20 deletions src/main/java/com/mg105/use_cases/battle/BattleInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ public void setPresenter(BattlePresenterInterface presenter) {
* Creates a new encounter with random opponents and sets it as the current encounter in GameState.
*/
public void createEncounter() {
/* OLD RANDOMLY GENERATED OPPONENTS CODE
Random rand = new Random();
ArrayList<BattleCharacter> opponents = new ArrayList<>();
for (int i = 0; i < 4; ++i){
int charHealth = rand.nextInt(5, 41);
int charDmg = rand.nextInt(1, 11);
int charSpeed = rand.nextInt(3, 16);
Move m1 = new Move(-rand.nextInt(1, 8), 0, "first", false);
Move m2 = new Move(rand.nextInt(1, 4), 0, "second", true);
BattleCharacter character = new BattleCharacter(charHealth, "Opponent " + i,
charDmg, charSpeed, true, m1, m2);
opponents.add(character);
}
*/
ArrayList<BattleCharacter> opponents = new ArrayList<>(state.getCurrOpponent().getOpponents());
ArrayList<BattleCharacter> party = this.state.getParty();
Battle b = new Battle(opponents, party);
Expand Down Expand Up @@ -311,12 +295,9 @@ public boolean endBattle() {
if (status == 1) {
addReward();
return true;
} else if (status == -1) {
state.getParty().addAll(state.getFainted());
state.getFainted().removeAll(state.getParty());
}

// since at this point status != 0, status must == -1 (battle was lost)
// status must == -1 (battle was lost) or 0 (battle was forfeited)
return false;
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/mg105/user_interface/BattleMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class BattleMenu implements EventHandler<ActionEvent>, BattleMenuInterfac
private final Label o3 = new Label();

private final Button nextRound;

private final Button forfeit;
private final Button moveOne;
private final Button moveTwo;

Expand Down Expand Up @@ -72,6 +74,11 @@ public BattleMenu(BattlePresenter battlePres) {
nextRound.setOnAction(this);
grid.add(nextRound, 10, 30);

forfeit = new Button("Forfeit");
forfeit.setId("Forfeit");
forfeit.setOnAction(this);
grid.add(forfeit, 10, 2);

grid.add(p0, 1, 4);
grid.add(p1, 1, 8);
grid.add(p2, 1, 12);
Expand Down Expand Up @@ -294,6 +301,8 @@ public void handle(ActionEvent event) {
nextRound.setDisable(false);
}

} else if (source.equals(forfeit)) {
presenter.endBattle();
} else if(source.equals(moveOne)) {
moveNum = 1;
displayTargets();
Expand Down

0 comments on commit 15b29c2

Please sign in to comment.