Skip to content

Commit

Permalink
several bugs battle fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
HastiKarimi committed Jun 26, 2021
1 parent 61bddab commit 746abaf
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 497 deletions.
5 changes: 3 additions & 2 deletions src/main/java/controller/game/BattleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public class BattleController {

public BattleController(MonsterCardInUse attacker, MonsterCardInUse preyCard,
BattlePhaseController battlePhaseController) {
MainPhaseController mainPhase = preyBoard.getController().getMainPhaseController();
int summonedCardsLength = mainPhase.summonedInThisPhase.size();
this.attackerBoard = attacker.getBoard();
this.preyBoard = preyCard.getBoard();
this.attacker = attacker;
this.preyCard = preyCard;
MainPhaseController mainPhase = preyBoard.getController().getMainPhaseController();
preyBoard.getController().getBattlePhaseController().battleController = this;
int summonedCardsLength = mainPhase.summonedInThisPhase.size();
attackerAttack = attacker.getAttack();
preyPoint = preyCard.appropriatePointAtBattle();
attacker.watchByState(CardState.WANT_TO_ATTACK);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/controller/game/BattlePhaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import model.card.CardType;
import model.card.cardinusematerial.CardInUse;
import model.card.cardinusematerial.MonsterCardInUse;
import view.messageviewing.Print;
import view.exceptions.*;

import java.util.ArrayList;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void reArrangeBattle(MonsterCardInUse attacker) {
MonsterCardInUse preyCard = (MonsterCardInUse) selectController.getTheCardInUse();
if (preyCard != null)
battleController = new BattleController(attacker, preyCard, this);
//TODO else : print that battle was canceled
else Print.print(Print.cancelBattle);
}
}

Expand All @@ -66,7 +67,7 @@ public void attackToLifePoint() throws NoSelectedCard, CardCantAttack, WrongPhas
throw new NoSelectedCard();
else if (!(cardInUse instanceof MonsterCardInUse))
throw new CardCantAttack();
else if (((MonsterCardInUse) cardInUse).isInAttackMode())
else if (!((MonsterCardInUse) cardInUse).isInAttackMode())
throw new CardCantAttack();
else if (gamePlay.getCurrentPhase() != Phase.BATTLE)
throw new WrongPhaseForAction();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/model/watchers/Watcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected static void emptyStack() {
protected static boolean addToStack(Watcher watcher) {
if (!stack.contains(watcher)) {
if (stack.size() == 0 || stack.get(stack.size() - 1).speed <= watcher.speed) {
if (stack.get(stack.size() - 1).ownerOfWatcher.ownerOfCard != watcher.ownerOfWatcher.ownerOfCard)
if (stack.size() !=0 && stack.get(stack.size() - 1).ownerOfWatcher.ownerOfCard != watcher.ownerOfWatcher.ownerOfCard)
roundController.temporaryTurnChange(watcher.ownerOfWatcher.ownerOfCard);
if (watcher.ownerOfWatcher.thisCard.preCardInGeneral instanceof PreSpellTrapCard) {
PreSpellTrapCard preSpellTrapCard = (PreSpellTrapCard) watcher.ownerOfWatcher.thisCard.preCardInGeneral;
Expand Down Expand Up @@ -123,7 +123,7 @@ public void trapHasDoneItsEffect() {

public void addWatcherToCardInUse(CardInUse cardInUse) {
if (cardInUse == null) return;
if (!amWatching.contains(cardInUse)) {
if (!cardInUse.isCellEmpty() && !amWatching.contains(cardInUse)) {
cardInUse.watchersOfCardInUse.add(this);
amWatching.add(cardInUse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean canPutWatcher() {
@Override
public void putWatcher(CardInUse cardInUse) {
for (MonsterCardInUse monsterCardInUse : ownerOfWatcher.ownerOfCard.getBoard().getMonsterZone()) {
if (!amWatching.contains(monsterCardInUse)) {
if (!monsterCardInUse.isCellEmpty() && !amWatching.contains(monsterCardInUse)) {
monsterCardInUse.addToAttack(400);
monsterCardInUse.watchersOfCardInUse.add(this);
amWatching.add(monsterCardInUse);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/view/messageviewing/Print.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package view.messageviewing;

public class Print { //print in general
public static String cancelBattle = "the battle was canceled";
public static void print(String toBePrinted) {
System.out.println(toBePrinted);
}
Expand Down
Loading

0 comments on commit 746abaf

Please sign in to comment.