Skip to content

Commit

Permalink
remove todos & comments, fix some bugs amd make ready for presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
abolfazlghalandary committed Jun 24, 2021
1 parent 35213de commit 64c3e2e
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 133 deletions.
35 changes: 0 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,6 @@
<artifactId>opencsv</artifactId>
<version>5.4</version>
</dependency>

<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-nn</artifactId>
<version>1.0.0-alpha</version>
</dependency>

<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-datasets</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>1.0.0-alpha</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-datavec-iterators</artifactId>
<version>1.0.0-alpha</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-api</artifactId>
<version>1.0.0-alpha</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
Expand All @@ -105,19 +78,11 @@
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>11</version>
</dependency>


</dependencies>

</project>
2 changes: 0 additions & 2 deletions src/main/java/controller/AIPlayerController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package controller;

import com.opencsv.CSVWriter;
import controller.gamephasescontrollers.GameController;
import model.CoinDice;
import model.board.CardStatus;
import model.board.Cell;
import model.cards.Monster;
import view.gamephases.Duel;

import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private String attackToDefensiveHiddenCell(Cell attackerCell, Cell attackedCell,
response = "opponent’s monster card was " +
attackedCell.getCellCard().getName() + " the defense position monster is destroyed";
response += Marshmallon.handleEffect(gameController, attackerCell, attackedCell);
if (!Marshmallon.isMarshmallon(attackedCell))//todo chera ba payiniha fargh miknone? baad inja tanaghoz dareha
if (!Marshmallon.isMarshmallon(attackedCell))
attackedCell.removeCardFromCell(opponentGameBoard);
} else if (isAttackerAndAttackedPowerEqual(attackerCell, attackedCell)) {
response = "opponent’s monster card was " +
Expand Down Expand Up @@ -240,7 +240,7 @@ public GameController getGameController() {
return gameController;
}

public int getPower(Cell cell, Cell attackerCell, Cell attackedCell) {//todo null pointer exception
public int getPower(Cell cell, Cell attackerCell, Cell attackedCell) {
switch (cell.getCardStatus()) {
case DEFENSIVE_OCCUPIED:
case DEFENSIVE_HIDDEN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ public void changeTurn(boolean isTemporary, boolean backToPlayer) {
changedPositionCells = new ArrayList<>();
attackerCellsThisTurn = new ArrayList<>();
turnCount++;
//todo update changedPositionCells & other fields
//todo reset attacked arraylist
}

public void activateTrapEffect(ArrayList<SpellAndTrap> trapsCanBeActivated) {
Expand Down Expand Up @@ -426,6 +424,8 @@ public String getSideDeckCards(Player player) {
}

private void changeCards(Player player) {
if (player.isAI())
return;
Deck deck = player.getPlayDeck();
String deckInfo = player.getUser().getNickname() + "’s Deck: " + deck.getName() + "\n";
ArrayList<Card> monsters = Card.getMonstersSorted(deck.getMainDeck());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ default void monsterSummon(GameController gameController) throws GameException {
currentPlayer.getGameBoard().getHandCards().remove(selectedCell);
Cell.deselectCell();
}
default boolean isSummonedMonsterATKMoreThan1000(Cell summonedCell) {//todo check null pointer exception

default boolean isSummonedMonsterATKMoreThan1000(Cell summonedCell) {
return ((Monster) summonedCell.getCellCard()).getAtk() >= 1000;
}

Expand Down Expand Up @@ -112,18 +113,15 @@ private void addMonstersToSummonEffectSpellAndTrap(Cell summonedCell) {
summonEffectSpellAndTrap.add(new TorrentialTribute());
if (isSummonedMonsterATKMoreThan1000(summonedCell))
flipSummonEffectSpellAndTrap.add(new TorrentialTribute());
//todo add the rest of summon monsters thing
}

private void addMonstersToFlipSummonEffectSpellAndTrap(Cell summonedCell) {
if (isSummonedMonsterATKMoreThan1000(summonedCell))
flipSummonEffectSpellAndTrap.add(new TorrentialTribute());
//todo add the rest of summon monsters thing
}

private void addMonstersToSpecialSummonEffectSpellAndTrap() {
SpecialSummonEffectSpellAndTrap.add(new TorrentialTribute());
//todo add the rest of summon monsters thing
}

private void handleTributeForNormalSummon(Player currentPlayer, Cell selectedCell, int monsterLevel, boolean isSpecialSummon) throws GameException {
Expand Down Expand Up @@ -168,24 +166,10 @@ private void handleTributeForNormalSummon(Player currentPlayer, Cell selectedCel
for (Cell tribute : tributes) {
tribute.removeCardFromCell(playerGameBoard);
}
// for (int i=0;i<numberOfTributes;i++){
// ViewInterface.showResult("select cell to tribute:");
// Duel.processSelect(ViewInterface.getInput());
// newSelectedCell = Cell.getSelectedCell();
// if (!currentPlayer.getGameBoard().isCellInMonsterZone(newSelectedCell))
// ViewInterface.showResult(GameResponses.NO_MONSTER_ON_CELL.response);
// tributes.add(newSelectedCell);
// ViewInterface.showResult("cell taken");
// }
// for (Cell tribute : tributes) {
// tribute.removeCardFromCell(currentPlayer.getGameBoard());
// }
//
// }
}
}

default void setCard(GameController gameController) throws GameException {//todo, the method can insert 6 spells
default void setCard(GameController gameController) throws GameException {
Cell selectedCell = Cell.getSelectedCell();
GameBoard playerGameBoard = gameController.getCurrentTurnPlayer().getGameBoard();
if (selectedCell == null) {
Expand Down Expand Up @@ -267,24 +251,10 @@ default void activateSpell(GameController gameController) throws GameException {
} else if (playerGameBoard.isSpellAndTrapCardZoneFull() && spell.getAttribute() != SpellOrTrapAttribute.FIELD) {
throw new GameException(GameResponses.SPELL_ZONE_IS_FULL.response);
} else {
//todo activate spell
if(Cell.getSelectedCell().isEmpty()||Cell.getSelectedCell()==null){
System.out.println("error in activate effect");
}
SpellAndTrap.activateSpellEffects(gameController, spell);
// if(!playerGameBoard.isCellInSpellAndTrapZone(selectedCell)) {
// playerGameBoard.getHandCards().remove(selectedCell);
// if (spell.getAttribute() == SpellOrTrapAttribute.FIELD) {
// playerGameBoard.addCardToFieldZone(card);
// gameController.currentTurnOpponentPlayer.getGameBoard().addCardToFieldZone(card);
// } else {
// playerGameBoard.addCardToSpellAndTrapCardZone(card, CardStatus.OCCUPIED,gameController);
// }
// }
// else{
// selectedCell.setCardStatus(CardStatus.OCCUPIED);
// }
// Cell.deselectCell();
}
}
}
Expand All @@ -299,7 +269,6 @@ default void flipSummon(GameController gameController) throws GameException {
if (!currentPlayer.getGameBoard().isCellInMonsterZone(selectedCell)) {
throw new GameException(GameResponses.CAN_NOT_CHANGE_CARD_POSITION.response);
}
//todo ببینین ارور دوم رو درست هندل کردم: در همین دور تازه روی زمین گذاشته شده باشد
if (selectedCell.getCardStatus() != CardStatus.DEFENSIVE_HIDDEN || gameController.getChangedPositionCells().contains(selectedCell)) {
throw new GameException(GameResponses.CAN_NOT_FLIP_SUMMON.response);
}
Expand All @@ -316,11 +285,6 @@ default void specialSummon(GameController gameController) throws GameException {
Player currentPlayer = gameController.currentTurnPlayer;
Cell selectedCell = Cell.getSelectedCell();
while (true) {
// if (selectedCell == null) {
// throw new GameException(GameResponses.NO_CARDS_SELECTED.response);
// } else if (!isSummonable(selectedCell.getCellCard())) {
// throw new GameException(GameResponses.CANT_SUMMON_CARD.response);
// }
String input = ViewInterface.getInput();
if (!input.equals("summon")) {
ViewInterface.showResult(GameResponses.YOU_SHOULD_SPECIAL_SUMMON_NOW.response);
Expand Down Expand Up @@ -361,7 +325,6 @@ default String showGameBoard(Player currentPlayer, Player opponentPlayer) {
response += "\tc";
}
response += "\n" + opponentPlayerGameBoard.getDeckZone().size() + "\n";
response += "\t4\t2\t1\t3\t5\n";
int[] opponentCellNumbering = {3, 1, 0, 2, 4};
for (int i = 0; i < 5; i++) {
if (opponentPlayerGameBoard.getSpellAndTrapCardZone()[opponentCellNumbering[i]]
Expand Down Expand Up @@ -460,7 +423,6 @@ default String showGameBoard(Player currentPlayer, Player opponentPlayer) {
}
}
}
response += "\n\t5\t3\t1\t2\t4";
response += "\n\t\t\t\t\t\t" + playerGameBoard.getDeckZone().size() + "\n";
for (int i = 0; i < playerGameBoard.getHandCards().size(); i++) {
response += "c\t";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void increaseLP(int amount) {
setLP(this.getLP() + amount);
}

public GameBoard getGameBoard() {//better to rename to getPlayerGameBoard
public GameBoard getGameBoard() {
return playerGameBoard;
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void removeDeck(Deck deck) {

private void initializeCards() {
ArrayList<Card> initCards = new ArrayList<>();
//game init cards:

initCards.add(new AxeRaider());
initCards.add(new Babydragon());
initCards.add(new CallofTheHaunted());
Expand All @@ -208,12 +208,11 @@ private void initializeCards() {
initCards.add(new HarpiesFeatherDuster());
initCards.add(new MagicCylinder());
initCards.add(new MagicJamamer());
initCards.add(new MonsterReborn());
initCards.add(new SpiralSerpent());
initCards.add(new Mysticalspacetyphoon());
initCards.add(new SlotMachine());
initCards.add(new TorrentialTribute());

//other cards added by me (parham)

initCards.add(new BattleOX());
initCards.add(new BeastKingBarbaros());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/model/board/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Cell(Card card) {
}


public static void deselectCell() {//better to be same as select cell or rename
public static void deselectCell() {
selectedCell = null;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/model/cards/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public int compare(Card card1, Card card2) {
public static Card getNewCardObjectByName(String name) {

switch (name) {
//monsters:
case "Battle OX":
return new BattleOX();

Expand Down Expand Up @@ -220,7 +219,8 @@ public static Card getNewCardObjectByName(String name) {
case "Command Knight":
return new CommandKnight();

//spell and traps:


case "Trap Hole":
return new TrapHole();

Expand Down Expand Up @@ -383,4 +383,5 @@ public Kind getCardKind() {
}

public enum Kind {MONSTER, MAGIC}

}
5 changes: 2 additions & 3 deletions src/main/java/model/cards/Deck.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public void setActive(boolean active) {
}

public boolean isDeckValid() {
//TODO checkForEachCardFrequency
return true;
return mainDeck.size() >= 40;
}

public boolean isMainDeckFull() {
Expand Down Expand Up @@ -160,7 +159,7 @@ public String toString() {
}
}

public Deck clone() {//todo use this except reference
public Deck clone() {
Deck copiedDeck = new Deck(this.getName());
for (Card card : mainDeck) {
copiedDeck.addCardToMainDeck(card.clone());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/model/cards/justforscore/JustForScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class JustForScore {
// return monsterCardsDetailsList;
// }
//
// public static List<TrapAndSpellCardDetails> importTrapAndSpellsDetails() throws FileNotFoundException {//todo save the list in model
// public static List<TrapAndSpellCardDetails> importTrapAndSpellsDetails() throws FileNotFoundException {
// List<TrapAndSpellCardDetails> trapAndSpellCardDetailsList = new CsvToBeanBuilder(
// new FileReader("src/resources/cards details/SpellTrap.csv"))
// .withType(TrapAndSpellCardDetails.class).build().parse();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/model/cards/monsters/CommandKnight.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CommandKnight() {
, 2100, 1000, 1000, 4, MonsterAttribute.FIRE, MonsterType.WARRIOR, CardType.EFFECTIVE);
}

public static void handleEffect(CardStatus cardStatus, Cell cell) {//todo deactivate
public static void handleEffect(CardStatus cardStatus, Cell cell) {
if (cell == null || cell.isEmpty() || cardStatus != CardStatus.OFFENSIVE_OCCUPIED ||
!cell.getCellCard().getName().equals("Command Knight")) return;

Expand All @@ -47,7 +47,7 @@ public static void deActivateEffect(Cell cell) {
ViewInterface.showResult("Command Knight effect deActivated: all monsters atk will decrease 400");
try {
((CommandKnight) cell.getCellCard()).owner.getGameBoard().addAllMonstersATK(-400);
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/model/cards/monsters/GateGuardian.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static boolean handleEffect(GameController gameController) throws GameExc
GameBoard playerGameBoard = gameController.getCurrentTurnPlayer().getGameBoard();
Cell selectedCell = Cell.getSelectedCell();
if (!selectedCell.getCellCard().getName().equals("Gate Guardian")) return false;
//todo پنج تا مانستر برا یه هیولا D:
if (!playerGameBoard.doesMonsterZoneHaveMonsters(5) || !gameController.getMainPhase1Controller().canSpecialSummon(gameController)) {
throw new GameException(GameResponses.CAN_NOT_SET_OR_SUMMON.response);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/model/cards/trapandspells/MonsterReborn.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void setActivated(GameController gameController) {
playerGraveyardMonstersCell.remove(choice - 1);
try {
gameController.getMainPhase1Controller().specialSummon(gameController);
} catch (GameException e) {
} catch (GameException ignored) {
}
return;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/model/cards/trapandspells/TwinTwisters.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void setActivated(GameController gameController) {
}

Cell.setSelectedCell(oldSelectedCell);
updateSpellInGameBoard(gameController);//todo, conflict with AI
updateSpellInGameBoard(gameController);
}

private static boolean canActivate(GameController gameController) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/view/gamephases/Duel.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static void runGame(GameController gameController) {
break;
}
}
// showPhase();
AIPlayerController.recordGameLogs(gameController);
}
gameController.endGameRound();
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/view/gamephases/MainPhase1.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,6 @@ protected void execute() {
@Override
protected String processCommand(String command) {
String response = "";
//todo injaro badan azam beporsin tozih bedam bahaton check konam
/* if (gameController.shouldRitualSummonNow) {
if (command.matches(GameRegexes.SELECT.regex)) {
response = processSelect(command);
} else if (command.matches(GameRegexes.SUMMON.regex)) {
try {
mainPhase1Controller.ritualSummon(gameController);
response=GameResponses.SUMMONED_SUCCESSFULLY.response;
}catch (GameException e){
response=e.toString();
}
} else {
response = GameResponses.YOU_SHOULD_RITUAL_SUMMON_NOW.response;
}
}*/
if (command.equals("show attack")) {
System.out.println(((Monster) Cell.getSelectedCell().getCellCard()).getAtk());
} else if (command.equals("remove card"))
Expand Down Expand Up @@ -124,7 +108,6 @@ else if (gameController.checkCommandIsNotInCurrentPhase(command)) {
response = e.toString();
}
}
//todo check whether we have handled all methods in this phase or not
else if (command.matches(GameRegexes.SURRENDER.regex)) {
gameController.surrender();
} else if (command.matches(GameRegexes.INCREASE_LP.regex)) {
Expand Down
Loading

0 comments on commit 64c3e2e

Please sign in to comment.