Commit 75ff25f7 authored by soldier.mh.2001's avatar soldier.mh.2001
Browse files

Merge remote-tracking branch 'origin/main'

parents c38dac01 f2a9d651
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="project" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="f6e2b2ce-4ca9-4617-8f8b-40311e2222f4" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/server/src/main/java/MainServer.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/AllCardsInitiator.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/BattlePhase.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/Card.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/CardAndImage.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/CreateNewCard.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/Deck.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/DrawPhase.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/MainPhase.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/MonsterCard.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/MonsterPowers.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/MonstersDescriptions.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/Phase.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/Player.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/Round.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/Scoreboard.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/SpellCard.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/SpellEffects.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/SpellsDescription.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/TrapCard.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/TrapEffectMethods.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/TrapsDescription.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/User.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/Utilities.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/Attribute.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/MiniGame.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/MonsterCardPosition.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/MonsterPower.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/MonsterType.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/NumberOfRounds.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/PhaseName.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/RecentActionsInGame.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/SpellEffect.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/SpellIcon.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/SpellOrTrapCardPosition.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/Status.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/TrapEffect.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/TrapIcon.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/server/src/main/java/model/enums/Turn.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="1vRGFY2XK8yZIedXqtYrN9QPQns" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="f6e2b2ce-4ca9-4617-8f8b-40311e2222f4" name="Default Changelist" comment="" />
<created>1626517385009</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1626517385009</updated>
<workItem from="1626517386920" duration="17000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\Users\ten\IdeaProjects\BebinimChiMishe\server\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
Server
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="Server" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
\ No newline at end of file
This diff is collapsed.
package server.model;
import server.model.enums.MonsterCardPosition;
public class BattlePhase extends Phase {
public BattlePhase(Round round) {
super(round);
}
public int attackDirect(MonsterCard attackerCard){
Player rivalPlayer = getRivalPlayerByTurn();
int damageOfAttackingCard = attackerCard.getAttackPoint();
if(rivalPlayer.getLifePoint() < damageOfAttackingCard){
int attackDamage = rivalPlayer.getLifePoint();
rivalPlayer.setLifePoint(0);
return attackDamage;
}
rivalPlayer.decreaseLifePoint(damageOfAttackingCard);
attackerCard.setHasBattledInBattlePhase(true);
return damageOfAttackingCard;
}
public String attackToCardAndReturnAttackReport(int location, MonsterPowers powers, MonsterCard attackerCard){
MonsterCard defenderCard = getRivalPlayerByTurn().getMonsterCardsInZone().get(location);
if(defenderCard.getPosition() == MonsterCardPosition.OFFENSIVE_OCCUPIED){
attackerCard.setHasBattledInBattlePhase(true);
return attackToOffensiveOccupiedCardAndReturnReport(location, attackerCard, defenderCard, powers);
} else {
attackerCard.setHasBattledInBattlePhase(true);
return attackToDefensiveCardAndReturnReport(location, attackerCard, defenderCard, powers);
}
}
private String attackToDefensiveCardAndReturnReport(int location, MonsterCard attackerCard, MonsterCard defenderCard, MonsterPowers powers) {
int damage = attackerCard.getAttackPoint() - defenderCard.getDefencePoint();
if(damage > 0){
defenderCard.setGoingToGraveyard(true);
powers.run(defenderCard, attackerCard, 0);
getRivalPlayerByTurn().addCardToGraveyard(defenderCard);
getRivalPlayerByTurn().removeCardFromCardsInZone(defenderCard, location);
if(defenderCard.getPosition() == MonsterCardPosition.DEFENSIVE_HIDDEN){
defenderCard.setPosition(MonsterCardPosition.DEFENSIVE_OCCUPIED);
return "opponent’s monster card was " + defenderCard.getName() + " and the defense position monster is destroyed";
} else {
return "the defense position monster is destroyed";
}
} else if (damage == 0){
if(defenderCard.getPosition() == MonsterCardPosition.DEFENSIVE_HIDDEN){
defenderCard.setPosition(MonsterCardPosition.DEFENSIVE_OCCUPIED);
return "opponent’s monster card was " + defenderCard.getName() + " and no card is destroyed";
} else {
return "no card is destroyed";
}
} else {
getPlayerByTurn().decreaseLifePoint(-damage);
if(getPlayerByTurn().getLifePoint()<0){
getPlayerByTurn().setLifePoint(0);
}
if(defenderCard.getPosition() == MonsterCardPosition.DEFENSIVE_HIDDEN){
defenderCard.setPosition(MonsterCardPosition.DEFENSIVE_OCCUPIED);
return "opponent’s monster card was " + defenderCard.getName() + " and no card is destroyed and you received "
+ -damage + " battle damage";
} else {
return "no card is destroyed and you received " + -damage + " battle damage";
}
}
}
private String attackToOffensiveOccupiedCardAndReturnReport(int location, MonsterCard attackerCard, MonsterCard defenderCard, MonsterPowers powers) {
int damage = attackerCard.getAttackPoint() - defenderCard.getAttackPoint();
if(damage > 0){
getRivalPlayerByTurn().decreaseLifePoint(damage);
if(getRivalPlayerByTurn().getLifePoint()<0){
getRivalPlayerByTurn().setLifePoint(0);
}
defenderCard.setGoingToGraveyard(true);
powers.run(defenderCard, attackerCard, damage);
getRivalPlayerByTurn().addCardToGraveyard(defenderCard);
getRivalPlayerByTurn().removeCardFromCardsInZone(defenderCard, location);
return "your opponent’s monster is destroyed and your opponent receives " + damage + " battle damage";
} else if (damage == 0){
defenderCard.setGoingToGraveyard(true);
attackerCard.setGoingToGraveyard(true);
attackerCard.setGoingToGraveyardWithItsOwnAttack(true);
powers.run(defenderCard, attackerCard, 0);
powers.run(attackerCard, defenderCard, 0);
getPlayerByTurn().addCardToGraveyard(attackerCard);
getPlayerByTurn().removeCardFromCardsInZone(attackerCard, getPlayerByTurn().getLocationOfThisMonsterCardInZone(attackerCard));
getRivalPlayerByTurn().addCardToGraveyard(defenderCard);
getRivalPlayerByTurn().removeCardFromCardsInZone(defenderCard, location);
return "both you and your opponent monster cards are destroyed and no one receives damage";
} else {
getPlayerByTurn().decreaseLifePoint(-damage);
if(getPlayerByTurn().getLifePoint()<0){
getPlayerByTurn().setLifePoint(0);
}
attackerCard.setGoingToGraveyardWithItsOwnAttack(true);
attackerCard.setGoingToGraveyard(true);
powers.run(attackerCard, defenderCard, damage);
getPlayerByTurn().addCardToGraveyard(attackerCard);
getPlayerByTurn().removeCardFromCardsInZone(attackerCard, getPlayerByTurn().getLocationOfThisMonsterCardInZone(attackerCard));
return "Your monster card is destroyed and you received " + -damage + " battle damage";
}
}
}
package server.model;
import com.google.gson.annotations.Expose;
import javafx.scene.image.Image;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public abstract class Card {
@Expose
protected String name;
@Expose
protected String number;
@Expose
protected String description;
@Expose
protected boolean isGoingToGraveyard = false;
@Expose
protected String ownerUsername;
@Expose
protected int price;
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
protected int classID;
private static ArrayList<CardAndImage> cardsAndImages = new ArrayList<>();
private static HashMap<String, Integer> prices = new HashMap<>();
private static ArrayList<Card> allCards = new ArrayList<>();
public static ArrayList<CardAndImage> getCardsAndImages() {
cardsAndImages.sort((o1, o2) -> Utilities.compareAlphabetical(o1.getCardName(), o2.getCardName()));
return cardsAndImages;
}
public Card(String ownerUsername, String name, String number, String description) {
setOwnerUsername(ownerUsername);
setName(name);
setDescription(description);
setNumber(number);
}
public Card() {
}
public static Image getCardImageByName(String cardName){
for (CardAndImage cardAndImage : cardsAndImages) {
if(cardAndImage.getCardName().equals(cardName)){
return cardAndImage.getImage();
}
}
try {
Card card = Card.getCardByName(allCards, cardName);
if(card instanceof MonsterCard){
return new Image(Card.class.getResource("/cards/Monsters/newMonster.jpg").toExternalForm());
} else if (card instanceof SpellCard){
return new Image(Card.class.getResource("/cards/SpellTrap/newSpell.jpg").toExternalForm());
} else {
return new Image(Card.class.getResource("/cards/SpellTrap/newTrap.jpg").toExternalForm());
}
} catch (Exception e){
e.printStackTrace();
return null;
}
}
public static String getCardNameByImage(Image image){
for (CardAndImage cardAndImage : cardsAndImages) {
if(cardAndImage.getImage().equals(image)){
return cardAndImage.getCardName();
}
}
return null;
}
public static HashMap<String, Integer> getPrices() {
return prices;
}
public abstract Object clone() throws CloneNotSupportedException;
public abstract String toString();
public static String cardsArrayListToString(ArrayList<Card> cards) {
ArrayList<Card> monsterCards = new ArrayList<>();
ArrayList<Card> spellAndTrapCards = new ArrayList<>();
divideCardsByType(cards, monsterCards, spellAndTrapCards);
sortCardsWithName(monsterCards);
sortCardsWithName(spellAndTrapCards);
StringBuilder cardsToStringBuilder = new StringBuilder("Monsters:\n");
for (Card monsterCard : monsterCards) {
cardsToStringBuilder.append(monsterCard.getName());
cardsToStringBuilder.append(": ");
cardsToStringBuilder.append(monsterCard.getDescription());
cardsToStringBuilder.append("\n");
}
cardsToStringBuilder.append("Spells and Traps:\n");
for (Card spellAndTrapCard : spellAndTrapCards) {
cardsToStringBuilder.append(spellAndTrapCard.getName());
cardsToStringBuilder.append(": ");
cardsToStringBuilder.append(spellAndTrapCard.getDescription());
cardsToStringBuilder.append("\n");
}
return cardsToStringBuilder.toString();
}
private static void divideCardsByType(ArrayList<Card> cards, ArrayList<Card> monsterCards,
ArrayList<Card> spellAndTrapCards) {
for (Card card : cards) {
if (card instanceof MonsterCard) {
monsterCards.add(card);
} else if (card instanceof SpellCard || card instanceof TrapCard) {
spellAndTrapCards.add(card);
}
}
}
private static void sortCardsWithName(ArrayList<Card> cards) {
for (int i = 0; i < cards.size(); i++) {
for (int j = 0; j < cards.size() - 1; j++) {
if (Utilities.compareAlphabetical(cards.get(j).getName(), cards.get(j + 1).getName()) > 0) {
Collections.swap(cards, j, j + 1);
}
}
}
}
public static void sortCardsWithImage(ArrayList<Card> cardsToAdd) {
cardsToAdd.sort((o1, o2) -> {
int classCompare = o1.getClassID() - o2.getClassID();
if(classCompare != 0){
return -classCompare;
} else {
return o1.getName().compareTo(o2.getName());
}
});
}
public static ArrayList<Card> getAllCards() {
return allCards;
}
public static void addToAllCards(Card card) {
Card.allCards.add(card);
}
public static boolean isThisCardNameValid(String cardName) {
for (Card card : Card.getAllCards()) {
if (card.getName().equals(cardName)) {
return true;
}
}
return false;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public boolean isGoingToGraveyard() {
return isGoingToGraveyard;
}
public void setGoingToGraveyard(boolean goingToGraveyard) {
isGoingToGraveyard = goingToGraveyard;
}
public String getOwnerUsername() {
return ownerUsername;
}
public void setOwnerUsername(String ownerUsername) {
this.ownerUsername = ownerUsername;
}
public int getClassID() {
return classID;
}
public static Card getCardByName(ArrayList<Card> cards, String name) throws CloneNotSupportedException {
for (Card card : cards) {
if (card.getName().equals(name)) {
return (Card) card.clone();
}
}
return null;
}
}
package server.model;
import javafx.scene.image.Image;
public class CardAndImage {
private String cardName;
private Image image;
public CardAndImage(Image image, String cardName){
this.cardName = cardName;
this.image = image;
}
public String getCardName() {
return cardName;
}
public void setCardName(String cardName) {
this.cardName = cardName;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
}
package server.model;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.controller.CreateNewCardController;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
public class CreateNewCard {
private CreateNewCardController controller;
public CreateNewCard(CreateNewCardController controller) {
this.controller = controller;
}
public static ArrayList<MonsterCard> newMonsters = new ArrayList<>();
public static ArrayList<SpellCard> newSpells = new ArrayList<>();
public static ArrayList<TrapCard> newTraps = new ArrayList<>();
public static ArrayList<Card> newCards = new ArrayList<>();
public static void serialize() {
try (Writer writer = new FileWriter("src/NewMonsterOutput.json")) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
gson.toJson(CreateNewCard.newMonsters, writer);
} catch (IOException e) {
e.printStackTrace();
}
try (Writer writer = new FileWriter("src/NewTrapOutput.json")) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
gson.toJson(CreateNewCard.newTraps, writer);
} catch (IOException e) {
e.printStackTrace();
}
try (Writer writer = new FileWriter("src/NewSpellOutput.json")) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
gson.toJson(CreateNewCard.newSpells, writer);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void deserialize() {
Gson gson = new Gson();
Reader reader = null;
try {
reader = Files.newBufferedReader(Paths.get("src/NewMonsterOutput.json"));
} catch (IOException e) {
e.printStackTrace();
}
MonsterCard[] monsterCards = gson.fromJson(reader, MonsterCard[].class);