Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ahak14 committed May 9, 2019
1 parent 21f0e3a commit c291d63
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 62 deletions.
8 changes: 3 additions & 5 deletions src/controller/BattleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class BattleController {
private BattleLogicController battleLogicController;
private boolean isEndedGame = false;

//TODO add coordination for show minion

public static BattleController getInstance() {

if (battleController == null) {
Expand Down Expand Up @@ -145,6 +143,7 @@ private void selectAndUseCardRequestMove(Card card, Cell destinationCell) {

gameLogic.moveProcess(card, destinationCell);
//todo if there is flag in cell get that
//todo check mane
}

private void selectAndUseCardRequestShowInfo(SelectAndUseCardRequest request, Card item) {
Expand Down Expand Up @@ -203,7 +202,6 @@ private void enterGraveYardRequestShowCards() {
ArrayList<Card> cards;
if (match.findPlayerPlayingThisTurn().equals(match.getPlayer1()))
cards = match.getPlayer1GraveYard().getCards();

else
cards = match.getPlayer2GraveYard().getCards();

Expand Down Expand Up @@ -310,7 +308,7 @@ private void gameInfoRequestKillTheHeroMode(Cell[][] cells) {

Unit hero = (Unit) card;

if (match.getPlayer1().getUserName().equals(card.getTeam()))
if (match.getPlayer1().getUserName().equals(hero.getTeam()))
gameInfoBattleViewKillTheHero.setPlayer1HeroHP(hero.getHealthPoint());
else
gameInfoBattleViewKillTheHero.setPlayer2HeroHP(hero.getHealthPoint());
Expand Down Expand Up @@ -442,7 +440,7 @@ private void showNextCardRequest() {
showCardsBattleView.show(showCardsBattleView);

} catch (NullPointerException e) {
System.out.println("You don't have reserve card");
BattleLog.errorHasNotReserveCard();
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/controller/BattleLogicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ public boolean isCellAvailableForMove(Cell originCell, Cell destinationCell) {
public boolean isUnitStun(Unit unit) {

ArrayList<Buff> buffs = unit.getBuffs();
try {
for (Buff buff : buffs) {

for (Buff buff : buffs) {

if (buff.isStun()) {
BattleLog.errorUnitIsStun();
return true;
if (buff.isStun()) {
BattleLog.errorUnitIsStun();
return true;
}
}
} catch (NullPointerException e) {
System.err.println("ArrayList of buff is null (BattleLogicController/isUnitStun)");
}

return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/models/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void setID(Card card) {
} catch (NullPointerException e) {
}
card.setCardID(userName + "_" + card.getCardName() + "_" + (instanceNum + 1));
card.setTeam(userName);
card.setSellCost();
}

Expand Down
8 changes: 4 additions & 4 deletions src/models/GamePlay/GameLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class GameLogic {
private Match match;
int flagsNumber;
int remainTurnToHoldingTheFlag; //todo initialize in dead and get
private ArrayList<Card> attackedCardsInATurn = new ArrayList<>(); //todo add attacker to array
private ArrayList<Card> movedCardsInATurn = new ArrayList<>();
private ArrayList<Card> cardsInTablePlayer1 = new ArrayList<>(); //todo fill that in game and delete when minion die
private ArrayList<Card> cardsInTablePlayer2 = new ArrayList<>();
ArrayList<Card> attackedCardsInATurn = new ArrayList<>(); //todo add attacker to array
ArrayList<Card> movedCardsInATurn = new ArrayList<>();
ArrayList<Card> cardsInTablePlayer1 = new ArrayList<>(); //todo fill that in game and delete when minion die
ArrayList<Card> cardsInTablePlayer2 = new ArrayList<>();

public ArrayList<Card> getCardsInTablePlayerPlayingThisTurn() {

Expand Down
36 changes: 26 additions & 10 deletions src/models/GamePlay/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public Match(MatchType matchType, Account player1, Account player2) {
this.player1 = player1;
this.player2 = player2;
gameLogic = new GameLogic(this);
if (matchType == MatchType.HOLD_THE_FLAG)
gameLogic.remainTurnToHoldingTheFlag = gameLogic.NUMBER_OF_TURNS_TO_HOLD_THE_FLAG;

initializePlayerVariables();
if (matchType == MatchType.KILL_THE_HERO) initializeTableModeKillTheHero();
else initializeTableModeHoldTheFlag();
}

public Match(int flagsNumber, Account player1, Account player2) {
Expand All @@ -79,6 +81,9 @@ public Match(int flagsNumber, Account player1, Account player2) {
this.player2 = player2;
gameLogic = new GameLogic(this);
gameLogic.flagsNumber = flagsNumber;

initializePlayerVariables();
initializeTableModeCollectTheFlag(flagsNumber);
}

public Account findPlayerPlayingThisTurn() {
Expand All @@ -87,28 +92,39 @@ public Account findPlayerPlayingThisTurn() {
return player2;
}

public void intializeTableModeKillTheHero() {
private void initializeTableModeKillTheHero() {

Card hero1 = player1.getHand().getHero();
Card hero2 = player2.getHand().getHero();

table.getCells()[2][0].setCard(hero1);
table.getCells()[2][8].setCard(hero2);
Cell cellHero1 = table.getCells()[2][1];
Cell cellHero2 = table.getCells()[2][7];
cellHero1.setCard(hero1);
cellHero2.setCard(hero2);
hero1.setCell(cellHero1);
hero2.setCell(cellHero2);

gameLogic.cardsInTablePlayer1.add(hero1);
gameLogic.cardsInTablePlayer2.add(hero2);
}

private void initializePlayerVariables() {

player1.getHand().initializeHand(player1.getCollection().getSelectedDeck());
player2.getHand().initializeHand(player2.getCollection().getSelectedDeck());
}

public void intializeTableModeHoldTheFlag() {
private void initializeTableModeHoldTheFlag() {

intializeTableModeKillTheHero();
initializeTableModeKillTheHero();

Card flag = new Card(0, 0, "flag", null, "", CardType.FLAG, null);
table.getCells()[2][4].setCard(flag);

}

public void intializeTableModeCollectTheFlag(int numberOfFlags) {
private void initializeTableModeCollectTheFlag(int numberOfFlags) {

intializeTableModeKillTheHero();
initializeTableModeKillTheHero();

Random random = new Random();

Expand Down
2 changes: 1 addition & 1 deletion src/models/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class Unit extends Card implements Serializable {
private int HP;
private int AP;
private ArrayList<Buff> buffs;
private ArrayList<Buff> buffs = new ArrayList<>();
private SpecialPowerType specialPowerType;
private Spell specialPower;
private UnitType unitType;
Expand Down
1 change: 1 addition & 0 deletions src/request/battleRequest/BattleRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private BattleRequest select(String command) {

SelectAndUseCardRequest selectAndUseCardRequest = new SelectAndUseCardRequest();
selectAndUseCardRequest.setID(command.split("\\s")[1]);
BattleLog.logCardSelected(selectAndUseCardRequest.getID());

while (true) {

Expand Down
12 changes: 11 additions & 1 deletion src/view/battleView/BattleLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

public class BattleLog {

public static void logCardSelected(String cardID) {

System.out.println(cardID + " selected");
}

public static void errorInvalidCardID() {

System.out.println("Invalid card id");
Expand Down Expand Up @@ -51,7 +56,7 @@ public static void errorIsNotYourTurn() {

public static void errorCellIsFill() {

System.out.println("This cell is fill and can not insert minion on this cell");
System.out.println("This cell is fill");
}

public static void errorCellIsNotFill() {
Expand Down Expand Up @@ -117,4 +122,9 @@ public static void errorUnitMovedPreviously() {

System.out.println("This unit moved previously");
}

public static void errorHasNotReserveCard() {

System.out.println("You don't have reserve card");
}
}
10 changes: 5 additions & 5 deletions src/view/battleView/BattleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,28 @@ private void showCardInfoHero(ShowCardInfoBattleViewHero showInfo) {
System.out.println("Hero:");
System.out.println(" Name: " + showInfo.getName());
System.out.println(" Cost: " + showInfo.getCost());
System.out.println(" Desc: \n" + showInfo.getDescription());
System.out.println(" Desc: " + showInfo.getDescription());
}

private void showCardInfoMinion(ShowCardInfoBattleViewMinion showInfo) {

System.out.println(" Minion:");
System.out.println("Minion:");
System.out.println(" Name: " + showInfo.getName());
System.out.println(" HP: " + showInfo.getHealthPoint() +
" AP:" + showInfo.getAttackPoint() + " MP:" + showInfo.getManaPoint());
System.out.println(" Range: " + showInfo.getRange());
System.out.println(" Combo-ability: " + showInfo.hasComboAbility());
System.out.println(" Cost: " + showInfo.getCost());
System.out.println(" Desc: \n" + showInfo.getDescription());
System.out.println(" Desc: " + showInfo.getDescription());
}

private void showCardInfoSpell(ShowCardInfoBattleViewSpell showInfo) {

System.out.println(" Spell:");
System.out.println("Spell:");
System.out.println(" Name: " + showInfo.getName());
System.out.println(" MP: " + showInfo.getManaPoint());
System.out.println(" Cost: " + showInfo.getCost());
System.out.println(" Desc: \n" + showInfo.getDescription());
System.out.println(" Desc: " + showInfo.getDescription());
}

private void showCollectedItems(ShowCollectedItemsBattleView collectedItem) {
Expand Down
7 changes: 2 additions & 5 deletions src/view/battleView/ShowCardsBattleView.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package view.battleView;

import models.Card;
import models.CardType;
import models.Unit;
import models.UnitType;
import models.*;

import java.util.ArrayList;

Expand All @@ -30,7 +27,7 @@ else if (card.getType() == CardType.MINION) {

} else if (card.getType() == CardType.SPELL) {

Unit spell = (Unit) card;
Spell spell = (Spell) card;
setCardsForSpell(spell.getCardName(), spell.getPrice(), spell.getDescription(),
spell.getManaCost());
}
Expand Down
50 changes: 25 additions & 25 deletions testCase.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
create account erfan
erfan
create account ali
ali
enter shop
buy total_disarm
buy lighting_bolt
Expand Down Expand Up @@ -28,30 +28,30 @@ buy panther
exit
enter collection
create deck mode1
add erfan_total_disarm_1 to deck mode1
add erfan_lighting_bolt_1 to deck mode1
add erfan_all_disarm_1 to deck mode1
add erfan_all_poison_1 to deck mode1
add erfan_dispel_1 to deck mode1
add erfan_sacrifice_1 to deck mode1
add erfan_shock_1 to deck mode1
add ali_total_disarm_1 to deck mode1
add ali_lighting_bolt_1 to deck mode1
add ali_all_disarm_1 to deck mode1
add ali_all_poison_1 to deck mode1
add ali_dispel_1 to deck mode1
add ali_sacrifice_1 to deck mode1
add ali_shock_1 to deck mode1

add erfan_white_demon_1 to deck mode1
add erfan_soul_eater_1 to deck mode1
add ali_white_demon_1 to deck mode1
add ali_soul_eater_1 to deck mode1

add erfan_iraj_1 to deck mode1
add erfan_iraj_2 to deck mode1
add erfan_arjang_1 to deck mode1
add erfan_big_giant_1 to deck mode1
add erfan_panther_1 to deck mode1
add erfan_siavash_1 to deck mode1
add erfan_iraj_3 to deck mode1
add erfan_iraj_4 to deck mode1
add erfan_iraj_5 to deck mode1
add erfan_big_giant_2 to deck mode1
add erfan_panther_2 to deck mode1
add erfan_big_giant_3 to deck mode1
add erfan_panther_3 to deck mode1
add ali_iraj_1 to deck mode1
add ali_iraj_2 to deck mode1
add ali_arjang_1 to deck mode1
add ali_big_giant_1 to deck mode1
add ali_panther_1 to deck mode1
add ali_siavash_1 to deck mode1
add ali_iraj_3 to deck mode1
add ali_iraj_4 to deck mode1
add ali_iraj_5 to deck mode1
add ali_big_giant_2 to deck mode1
add ali_panther_2 to deck mode1
add ali_big_giant_3 to deck mode1
add ali_panther_3 to deck mode1

select deck mode1
exit
Expand Down Expand Up @@ -116,5 +116,5 @@ select deck mode1
exit
enter battle
2
select user erfan
select user ali
start multiplayer game 1

0 comments on commit c291d63

Please sign in to comment.