diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bc5b7e3..0000000 --- a/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -# Created by .ignore support plugin (hsz.mobi) -### Java template -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar -.idea -project-27.iml - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -/out/ -/src/gson/ diff --git a/README.md b/README.md deleted file mode 100644 index dc64942..0000000 --- a/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# project-27 -# project-27 -amir mohammad mohammadi 97107126 -Ali Ghasemi 97106205 -Mohammad Namdar 97106302 diff --git a/src/Moudle/Account.Java b/src/Moudle/Account.Java index f3d9dc1..5273d93 100644 --- a/src/Moudle/Account.Java +++ b/src/Moudle/Account.Java @@ -1,154 +1,136 @@ package Moudle; -import Controller.ControlBox; - import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Account { - private static ArrayList accounts; - private String username; - private String password; + private static ArrayList accounts = new ArrayList<>(); + private String userName; + private String passWord; private Collection collection; private int money; private ArrayList decks; private Deck mainDeck; private int wins; private int losses; - private static int inputType; //0:nothing's happened, 1:username's been added, 2:password's been added - - public static void input(ControlBox controlBox) { - int input = inputType; - if (controlBox.getType().equals("createAccount")) { - if(input == 1){ - if(input == 2){ - - } - } - } + public String getUserName() { + return userName; } - public boolean isValidDeck() { - return false; + public void setUserName(String userName) { + this.userName = userName; } - public String getUsername() { - return username; + public Collection getCollection() { + return collection; } - public void setCollection(Collection collection) { - this.collection = collection; + public int getMoney() { + return money; } public void setMoney(int money) { this.money = money; } - public void addDeck(Deck deck) { - this.decks.add(deck); + public void addMoney(int money) { + this.money += money; } - public void setMainDeck(Deck deck) { - this.mainDeck = deck; + public void spendMoney(int money) { + this.money -= money; } - public Collection getCollection() { - return collection; + public ArrayList getDecks() { + return decks; } - public int getMoney() { - return money; - } - public void spendMoney(int price) { - money -= price; + public Deck getMainDeck() { + return mainDeck; } - public void addMoney(int price) { - money += price; + public void setMainDeck(Deck mainDeck) { + this.mainDeck = mainDeck; } - public ArrayList getDecks() { - return decks; + public int getWins() { + return wins; } - public Deck getMainDeck() { - return mainDeck; + public int getLosses() { + return losses; } - public static void createAccount(String username) { - Scanner scanner = new Scanner(System.in); - int accountFounded = 0; - for (int i = 0; i < accounts.size(); i++) { - if (accounts.get(i).username.equals(username)) { - accountFounded = 1; + public static Account findAccount(String userName) { + if (accounts.size() == 0) { + return null; + } else { + for (int i = 0; i < accounts.size(); i++) { + if (accounts.get(i).userName.equals(userName)) { + return accounts.get(i); + } } } - if (accountFounded == 1) { - System.out.println("This user has already been created!"); + return null; + } + + public static void createAccount(String userName) { + if (findAccount(userName) != null) { + System.out.println("There is an account with this userName!"); } else { - String password = scanner.next(); + Scanner scanner = new Scanner(System.in); + String passWord = scanner.next(); Account account = new Account(); - account.username = username; - account.password = password; + account.userName = userName; + account.passWord = passWord; accounts.add(account); + System.out.println("created"); } + } - public static void login(String username) { - Scanner scanner = new Scanner(System.in); - int accountFounded = 0; - for (int i = 0; i < accounts.size(); i++) { - if (accounts.get(i).username.equals(username)) { - accountFounded = 1; - } - } - if (accountFounded == 0) { - System.out.println("There is no such username!"); + public boolean login(String userName) { + if (findAccount(userName) == null) { + System.out.println("There is no account with this userName!"); + return false; } else { - String password = scanner.next(); - for (int i = 0; i < accounts.size(); i++) { - if (accounts.get(i).password.equals(password)) { - - } else { - System.out.println("Wrong password!"); - } + Scanner scanner = new Scanner(System.in); + String passWord = scanner.next(); + if (passWord.equals(findAccount(userName).passWord)) { + + return true; + } else { + System.out.println("Wrong passWord!"); + return false; } } } - public void logout() { - - } - - public static void save() { - - } - - public void increaseWins() { - wins++; - } - - public void increaseLosses() { - losses++; - } - public static void showLeaderBoard() { for (int i = 0; i < accounts.size(); i++) { for (int j = i + 1; j < accounts.size(); j++) { - if (accounts.get(i).wins < accounts.get(j).wins) { + if (accounts.get(j).wins > accounts.get(i).wins) { Collections.swap(accounts, i, j); } } } for (int i = 0; i < accounts.size(); i++) { - System.out.println(i + "-" + "UserName" + ":" + accounts.get(i).username + "-" + "Wins" + ":" + accounts.get(i).wins); + System.out.printf("%d-UserName : %s-Wins : %d\n", i + 1, accounts.get(i).userName, accounts.get(i).wins); } } - public void help() { - System.out.println("create account [user name]\nlogin [user name]\nshow leaderboard\nsave\nlogout\n"); + public static void save() { + + } + + public static void logout() { + + } + + public static void help() { + System.out.print("create account [user name}\nlogin [user name]\nshow leaderboard\nsave\nlogout\nhelp\n"); } -} \ No newline at end of file +} diff --git a/src/Moudle/Battle.java b/src/Moudle/Battle.java index b71398a..5b4c7fd 100644 --- a/src/Moudle/Battle.java +++ b/src/Moudle/Battle.java @@ -1,430 +1,170 @@ package Moudle; -import Controller.ControlBox; -import View.View; - import java.util.ArrayList; public class Battle { - private static Battle currentBattle; - private Fighter selectedFighter; - private ArrayList minionAndHeroes = new ArrayList<> ( ); - private Ground ground; - private int currentTurn; - private Player player1; - private Player player2; - private Player playerInTurn; - private ArrayList fighters; - private Card selectedCard; - private Item selectedItem; - private int battleType; - private ArrayList flags; - private int numberOfFlags; - private Item mainFlag; - private Fighter heroP1; - private Fighter heroP2; - private ArrayList buffs = new ArrayList<> ( ); - - public Ground getGround () { - return ground; - } - - public static void input ( ControlBox controllBox ) { - String in = controllBox.getType ( ); - if ( in.equals ( "game info" ) ) { - currentBattle.showInfo ( ); - return; - } - if ( in.equals ( "show my minions" ) ) { - currentBattle.playerInTurn.showFighters ( ); - } - if ( in.equals ( "show my opponent minions" ) ) { - currentBattle.offTurn ( ).showFighters ( ); - } - if ( in.equals ( "show card info" ) ) { - currentBattle.showCardInfo ( controllBox.getCardID ( ) ); - } - if ( in.equals ( "select card" ) ) { - currentBattle.setInGroundCard ( controllBox.getCardID ( ) ); - } - if ( in.equals ( "end turn" ) ) { - currentBattle.nextTurn ( ); - } - if ( in.equals ( "use special power" ) ) { - //todo - } - if ( in.equals ( "show hand" ) ) { - //todo - - } - if ( in.equals ( "insert" ) ) { - currentBattle.insert ( controllBox.getCardName ( ) , controllBox.getX ( ) , controllBox.getY ( ) ); - } - if ( in.equals ( "move" ) ) { - currentBattle.move ( currentBattle.selectedFighter.getX ( ) , currentBattle.selectedFighter.getY ( ) - , controllBox.getX ( ) , controllBox.getY ( ) ); - } - if ( in.equals ( "attack" ) ) { - Fighter opponent = currentBattle.findFighter ( controllBox.getCardID ( ) , currentBattle.offTurn ( ) ); - if ( opponent == null ) { - //fosh - return; - } - currentBattle.attack ( currentBattle.selectedFighter , opponent ); - } - } - - private void setInGroundCard ( String cardID ) { - Fighter fighter = findFighter ( cardID , playerInTurn ); - if ( fighter == null ) { - //fosh - } else { - selectedFighter = fighter; - //accept; - } - } - private void showHand(){ - playerInTurn.showHand (); - } - private Fighter findFighter ( String cardID ) { - for ( Fighter fighter : fighters ) { - if ( fighter.getID ( ).equals ( cardID ) ) { - return fighter; - } - } - return null; - } - - private Fighter findFighter ( String cardID , Player player ) { - for ( Fighter fighter : player.getFighters ( ) ) { - if ( fighter.getID ( ).equals ( cardID ) ) - return fighter; - } - return null; - } - - private void showCardInfo ( String cardID ) { - Fighter fighter = findFighter ( cardID ); - if ( fighter == null ) { - //fosh - return; - } - View.showFighter ( fighter ); - } - - private Player offTurn () { - if ( player1 == playerInTurn ) - return player2; - return player1; - } - private boolean isValidInsert(Card card){ - if ( card.getManaPrice ()<=playerInTurn.getMana () ){ - playerInTurn.decreaseMana ( card.getManaPrice () ); - return true; - } - return false; - } - public void insert ( String cardName , int x , int y ) { - Card card = null;//todo cardName ali - if ( isValidInsert ( card ) ){ - //fosh - return; - } - int type = card.getCardType ( ); - if ( type == 0 ) { - Spell spell = ( Spell ) card; - if ( ! spell.getTarget ( ).isValidTarget ( this , x , y , playerInTurn ) ) { - System.out.println ( "invalid target" ); - return; - } - ArrayList fighters = spell.getTarget ( ).targetFighters ( this , x , y , playerInTurn ); - for ( Buff buff : spell.getMainBuffs ( ) ) { - buff ( buff , fighters , x , y ); - } - for ( Buff buff : spell.getBuffs ( ) ) { - buff ( buff , fighters , x , y ); - buffs.add ( buff ); - } - } - if ( type == 1 ) { - MinionAndHero minionAndHero = ( MinionAndHero ) card; - if ( ! isValidNewFighter ( minionAndHero , playerInTurn , x , y ) ) { - //fosh - return; - } - if ( ground.getCell ( x , y ).getCardOnCell ( ) != null ) { - //fosh - return; - } - if ( ground.getCell ( x , y ).getItemOnCell ( ) != null ) { - playerInTurn.addItem ( ground.getCell ( x , y ).getItemOnCell ( ) ); - } - minionAndHeroes.add ( minionAndHero ); - Fighter fighter = new Fighter ( minionAndHero , minionAndHeroes , playerInTurn ); - executeOnSpawnBuff ( fighter ); - ground.getCell ( x , y ).moveInCell ( fighter ); - fighter.setLocation ( x , y ); - } - } - - public void attack ( Fighter fighter , Fighter opponent ) { - int targetX = opponent.getX ( ); - int targetY = opponent.getY ( ); - if ( ! isValidDistanceForAttack ( ) ) { - //fosh - return; - } - if ( ! fighter.CanAttack ( ) ) { - //fosh - return; - } - fighter.disableCanAttack ( ); - fighter.disableCanMove ( ); - opponent.decreaseHP ( fighter.getAP ( ) - opponent.getHolyDefence ( ) ); - if ( opponent.isCanCounterAttack ( ) ) { - fighter.decreaseHP ( opponent.getAP ( ) - fighter.getHolyDefence ( ) ); - } - fighter.addAttackedFighter ( opponent ); - executeOnAttackAndDeBuff ( fighter , opponent ); - isDeath ( opponent ); - isDeath ( fighter ); - } - - private void executeOnAttackAndDeBuff ( Fighter offenser , Fighter defender ) { - if ( offenser.getSpecialPowerType ()==3 ){ - Fighter target = null; - if ( offenser.getSpecialPowerTarget ().getTargetType ()==7 ){ - target = defender; - } - else if(offenser.getSpecialPowerTarget ().getTargetType () == 8) - target = offenser; - for ( Buff buff:offenser.getSpecialPowers () ){ - if ( buff.getPlusDamageToAttacked ()>0 ){ - defender.decreaseHP ( buff.getPlusDamageToAttacked ()*offenser.howManyAttacked ( defender ) ); - } - if ( buff.noHolynessForOpponent () ){ - defender.decreaseHP ( defender.getHolyDefence () ); - } - target.addToBuff ( buff ); - if ( buff.isExeptABuff () ){ - buffs.add ( buff ); - } - } - } - if ( defender.getSpecialPowerType ()==4 ){ - Fighter target = null; - if ( defender.getSpecialPowerTarget ().getTargetType ()==7 ){ - target = offenser; - } - else if ( defender.getSpecialPowerTarget ().getTargetType ()==7 ){ - target = defender; - } - for ( Buff buff:offenser.getSpecialPowers () ){ - defender.addToBuff ( buff ); - if ( buff.isExeptABuff () ){ - buffs.add ( buff ); - } - } - } - } - - private void executeOnSpawnBuff ( Fighter fighter ) { - if ( fighter.getSpecialPowerType ()!=0 ) - return; - executeSpecialBuffs ( fighter ); - } - - private void executeOnDeathBuff ( Fighter fighter ) { - if ( fighter.getSpecialPowerType ()!=2 ) - return; - executeSpecialBuffs ( fighter ); - } - - private void executeSpecialBuffs ( Fighter fighter ) { - for ( Buff buff : fighter.getSpecialPowers ( ) ) { - ArrayList targets = fighter.getSpecialPowerTarget ( ). - targetFighters ( this , fighter.getX ( ) , fighter.getY ( ) , playerInTurn ); - buff ( buff , targets , fighter.getX ( ) , fighter.getY ( ) ); - } - } - - private boolean isDeath ( Fighter fighter ) { - if ( fighter.getHP ( ) < 1 ) { - ground.getCell ( fighter.getX ( ) , fighter.getY ( ) ).moveFromCell ( ); - executeOnDeathBuff ( fighter ); - if ( fighter.isHero () ){ - if ( fighter.getPlayer ()==player1 ) - winner ( player2 ); - winner ( player1 ); - return true; - } - return true; - } - return false; - } - - private boolean isValidDistanceForAttack () { - //todo - return true; - } - - private Fighter isValidTargetForAttack ( int targetX , int targetY ) { - Fighter fighter; - fighter = ( Fighter ) ground.getCell ( targetX , targetY ).getCardOnCell ( ); - if ( fighter.getPlayer ( ) == playerInTurn ) - return null; - return fighter; - } - - private boolean isValidNewFighter ( MinionAndHero minionAndHero , Player player , int x , int y ) { - return true; - } - - private void buff ( Buff buff , ArrayList fighters , int x , int y ) { - if ( buff.getIsCellBuff ( ) ) { - ground.getCell ( x , y ).addCellEffect ( buff.getCellBuff ( ) ); - - } else { - buff.setFighters ( fighters ); - for ( Fighter fighter : fighters ) { - fighter.addToBuff ( buff ); - } - } - } - - private boolean isValidMove ( int x1 , int y1 , int x2 , int y2 ) { - if ( Ground.getDistance ( x1 , y1 , x2 , y2 ) > 2 ) - return false; - if ( ground.getCell ( x2 , y2 ).getCardOnCell ( ) != null ) { - //fosh - return false; - } - if ( Ground.getDistance ( x1 , y1 , x2 , y2 ) == 2 ) { - if ( x1 == x2 ) { - if ( y1 > y2 ) { - if ( ground.getCell ( x1 , y1 - 1 ).getCardOnCell ( ) != null || ground.getCell ( x1 , y1 - 2 ).getCardOnCell ( ) != null ) { - //fosh - return false; - } - } - if ( y2 > y1 ) { - if ( ground.getCell ( x1 , y1 + 1 ).getCardOnCell ( ) != null || ground.getCell ( x1 , y1 + 2 ).getCardOnCell ( ) != null ) { - //fosh - return false; - } - } - } - else if ( y1 == y2 ) { - if ( x1 > x2 ) { - if ( ground.getCell ( x1-1 , y1 ).getCardOnCell ( ) != null || ground.getCell ( x1-2 , y1 ).getCardOnCell ( ) != null ) { - //fosh - return false; - } - } - if ( x2 > x1 ) { - if ( ground.getCell ( x1+1 , y1 ).getCardOnCell ( ) != null || ground.getCell ( x1+2 , y1 ).getCardOnCell ( ) != null ) { - //fosh - return false; - } - } - } - else{ - // TODO: 5/5/2019 - } - } - return true; - } - - private boolean isValidSelect () { - return true; - } - - public void checkWinner () { - } - - public void setMana () { - - } - - public Battle ( Player player1 , Player player2 , int battleType ) { - - } - - private void move ( int targetX , int targetY , int x , int y ) { - if ( ! isValidMove ( targetX , targetY , x , y ) ) { - //fosh - return; - } - if ( ! isValidTargetForMove ( targetX , targetY ) ) { - //fosh - return; - } - Fighter fighter = ( Fighter ) this.ground.getCell ( x , y ).getCardOnCell ( ); - if ( fighter.isCanMove ( ) ) { - //fosh - return; - } - if ( ground.getCell ( targetX , targetY ).getItemOnCell ( ) != null ) { - playerInTurn.addItem ( ground.getCell ( targetX , targetY ).getItemOnCell ( ) ); - } - ground.getCell ( x , y ).moveInCell ( fighter ); - ground.getCell ( targetX , targetY ).moveFromCell ( ); - } - - private boolean isValidTargetForMove ( int x , int y ) { - Fighter fighter = ( Fighter ) this.ground.getCell ( x , y ).getCardOnCell ( ); - if ( fighter.getPlayer ( ).equals ( this.playerInTurn ) ) { - return true; - } - return false; - } - - private void checkBuffs () { - for ( Buff buff : buffs ) { - if ( buff.getAgeType ( ) == 1 ) { - if ( buff.getAge ( ) < 1 ) { - removeBuff ( buff ); - } else buff.decreesAge ( ); - } - if ( buff.getAgeType ()==3 ){ - if ( buff.getAge ()<1 ){ - for ( Fighter fighter:buff.getFighters () ){ - fighter.addToBuff ( buff ); - } - } - } - } - } - - private void removeBuff ( Buff buff ) { - if ( buff.getIsCellBuff ( ) ) { - - } else { - for ( Fighter fighter : buff.getFighters ( ) ) { - fighter.removeFromBuff ( buff ); - } - } - } - - public void nextTurn () { - for ( Fighter fighter : fighters ) { - fighter.preTurnProcces ( ); - } - checkBuffs (); - currentTurn++; - setMana ( ); - setPlayerInTurn ( ); - } - - public void showInfo () { - - } - private void winner(Player player){ - - } - private void setPlayerInTurn () { - if ( playerInTurn.equals ( player1 ) ) - playerInTurn = player2; - playerInTurn = player1; - } + private static Battle currentBattle; + private Fighter selectedFighter; + private ArrayList minionAndHeroes; + private Ground ground; + private int currentTurn; + private Player player1; + private Player player2; + private Player playerInTurn; + private ArrayList fighters; + private Card selectedCard; + private Item selectedItem; + private int battleType; + private ArrayList flags; + private int numberOfFlags; + private Item mainFlag; + private Fighter heroP1; + private Fighter heroP2; + private ArrayList buffs; + + public static Battle getCurrentBattle() { + return currentBattle; + } + + public static void setCurrentBattle(Battle currentBattle) { + Battle.currentBattle = currentBattle; + } + + public Fighter getSelectedFighter() { + return selectedFighter; + } + + public void setSelectedFighter(Fighter selectedFighter) { + this.selectedFighter = selectedFighter; + } + + public ArrayList getMinionAndHeroes() { + return minionAndHeroes; + } + + public void setMinionAndHeroes(ArrayList minionAndHeroes) { + this.minionAndHeroes = minionAndHeroes; + } + + public Ground getGround() { + return ground; + } + + public void setGround(Ground ground) { + this.ground = ground; + } + + public int getCurrentTurn() { + return currentTurn; + } + + public void setCurrentTurn(int currentTurn) { + this.currentTurn = currentTurn; + } + + public Player getPlayer1() { + return player1; + } + + public void setPlayer1(Player player1) { + this.player1 = player1; + } + + public Player getPlayer2() { + return player2; + } + + public void setPlayer2(Player player2) { + this.player2 = player2; + } + + public Player getPlayerInTurn() { + return playerInTurn; + } + + public void setPlayerInTurn(Player playerInTurn) { + this.playerInTurn = playerInTurn; + } + + public ArrayList getFighters() { + return fighters; + } + + public void setFighters(ArrayList fighters) { + this.fighters = fighters; + } + + public Card getSelectedCard() { + return selectedCard; + } + + public void setSelectedCard(Card selectedCard) { + this.selectedCard = selectedCard; + } + + public Item getSelectedItem() { + return selectedItem; + } + + public void setSelectedItem(Item selectedItem) { + this.selectedItem = selectedItem; + } + + public int getBattleType() { + return battleType; + } + + public void setBattleType(int battleType) { + this.battleType = battleType; + } + + public ArrayList getFlags() { + return flags; + } + + public void setFlags(ArrayList flags) { + this.flags = flags; + } + + public int getNumberOfFlags() { + return numberOfFlags; + } + + public void setNumberOfFlags(int numberOfFlags) { + this.numberOfFlags = numberOfFlags; + } + + public Item getMainFlag() { + return mainFlag; + } + + public void setMainFlag(Item mainFlag) { + this.mainFlag = mainFlag; + } + + public Fighter getHeroP1() { + return heroP1; + } + + public void setHeroP1(Fighter heroP1) { + this.heroP1 = heroP1; + } + + public Fighter getHeroP2() { + return heroP2; + } + + public void setHeroP2(Fighter heroP2) { + this.heroP2 = heroP2; + } + + public ArrayList getBuffs() { + return buffs; + } + + public void setBuffs(ArrayList buffs) { + this.buffs = buffs; + } + + } diff --git a/src/Moudle/Buff.java b/src/Moudle/Buff.java index a812e79..dd9c518 100644 --- a/src/Moudle/Buff.java +++ b/src/Moudle/Buff.java @@ -3,96 +3,79 @@ import java.util.ArrayList; public class Buff { - private String name; - private boolean exeptABuff; - private ArrayList fighters; - private int cellX,cellY; - private boolean isCellBuff; - private boolean isPositive; - private int changeAP; - private int changeHP; - private int changeHollynes; - private boolean noHolynessForOpponent; - private int changeOpponentHolyness; - //boolean change int: 0:nothing 1:true 2:false 3:not - private int changeCanMove; - private int changeCanAttack; - private int changeCanCounterAttack; - private boolean disablePositiveBuffs; - private boolean disableNegativeBuffs; - private int plusDamageToAttacked; - //age type:0:unlimited 2:long age 3:execute when age is zero - private int ageType; - private int age; - private Buff cellBuff; - public void setCellXY(int x,int y){ - cellX=x; - cellY=y; - } - - public boolean isDisableNegativeBuffs () { - return disableNegativeBuffs; - } - - public boolean isDisablePositiveBuffs () { - return disablePositiveBuffs; - } - - public boolean noHolynessForOpponent(){ - return noHolynessForOpponent; - } - public boolean isPositive () { - return isPositive; - } - - public int getPlusDamageToAttacked () { - return plusDamageToAttacked; - } - - public boolean isExeptABuff () { - return exeptABuff; - } - - public int getAge () { - return age; - } - public boolean getIsCellBuff(){ - return isCellBuff; - } - public Buff getCellBuff () { - return cellBuff; - } - - public void setFighters ( ArrayList fighters ) { - this.fighters = fighters; - } - public void decreesAge(){ - age--; - } - public ArrayList getFighters () { - return fighters; - } - - public int getAgeType () { - return ageType; - } - - public int getChangeHollynes () { - return changeHollynes; - } - public int getChangeHP () { - return changeHP; - } - public int getChangeAP () { - return changeAP; - } - public int getChangeCanMove () { - return changeCanMove; - } - public int getChangeCanCounterAttack () { - return changeCanCounterAttack; - } - public int getChangeCanAttack () { - return changeCanAttack; - } + private String name; + private ArrayList fighters; + private int cellX, cellY; + private boolean isCellBuff; + private boolean isPositive; + private int changeAP; + private int changeHP; + private int changeHollynes; + //boolean change int: 0:nothing 1:true 2:false 3:not + private int changeCanMove; + private int changeCanAttack; + private int changeCanCounterAttack; + private boolean disableEnemyPositiveBuffs; + private boolean disablePlayerNegativeBuffs; + //age type:0:unlimited 2:long age + private int ageType; + private int age; + private Buff cellBuff; + + public void setCellXY(int x, int y) { + cellX = x; + cellY = y; + } + + public int getAge() { + return age; + } + + public boolean getIsCellBuff() { + return isCellBuff; + } + + public Buff getCellBuff() { + return cellBuff; + } + + public void setFighters(ArrayList fighters) { + this.fighters = fighters; + } + + public void decreesAge() { + age--; + } + + public ArrayList getFighters() { + return fighters; + } + + public int getAgeType() { + return ageType; + } + + public int getChangeHollynes() { + return changeHollynes; + } + + public int getChangeHP() { + return changeHP; + } + + public int getChangeAP() { + return changeAP; + } + + public int getChangeCanMove() { + return changeCanMove; + } + + public int getChangeCanCounterAttack() { + return changeCanCounterAttack; + } + + public int getChangeCanAttack() { + return changeCanAttack; + } } diff --git a/src/Moudle/Card.Java b/src/Moudle/Card.Java index 621c145..17e8442 100644 --- a/src/Moudle/Card.Java +++ b/src/Moudle/Card.Java @@ -1,90 +1,77 @@ package Moudle; -import View.View; import java.util.ArrayList; + public abstract class Card { - private static ArrayList cards = new ArrayList<>(); + private static ArrayList cards; private String name; private int cardID; private int shopPrice; private int manaPrice; - //0:spell 1:minion - private int cardType; + private int cardType;//0:spell 1:minion 2:hero - public int getCardType () { - return cardType; - } - - public int getManaPrice () { - return manaPrice; - } - public void showCard (){ - if ( this.getCardType ()==1 ){ - View.showFighter ( ( Fighter ) this ); - } - if(this.getCardType ()==0){ - View.showSpell ( ( Spell ) this ); - } - } - protected Card( String name, int shopPrice, int manaPrice, int cardType) { + protected Card(String name, int shopPrice, int manaPrice, int cardType) { this.name = name; this.shopPrice = shopPrice; this.manaPrice = manaPrice; - this.cardType= cardType; + this.cardType = cardType; cards.add(this); } + + public static ArrayList getCards() { + return cards; + } + + public static void setCards(ArrayList cards) { + Card.cards = cards; + } + public String getName() { return name; } + + public void setName(String name) { + this.name = name; + } + + public int getCardID() { + return cardID; + } + + public void setCardID(int cardID) { + this.cardID = cardID; + } + public int getShopPrice() { return shopPrice; } - public static void showCardInfo(int cardID) { - Card card = findCard(cardID); - printCardInfo(card); - } - public static void showCardInfo(int cardID, ArrayList cards) { - Card card = findCard(cardID, cards); - printCardInfo(card); + + public void setShopPrice(int shopPrice) { + this.shopPrice = shopPrice; } - private static void printCardInfo(Card card) { - if (card == null) { - System.out.println("there is no card with this ID"); - return; - } - System.out.println("name: " + card.name); - System.out.println("cardID: " + card.cardID); - System.out.println("price: " + card.shopPrice + " derick"); - System.out.println("mana price: " + card.manaPrice); + + public int getManaPrice() { + return manaPrice; } - public static Card findCard(int cardID) { - for (Card card : cards) { - if (card.cardID == cardID) - return card; - } - return null; + + public void setManaPrice(int manaPrice) { + this.manaPrice = manaPrice; } - public static Card findCard(String name) { - for (Card card : cards) { - if (card.name.equals(name)) - return card; - } - return null; + + public int getCardType() { + return cardType; } - public static Card findCard(String name, ArrayList cards) { - for (Card card : cards) { - if (card.name.equals(name)) - return card; - } - return null; + public void setCardType(int cardType) { + this.cardType = cardType; } - public static Card findCard(int cardID, ArrayList cards) { - for (Card card : cards) { - if (card.cardID == cardID) - return card; + public static Card findCard(String name) { + for (int i = 0; i < cards.size(); i++) { + if (cards.get(i).getName().equals(name)) { + return cards.get(i); + } } return null; } -} \ No newline at end of file +} diff --git a/src/Moudle/Collection.java b/src/Moudle/Collection.java index d0589e4..3d2098d 100644 --- a/src/Moudle/Collection.java +++ b/src/Moudle/Collection.java @@ -3,12 +3,13 @@ import java.util.ArrayList; public class Collection { - - private static ArrayList collections = new ArrayList<>(); - - private ArrayList cards = new ArrayList<>(); - private ArrayList items = new ArrayList<>(); - private ArrayList decks = new ArrayList<>(); + private static ArrayList collections; + private Account account; + private static ArrayList cards; + private static ArrayList minionAndHeroes; + private static ArrayList spells; + private static ArrayList items; + private ArrayList decks; public ArrayList getCards() { return cards; @@ -18,67 +19,192 @@ public ArrayList getItems() { return items; } - public static void save() { - - } - - public static void showAllDecks() { - + public static void exit() { + + } + + public static void show() { + System.out.println("Heroes :"); + for (int i = 0; i < minionAndHeroes.size(); i++) { + if (minionAndHeroes.get(i).isHero() == true) { + System.out.printf("\t%d:Name:%s - AP:%d - HP:%d - Class:%s - Special power:%s - Sell Cost:%d\n", + i + 1, minionAndHeroes.get(i).getAP(), minionAndHeroes.get(i).getHP(), + minionAndHeroes.get(i).getAttackType(), minionAndHeroes.get(i).getSpecialPowerType(), minionAndHeroes.get(i).getShopPrice()); + } + } + System.out.println("Items :"); + for (int i = 0; i < items.size(); i++) { + System.out.printf("\t%d:Name:%d - Desc: - Sell Cost:%d\n", i + 1 /*description*/, items.get(i).getPrice()); + } + System.out.println("Cards :"); + int counter = 0; + for (int i = 0; i < minionAndHeroes.size(); i++) { + if (minionAndHeroes.get(i).isHero() == false) { + System.out.printf("\tType:Minion - Class:%s - AP:%d - HP:%d - MP:%d - Special power:%s - Sell Cost:%d\n", + minionAndHeroes.get(i).getAttackType(), minionAndHeroes.get(i).getAP(), + minionAndHeroes.get(i).getHP(), minionAndHeroes.get(i).getManaPrice(), minionAndHeroes.get(i).getSpecialPowerType(), + minionAndHeroes.get(i).getShopPrice()); + counter++; + } + } + for (int i = 0; i < spells.size(); i++) { + System.out.printf("\tType:Spell - Name:%s - MP:%s - Desc: - Sell Cost:%d\n", spells.get(i).getName(), spells.get(i).getManaPrice(), + spells.get(i).getShopPrice()); + } + } + + public static void search(String name) { + if (Card.findCard(name) == null && Item.findItem(name) == null) { + System.out.println("There is no such card|item in collection"); + } else if (Card.findCard(name) != null && Item.findItem(name) == null) { + System.out.printf("Your card id is %d\n", Card.findCard(name).getCardID()); + } else if (Card.findCard(name) == null && Item.findItem(name) != null) { + System.out.printf("Your item id is %d\n", Item.findItem(name).getID()); + } } - public void show() { + public static void save() { } - public void search(String name) { - + public Card findCard(String cardName) { + for (int i = 0; i < cards.size(); i++) { + if (cards.get(i).getName().equals(cardName)) { + return cards.get(i); + } + } + return null; } - public void createDeck(String deckName) { - + public Item findItem(String itemName) { + for (int i = 0; i < items.size(); i++) { + if (items.get(i).getName().equals(itemName)) { + return items.get(i); + } + } + return null; } - public void deleteDeck(String deckName) { - + public Deck findDeck(String deckName) { + for (int i = 0; i < decks.size(); i++) { + if (decks.get(i).getName().equals(deckName)) { + return decks.get(i); + } + } + return null; } - public void addToDeck(int ID, String deckName) { - + public void addToCards(Card card) { + cards.add(card); } - public void removeFromDeck(int ID, String deckName) { - + public void removeFromCards(Card card) { + cards.remove(card); } - public boolean validateDeck(String deckName) { - return false; + public void addToItems(Item item) { + items.add(item); } - public void selectDeck(String deckName) { - + public void removeFromItems(Item item) { + items.remove(item); } - public void showDeck(String deckName) { - + public void createDeck(String deckName) { + if (findDeck(deckName) != null) { + System.out.println("There is already a deck with this name!"); + } else { + Deck deck = new Deck(); + deck.setName(deckName); + decks.add(deck); + } } - public void help() { - //$%^$^&%*%%%#^&^$&@#$@#$@#$&$&&#@$$%$???? - } + public void deleteDeck(String deckName) { + if (findDeck(deckName) == null) { + System.out.println("There is no such deck in your collection!"); + } else { + decks.remove(findDeck(deckName)); + } + } + + public void add(String name, String deckName) { + if (findCard(name) == null && findItem(name) == null) { + System.out.println("This card|item doesn't exist in the collection!"); + } else if (findCard(name) != null && findItem(name) == null) { + if (findDeck(deckName).findCard(name) != null) { + System.out.println("This card is already in deck!"); + } else { + if (findDeck(deckName).getCards().size() >= 21) { + System.out.println("You can't add anymore cards to deck!"); + } else { + findDeck(deckName).getCards().add(findCard(name)); + } + } + } else if (findCard(name) == null && findItem(name) != null) { + if (findDeck(deckName).getItem() != null) { + System.out.println("You can't add anymore items to deck!"); + } else { + findDeck(deckName).setItem(findItem(name)); + } + } + } + + public void remove(String name, String deckName) { + if (findDeck(deckName).findCard(name) == null && findDeck(deckName).getItem() == null) { + System.out.println("This card|item doesn't exist in deck!"); + } else if (findDeck(deckName).findCard(name) != null && findDeck(deckName).getItem() == null) { + findDeck(deckName).removeCard(findCard(name)); + } else if (findDeck(deckName).findCard(name) == null && findDeck(deckName).getItem() != null) { + findDeck(deckName).removeItem(findItem(name)); + } + } + + public void validateDeck(String deckName) { - public void addCard(Card card) { - cards.add(card); } - public void addItem(Item item) { - items.add(item); + public void selectDeck(String deckName) { + if (findDeck(deckName) == null) { + System.out.println("There is no such deck!"); + } else { + account.setMainDeck(findDeck(deckName)); + } + } + + public void showAllDecks() { + if (account.getMainDeck() != null) { + System.out.println("1:" + account.getMainDeck().getName() + ":"); + account.getMainDeck().show(); + int counter = 2; + for (int i = 0; i < decks.size(); i++) { + if (decks.get(i) != account.getMainDeck()) { + System.out.println(counter + ":" + decks.get(i).getName() + ":"); + decks.get(i).show(); + counter++; + } + } + } else { + int counter = 1; + for (int i = 0; i < decks.size(); i++) { + System.out.println(counter + " " + decks.get(i).getName() + ":"); + decks.get(i).show(); + counter++; + } + } } - public void removeCard(Card card) { - cards.remove(card); + public void showDeck(String deckName) { + if (findDeck(deckName) == null) { + System.out.println("There is no such deck!"); + } else { + findDeck(deckName).show(); + } } - public void removeItem(Item item) { - items.remove(item); + public static void help() { + System.out.printf("exit\nshow\nsearch [card name | item name]\nsave\ncreate deck[deck name]\ndelete deck [deck name]\n" + + "add[card id|card id|hero id]to deck[deck name]\nremove[card id|card id|hero id]from deck[deck name]\n" + + "validate deck[deck name]\nselect deck[deck name]\nshow all decks\nshow deck[deck name]\nhelp\n"); } } diff --git a/src/Moudle/Deck.java b/src/Moudle/Deck.java index e20c5cd..559d03a 100644 --- a/src/Moudle/Deck.java +++ b/src/Moudle/Deck.java @@ -2,26 +2,90 @@ import java.util.ArrayList; -public class Deck extends Collection { - +public class Deck { + private static ArrayList decks; private String name; - private ArrayList cards = new ArrayList<>(); - private Hero hero; + private ArrayList cards; + private ArrayList minionAndHeroes; + private ArrayList spells; private Item item; + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ArrayList getCards() { + return cards; + } + + public void setCards(ArrayList cards) { + this.cards = cards; + } + public Item getItem() { + return item; + } - public boolean isValidDeck() { + public void setItem(Item item) { + this.item = item; + } + public static Deck findDeck(String deckName) { + for (int i = 0; i < decks.size(); i++) { + if (decks.get(i).name.equals(deckName)) { + return decks.get(i); + } + } + return null; } - public void addCard(Card card) { + public Card findCard(String cardName) { + for (int i = 0; i < cards.size(); i++) { + if (cards.get(i).getName().equals(cardName)) { + return cards.get(i); + } + } + return null; } - public void addCard(Item item) { + public void removeCard(Card card) { + cards.remove(card); } - public void removeCarrd(Card card) { + public void removeItem(Item item) { + this.item = null; } + public void show() { + System.out.println("Heroes :"); + for (int i = 0; i < minionAndHeroes.size(); i++) { + if (minionAndHeroes.get(i).isHero() == true) { + System.out.printf("\t%d:Name:%s - AP:%d - HP:%d - Class:%s - Special power:%s - Sell Cost:%d\n", + i + 1, minionAndHeroes.get(i).getAP(), minionAndHeroes.get(i).getHP(), + minionAndHeroes.get(i).getAttackType(), minionAndHeroes.get(i).getSpecialPowerType(), minionAndHeroes.get(i).getShopPrice()); + } + } + System.out.println("Items :"); + System.out.printf("\t%d:Name:%d - Desc: - Sell Cost:%d\n", 1 /*description*/, item.getPrice()); + + System.out.println("Cards :"); + int counter = 0; + for (int i = 0; i < minionAndHeroes.size(); i++) { + if (minionAndHeroes.get(i).isHero() == false) { + System.out.printf("\tType:Minion - Class:%s - AP:%d - HP:%d - MP:%d - Special power:%s - Sell Cost:%d\n", + minionAndHeroes.get(i).getAttackType(), minionAndHeroes.get(i).getAP(), + minionAndHeroes.get(i).getHP(), minionAndHeroes.get(i).getManaPrice(), minionAndHeroes.get(i).getSpecialPowerType(), + minionAndHeroes.get(i).getShopPrice()); + counter++; + } + } + for (int i = 0; i < spells.size(); i++) { + System.out.printf("\tType:Spell - Name:%s - MP:%s - Desc: - Sell Cost:%d\n", spells.get(i).getName(), spells.get(i).getManaPrice(), + spells.get(i).getShopPrice()); + } + } } diff --git a/src/Moudle/Fighter.java b/src/Moudle/Fighter.java index 344d097..5628710 100644 --- a/src/Moudle/Fighter.java +++ b/src/Moudle/Fighter.java @@ -3,145 +3,131 @@ import java.util.ArrayList; public class Fighter extends MinionAndHero { - private int AP; - private int HP; - private int x; - private int y; - private String ID; - private ArrayList attackedFighter = new ArrayList<> ( ); - private boolean canCounterAttack; - private boolean canMove; - private boolean canAttack; - private int holyDefence; - ArrayList buffs = new ArrayList<> ( ); - private Cell currentCell; - private Player player; - public void preTurnProcces(){ - for ( Buff buff:this.getSpecialPowers () ){ - if ( this.getSpecialPowerType ()==1 ){ - addToBuff ( buff ); - } - } - this.enableBuffBoolEssence (); - } - public void addToBuff(Buff buff){ - if ( buff.getAgeType ()==3 ){ - return; - } - AP+=buff.getChangeAP (); - HP+=buff.getChangeHP (); - holyDefence+=buff.getChangeHollynes (); - buffs.add ( buff ); - if ( buff.isDisableNegativeBuffs () ) { - for ( Buff buff1:this.buffs ) - if ( !buff1.isPositive ( ) ) { - removeFromBuff ( buff1 ); - } - } - if ( buff.isDisablePositiveBuffs () ) { - for ( Buff buff1:this.buffs ) - if ( buff1.isPositive ( ) ) { - removeFromBuff ( buff1 ); - } - } - } - public int howManyAttacked(Fighter fighter){ - int counter=0; - for ( Fighter fighter1:attackedFighter ){ - if ( fighter==fighter1 ){ - counter++; - } - } - return counter; - } - public int getX () { - return x; - } - - public int getY () { - return y; - } - - public boolean CanAttack () { - return canAttack; - } - public void disableCanAttack(){ - canAttack=false; - } - public void disableCanMove(){ - this.canMove=false; - } - public void setLocation(int x,int y){ - this.x=x; - this.y=y; - } - public boolean isCanCounterAttack () { - return canCounterAttack; - } - @Override - public int getHP () { - return HP; - } - public void decreaseHP(int decrease){ - HP-=decrease; - } - @Override - public int getAP () { - return AP; - } - - public int getHolyDefence () { - return holyDefence; - } - - public boolean isCanMove () { - return canMove; - } - - public Player getPlayer () { - return player; - } - - public void removeFromBuff( Buff buff){ - AP-=buff.getChangeAP (); - HP-=buff.getChangeHP (); - holyDefence-=buff.getChangeHollynes (); - buffs.remove ( buff ); - } - public void enableBuffBoolEssence(){ - for ( Buff buff:buffs ){ - booleanChangeInt ( canAttack,buff.getChangeCanAttack () ); - booleanChangeInt ( canMove,buff.getChangeCanMove () ); - booleanChangeInt ( canCounterAttack,buff.getChangeCanCounterAttack () ); - } - } - public void addAttackedFighter(Fighter fighter){ - attackedFighter.add ( fighter ); - } - public String getID () { - return ID; - } - private void booleanChangeInt( boolean target, int changer){ - if ( changer==1 ) - target=true; - if ( changer==2 ) - target=false; - if ( changer==3 ){ - if ( target ) - target=false; - else target=true; - } - } - protected Fighter ( MinionAndHero minionAndHero,ArrayList minionAndHeroes,Player player ) { - super ( minionAndHero); - AP = super.getAP (); - HP = super.getHP (); - int counter=0; - for ( MinionAndHero minionAndHero1:minionAndHeroes ){ - if ( minionAndHero==minionAndHero1 ){ - counter++; - } - } - this.ID=player.getUsername ()+"_"+minionAndHero.getName ()+"_"+counter+1; - } + private int AP; + private int HP; + private int x; + private int y; + private String ID; + private boolean canCounterAttack; + private boolean canMove; + private boolean canAttack; + private int holyDefence; + ArrayList buffs = new ArrayList<>(); + private Cell currentCell; + private Player player; + + public void preTurnProcces() { + for (Buff buff : this.getSpecialPowers()) { + if (this.getSpecialPowerType() == 1) { + addToBuff(buff); + } + } + this.enableBuffBoolEssence(); + } + + public void addToBuff(Buff buff) { + AP += buff.getChangeAP(); + HP += buff.getChangeHP(); + holyDefence += buff.getChangeHollynes(); + buffs.add(buff); + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public boolean CanAttack() { + return canAttack; + } + + public void disableCanAttack() { + canAttack = false; + } + + public void disableCanMove() { + this.canMove = false; + } + + public void setLocation(int x, int y) { + this.x = x; + this.y = y; + } + + public boolean isCanCounterAttack() { + return canCounterAttack; + } + + @Override + public int getHP() { + return HP; + } + + public void decreaseHP(int decrease) { + HP -= decrease; + } + + @Override + public int getAP() { + return AP; + } + + public int getHolyDefence() { + return holyDefence; + } + + public boolean isCanMove() { + return canMove; + } + + public Player getPlayer() { + return player; + } + + public void removeFromBuff(Buff buff) { + AP -= buff.getChangeAP(); + HP -= buff.getChangeHP(); + holyDefence -= buff.getChangeHollynes(); + buffs.remove(buff); + } + + public void enableBuffBoolEssence() { + for (Buff buff : buffs) { + booleanChangeInt(canAttack, buff.getChangeCanAttack()); + booleanChangeInt(canMove, buff.getChangeCanMove()); + booleanChangeInt(canCounterAttack, buff.getChangeCanCounterAttack()); + } + } + + public String getID() { + return ID; + } + + private void booleanChangeInt(boolean target, int changer) { + if (changer == 1) + target = true; + if (changer == 2) + target = false; + if (changer == 3) { + if (target) + target = false; + else target = true; + } + } + + protected Fighter(MinionAndHero minionAndHero, ArrayList minionAndHeroes, Player player) { + super(minionAndHero); + AP = super.getAP(); + HP = super.getHP(); + int counter = 0; + for (MinionAndHero minionAndHero1 : minionAndHeroes) { + if (minionAndHero == minionAndHero1) { + counter++; + } + } + this.ID = player.getUserName() + "_" + minionAndHero.getName() + "_" + counter + 1; + } } diff --git a/src/Moudle/Ground.java b/src/Moudle/Ground.java index 7b3cc0a..0c36a72 100644 --- a/src/Moudle/Ground.java +++ b/src/Moudle/Ground.java @@ -4,17 +4,20 @@ public class Ground { private Cell[][] cells = new Cell[5][9]; - public Ground(){ - for ( Cell[] cell:cells ){ - for ( Cell cell1:cell ){ - cell1=new Cell (); + + public Ground() { + for (Cell[] cell : cells) { + for (Cell cell1 : cell) { + cell1 = new Cell(); } } } - public static int getDistance ( int x1, int y1, int x2, int y2) { - return Math.abs ( x1-x2 )+Math.abs ( y1-y2 ); + + public static int getDistance(int x1, int y1, int x2, int y2) { + return Math.abs(x1 - x2) + Math.abs(y1 - y2); } - public Cell getCell(int x,int y){ + + public Cell getCell(int x, int y) { return cells[x][y]; } } diff --git a/src/Moudle/Hand.java b/src/Moudle/Hand.java index 7dd4604..9ac1e1c 100644 --- a/src/Moudle/Hand.java +++ b/src/Moudle/Hand.java @@ -2,37 +2,36 @@ import java.util.ArrayList; -public class Hand extends Deck{ +public class Hand extends Deck { private Deck deck; private ArrayList cards = new ArrayList<>(); private Item item; private Card nextCard; + public void addCard() { } + public void addItem() { } - public void show(){ - for ( Card card:cards ){ - card.showCard (); - } - } - public void showNextCard(){ - nextCard.showCard (); - } + public Item getItem() { return this.item; } + public void selectNextCard() { } + public Card getNextCard() { return this.nextCard; } + public void removeCard() { } + public void removeItem() { } diff --git a/src/Moudle/Item.java b/src/Moudle/Item.java index 98c5747..be74a76 100644 --- a/src/Moudle/Item.java +++ b/src/Moudle/Item.java @@ -7,36 +7,54 @@ public class Item { private String name; private int price; private boolean isFlag; + private int ID; - public static Item findItem(String name) { - for (Item item : items) { - if (item.name.equals(name)) - return item; - } - return null; + public static ArrayList getItems() { + return items; } - public boolean isFlag(){ - return isFlag; + public static void setItems(ArrayList items) { + Item.items = items; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; } public int getPrice() { return price; } - public static Item findItem(String name, ArrayList items) { - for (Item item : items) { - if (item.name.equals(name)) - return item; - } - return null; + public void setPrice(int price) { + this.price = price; } - public static void setItems(ArrayList items) { - Item.items = items; + public void setID(int ID) { + this.ID = ID; } - public String getName() { - return name; + public int getID() { + return ID; + } + + public boolean isFlag() { + return isFlag; + } + + public void setFlag(boolean flag) { + isFlag = flag; + } + + public static Item findItem(String name) { + for (int i = 0; i < items.size(); i++) { + if (items.get(i).name.equals(name)) { + return items.get(i); + } + } + return null; } } diff --git a/src/Moudle/Load.java b/src/Moudle/Load.java index 5cbb105..19fabf7 100644 --- a/src/Moudle/Load.java +++ b/src/Moudle/Load.java @@ -1,56 +1,4 @@ package Moudle; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.Reader; -import java.lang.reflect.Type; -import java.util.ArrayList; public class Load { - public static void saveAccounts () { - } - public static void loadMinionAndHeros() throws FileNotFoundException { - Gson gson = CreatGson.getGson (); - Reader reader = new FileReader ( "MinionAndHeros.json" ); - MinionAndHeroTmp tmp = gson.fromJson ( reader, MinionAndHeroTmp.class); - MinionAndHero.setMinionAndHeroes ( tmp.minionAndHeroes ); - } - public static void loadSpells() throws FileNotFoundException { - Gson gson = CreatGson.getGson (); - Reader reader = new FileReader ( "Spells.json"); - SpellTmp tmp = gson.fromJson ( reader, ( Type ) Spell.class); - Spell.setSpells ( tmp.spells ); - } - public static void loadItems() throws FileNotFoundException { - Gson gson = CreatGson.getGson (); - Reader reader = new FileReader ( "Items.json" ); - ItemTmp tmp = gson.fromJson ( reader, ( Type ) Item.class ); - Item.setItems(tmp.items); - } - public static void loadAccounts(){ - Gson gson = CreatGson.getGson (); - } } -class ItemTmp{ - ArrayList items; -} -class MinionAndHeroTmp { - ArrayList minionAndHeroes; -} -class SpellTmp { - ArrayList spells; -} -class AccountTnp{ - ArrayList accounts; -} -class CreatGson { - private static Gson gson; - public static Gson getGson (){ - if ( gson == null ){ - GsonBuilder builder = new GsonBuilder (); - gson = builder.create (); - } - return gson; - } -} \ No newline at end of file diff --git a/src/Moudle/MatchHistory.java b/src/Moudle/MatchHistory.java index f653a2e..95deeeb 100644 --- a/src/Moudle/MatchHistory.java +++ b/src/Moudle/MatchHistory.java @@ -13,14 +13,14 @@ public class MatchHistory { private Date dateAndTime; public String[] loadLastMatch(Player player) { - + return null; } public void addMatchHistory(MatchHistory match) { matchHistories.add(match); } - public void MatchHistory(Game game) { - - } +// public void MatchHistory(Game game) { +// +// } } \ No newline at end of file diff --git a/src/Moudle/MinionAndHero.java b/src/Moudle/MinionAndHero.java index d2b2f5c..57016d4 100644 --- a/src/Moudle/MinionAndHero.java +++ b/src/Moudle/MinionAndHero.java @@ -10,41 +10,47 @@ public class MinionAndHero extends Card { private int nation; private int attackType; private String[] abilities; - private ArrayList specialPowers=new ArrayList<>(); + private ArrayList specialPowers = new ArrayList<>(); private int specialPowerCoolDown; //0:onspawn 2:passive 3:ondeath 4:onAttack 5:onDe 6:combo private int specialPowerType; - private Target specialPowerTarget; - public Target getSpecialPowerTarget () { - return specialPowerTarget; + public int getAttackType() { + return attackType; } - public int getSpecialPowerType () { + public int getSpecialPowerType() { return specialPowerType; } - public ArrayList getSpecialPowers () { + public ArrayList getSpecialPowers() { return specialPowers; } - protected MinionAndHero( String name, int shopPrice, int manaPrice) { - super(name,shopPrice, manaPrice,1); + + protected MinionAndHero(String name, int shopPrice, int manaPrice) { + super(name, shopPrice, manaPrice, 1); } - protected MinionAndHero(MinionAndHero minionAndHero){ - super (minionAndHero.getName (),minionAndHero.getShopPrice (),minionAndHero.getManaPrice (),1 ); + + protected MinionAndHero(MinionAndHero minionAndHero) { + super(minionAndHero.getName(), minionAndHero.getShopPrice(), minionAndHero.getManaPrice(), 1); } - public int getAP () { + + public int getAP() { return AP; } - public int getHP () { + + public int getHP() { return HP; } - public static void setMinionAndHeroes( ArrayList minionAndHeroes) { + + public static void setMinionAndHeroes(ArrayList minionAndHeroes) { MinionAndHero.minionAndHeroes = minionAndHeroes; } + public int getNation() { return nation; } + public boolean isHero() { return isHero; } diff --git a/src/Moudle/Player.java b/src/Moudle/Player.java index 36ed3d0..13604d0 100644 --- a/src/Moudle/Player.java +++ b/src/Moudle/Player.java @@ -1,7 +1,5 @@ package Moudle; -import View.View; - import java.util.ArrayList; public class Player extends Account { @@ -11,33 +9,24 @@ public class Player extends Account { private ArrayList graveYard; private ArrayList items; private ArrayList buffs; - public void addToBuffs(Buff buff){ - } + public void addToBuffs(Buff buff) { - public int getMana () { - return mana; - } - public void decreaseMana(int mony){ - mana-=mony; } - public void addItem( Item item){ - items.add ( item ); - } - public ArrayList getFighters () { + + public ArrayList getFighters() { return fighters; } - public boolean equals ( Object object){ - if ( object.getClass () == Player.class ) - { - Account account = (Player)object; - if ( account.getUsername ().equals ( this.getUsername () ) ) + public boolean equals(Object object) { + if (object.getClass() == Player.class) { + Account account = (Player) object; + if (account.getUserName().equals(this.getUserName())) return true; return false; - } - else return false; + } else return false; } + public void insert() { } @@ -45,11 +34,11 @@ public void insert() { public void showCollectables() { } - public void showFighters(){ - for ( Fighter fighter:fighters ){ - View.showFighter ( fighter ); - } + + public void showFighters() { + System.out.println(fighters); } + public void useItem(Item item) { } @@ -63,6 +52,6 @@ public void showNextCard() { } public void showHand() { - hand.show (); + } } \ No newline at end of file diff --git a/src/Moudle/Shop.java b/src/Moudle/Shop.java index 8ff9372..4afc593 100644 --- a/src/Moudle/Shop.java +++ b/src/Moudle/Shop.java @@ -1,7 +1,5 @@ package Moudle; -import Controller.ControlBox; - import java.util.ArrayList; public class Shop { @@ -10,101 +8,129 @@ public class Shop { private ArrayList cards; private ArrayList items; - public static void input(ControlBox controllBox) { - if (controllBox.getType().equals("search")) { - Card card = Card.findCard(controllBox.getCardName()); - if (card == null) { + public void input(){ - } - } + } + public Account getAccount() { + return account; + } + + public void setAccount(Account account) { + this.account = account; } - public static void handleInput() { + public ArrayList getHeroesAndMinions() { + return heroesAndMinions; + } + + public void setHeroesAndMinions(ArrayList heroesAndMinions) { + this.heroesAndMinions = heroesAndMinions; + } + public ArrayList getCards() { + return cards; } - public void search(String name) { - boolean founded = false; + public void setCards(ArrayList cards) { + this.cards = cards; + } + + public ArrayList getItems() { + return items; + } + + public void setItems(ArrayList items) { + this.items = items; + } + + public void exit() { + + } + + public void showCollection() { + System.out.println(account.getCollection().getCards()); + System.out.println(account.getCollection().getItems()); + } + + public Card findCard(String name) { for (int i = 0; i < cards.size(); i++) { if (cards.get(i).getName().equals(name)) { - founded = true; + return cards.get(i); } } + return null; + } + + public Item findItem(String name) { for (int i = 0; i < items.size(); i++) { if (items.get(i).getName().equals(name)) { - founded = true; + return items.get(i); } } - if (founded == false) { - System.out.println("We don't have this card/item!"); + return null; + } + + public int search(String name) { + if (findCard(name) != null && findItem(name) == null) { + return findCard(name).getCardID(); + } else if (findCard(name) == null && findItem(name) != null) { + return findItem(name).getID(); + } + System.out.println("This card|item is not in the shop!"); + return 0; + } + + public int searchCollection(String name) { + if (account.getCollection().findCard(name) != null && account.getCollection().findItem(name) == null) { + return account.getCollection().findCard(name).getCardID(); + } else if (account.getCollection().findCard(name) == null && account.getCollection().findItem(name) != null) { + return account.getCollection().findItem(name).getID(); } + System.out.println("This card|item is not in your collection!"); + return 0; } public void buy(String name) { - if (Card.findCard(name) == null && Item.findItem(name) == null) { - System.out.println("This card/item doesn't exist!"); - } else if (Card.findCard(name) != null && Item.findItem(name) == null) { - if (account.getMoney() < Card.findCard(name).getShopPrice()) { + if (findCard(name) == null && findItem(name) == null) { + System.out.println("This card|item is not in the shop!"); + } else if (findCard(name) != null && findItem(name) == null) { + if (account.getMoney() < findCard(name).getShopPrice()) { System.out.println("You don't have enough money!"); } else { - account.spendMoney(Card.findCard(name).getShopPrice()); - account.getCollection().addCard(Card.findCard(name)); + account.getCollection().addToCards(findCard(name)); + account.spendMoney(findCard(name).getShopPrice()); } - } else if (Card.findCard(name) == null && Item.findItem(name) != null) { - if (account.getMoney() < Item.findItem(name).getPrice()) { + } else if (findCard(name) == null && findItem(name) != null) { + if (account.getMoney() < findItem(name).getPrice()) { System.out.println("You don't have enough money!"); } else if (account.getCollection().getItems().size() >= 3) { - System.out.println("You can't buy more than 3 items!"); + System.out.println("You can't buy anymore items!"); } else { - account.spendMoney(Item.findItem(name).getPrice()); - account.getCollection().addItem(Item.findItem(name)); + account.getCollection().addToItems(findItem(name)); + account.spendMoney(findItem(name).getPrice()); } } } public void sell(String name) { - if (Card.findCard(name) == null && Item.findItem(name) == null) { - System.out.println("This card/item doesn't exist!"); - } else if (Card.findCard(name) != null && Item.findItem(name) == null) { - account.getCollection().removeCard(Card.findCard(name)); - account.addMoney(Card.findCard(name).getShopPrice()); - } else if (Card.findCard(name) == null && Item.findItem(name) != null) { - account.getCollection().removeItem(Item.findItem(name)); - account.addMoney(Item.findItem(name).getPrice()); - } - } - - public void showCollection() { - - } - - public void searchCollection(String name) { - boolean founded = false; - for (int i = 0; i < account.getCollection().getCards().size(); i++) { - if (account.getCollection().getCards().get(i).getName().equals(name)) { - founded = true; - } - } - for (int i = 0; i < account.getCollection().getItems().size(); i++) { - if (account.getCollection().getItems().get(i).getName().equals(name)) { - founded = true; - } - } - if (founded == false) { - System.out.println("This card/item doesn't exist!"); + if (findCard(name) == null && findItem(name) == null) { + System.out.println("You don't have this card|item!"); + } else if (findCard(name) != null && findItem(name) == null) { + account.getCollection().removeFromCards(findCard(name)); + account.addMoney(findCard(name).getShopPrice()); + } else if (findCard(name) == null && findItem(name) != null) { + account.getCollection().removeFromItems(findItem(name)); + account.addMoney(findItem(name).getPrice()); } } public void show() { - - } - - public void exit() { - + System.out.println(cards); + System.out.println(items); } public void help() { - System.out.println("exit\nshow collection\nsearch [item name|card name]\nsearch collection [item name|card name]\n" + - "buy [card name|item name]\nsell [card id|card id]\nshow"); + System.out.printf("exit\nshow collection\nsearch[item name|card name]\nsearch collection[item name|card name]\n" + + "buy[card name|item name]\nsell[card id|item id]\nshow\n"); } -} \ No newline at end of file +} diff --git a/src/Moudle/Spell.java b/src/Moudle/Spell.java index 95955cc..ca3fde1 100644 --- a/src/Moudle/Spell.java +++ b/src/Moudle/Spell.java @@ -3,26 +3,26 @@ import java.util.ArrayList; public class Spell extends Card { - private ArrayList spells = new ArrayList ( ); - private ArrayList mainBuffs; - private ArrayList buffs; - private Target target; + private ArrayList spells = new ArrayList ( ); + private ArrayList mainBuffs; + private ArrayList buffs; + private Target target; - public ArrayList getBuffs () { - return buffs; - } + public ArrayList getBuffs () { + return buffs; + } - public ArrayList getMainBuffs () { - return mainBuffs; - } + public ArrayList getMainBuffs () { + return mainBuffs; + } - public Target getTarget () { - return target; - } - public void setSpells ( ArrayList spells ) { - this.spells = spells; - } - protected Spell ( String name , int cardID , int shopPrice , int manaPrice ) { - super ( name , cardID , shopPrice , manaPrice ); - } + public Target getTarget () { + return target; + } + public void setSpells ( ArrayList spells ) { + this.spells = spells; + } + protected Spell ( String name , int cardID , int shopPrice , int manaPrice ) { + super ( name , cardID , shopPrice , manaPrice ); + } } diff --git a/src/Moudle/Target.java b/src/Moudle/Target.java index d67b27d..d4ad31d 100644 --- a/src/Moudle/Target.java +++ b/src/Moudle/Target.java @@ -3,116 +3,114 @@ import java.util.ArrayList; public class Target { - //targetType 0:rectangle 1:1force 2:all forces 3:force in a row 4:force in a column 5:8cell in near 6:a random Fighter - //7:attacked Fighter 8:herself - private int targetType; - private int rectangleLength; - //targetFriendType:0:no diffrence 1:only friend 2:only enemy - private int targetFriendType; - //targetDegreeType:0:no diffrence 1:minion 2:hero - private int targetDegreeType; + //targetType 0:rectangle 1:1force 2:all forces 3:force in a row 4:force in a column 5:8cell in near + private int targetType; + private int rectangleLength; + //targetFriendType:0:no diffrence 1:only friend 2:only enemy + private int targetFriendType; + //targetDegreeType:0:no diffrence 1:minion 2:hero + private int targetDegreeType; - public int getTargetType () { - return targetType; - } + public boolean isValidTarget(Battle battle, int x, int y, Player player) { + if (targetType == 0) { + if (isOutOfSide(x, y) || isOutOfSide(x + rectangleLength - 1, y + rectangleLength - 1)) + return false; + return true; + } + if (targetType == 1) { + if (battle.getGround().getCell(x, y).getCardOnCell() == null) { + return false; + } + Fighter fighter = (Fighter) battle.getGround().getCell(x, y).getCardOnCell(); + return checkFriendAndDegreeType(fighter, player); + } + if (targetType == 2 || targetType == 4 || targetType == 3 || targetType == 5) + return true; + return false; + } - public boolean isValidTarget( Battle battle, int x, int y, Player player){ - if ( targetType==0 ){ - if ( isOutOfSide ( x,y )||isOutOfSide ( x+rectangleLength-1,y+rectangleLength-1 ) ) - return false; - return true; - } - if ( targetType==1 ){ - if ( battle.getGround ().getCell ( x, y ).getCardOnCell () == null ) { - return false; - } - Fighter fighter = (Fighter)battle.getGround ().getCell ( x, y ).getCardOnCell (); - return checkFriendAndDegreeType (fighter,player ); - } - if(targetType==2||targetType==4||targetType==3||targetType==5) - return true; - return false; - } - public ArrayList targetFighters(Battle battle,int x,int y,Player player){ - ArrayList targets = new ArrayList<> ( ); - Ground ground = battle.getGround (); - if ( targetType==0 ){ - for ( int i=0;i4||x<0 ) - return true; - if(y>8||y<0) - return true; - return false; - } - private boolean checkFriendAndDegreeType(Fighter fighter,Player player) { - if ( targetDegreeType!=0 ) { - if ( targetDegreeType==1 ) { - if ( fighter.isHero ( ) ) - return false; - } - if ( targetDegreeType == 2 ) { - if ( !fighter.isHero () ) - return false; - } - } - if ( targetFriendType!=0 ){ - if ( targetFriendType==1 ){ - if ( fighter.getPlayer ()!=player ) - return false; - } - if ( targetFriendType==2 ){ - if ( fighter.getPlayer ()==player ) - return false; - } - } - return true; - } + public ArrayList targetFighters(Battle battle, int x, int y, Player player) { + ArrayList targets = new ArrayList<>(); + Ground ground = battle.getGround(); + if (targetType == 0) { + for (int i = 0; i < rectangleLength; i++) { + for (int j = 0; j < rectangleLength; j++) { + if (ground.getCell(x + i, y + j).getCardOnCell() != null) { + targets.add((Fighter) ground.getCell(x + i, y + j).getCardOnCell()); + } + } + } + } + if (targetType == 1) { + targets.add((Fighter) ground.getCell(x, y).getCardOnCell()); + } + if (targetType == 2) { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 5; j++) { + Fighter fighter = (Fighter) ground.getCell(i, j).getCardOnCell(); + if (checkFriendAndDegreeType(fighter, player)) + targets.add(fighter); + } + } + } + if (targetType == 3) { + for (int i = 0; i < 8; i++) { + Fighter fighter = (Fighter) ground.getCell(i, y).getCardOnCell(); + if (checkFriendAndDegreeType(fighter, player)) + targets.add(fighter); + } + } + if (targetType == 4) { + for (int j = 0; j < 5; j++) { + Fighter fighter = (Fighter) ground.getCell(x, j).getCardOnCell(); + if (checkFriendAndDegreeType(fighter, player)) + targets.add(fighter); + } + } + if (targetType == 5) { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) + break; + Fighter fighter = (Fighter) ground.getCell(x + i, y + j).getCardOnCell(); + if (checkFriendAndDegreeType(fighter, player)) { + targets.add(fighter); + } + } + } + } + return targets; + } + + private boolean isOutOfSide(int x, int y) { + if (x > 4 || x < 0) + return true; + if (y > 8 || y < 0) + return true; + return false; + } + + private boolean checkFriendAndDegreeType(Fighter fighter, Player player) { + if (targetDegreeType != 0) { + if (targetDegreeType == 1) { + if (fighter.isHero()) + return false; + } + if (targetDegreeType == 2) { + if (!fighter.isHero()) + return false; + } + } + if (targetFriendType != 0) { + if (targetFriendType == 1) { + if (fighter.getPlayer() != player) + return false; + } + if (targetFriendType == 2) { + if (fighter.getPlayer() == player) + return false; + } + } + return true; + } } diff --git a/src/Test/Main.java b/src/Test/Main.java new file mode 100644 index 0000000..d33cb68 --- /dev/null +++ b/src/Test/Main.java @@ -0,0 +1,106 @@ +package Test; + +import java.util.Scanner; + +import Model.*; + +public class Main { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int location = 0; //0: account, 1:main menu, 2:collection, 3:shop, 4:battle, -1:exit the game + Account account = new Account(); + Collection collection = new Collection(); + while (location != -1) { + while (location == 0) { + String input = scanner.nextLine(); + input.toLowerCase(); + if (input.contains("create account")) { + Account.createAccount(input.split(" ")[2]); + } + if (input.contains("login")) { + if (account.login(input.split(" ")[1]) == true) { + location = 1; + } + } + if (input.contains("show")) { + Account.showLeaderBoard(); + } + if (input.contains("save")) { + Account.save(); + } + if (input.contains("logout")) { + account.logout(); + } + if (input.contains("help")) { + account.help(); + } + } + while (location == 1) { + System.out.println("1.Collection"); + System.out.println("2.Shop"); + System.out.println("3.Battle"); + System.out.println("4.Exit"); + System.out.println("5.Help"); + String input = scanner.nextLine(); + input.toLowerCase(); + if (input.contains("enter")) { + if (input.contains("collection")) { + location = 2; + } + if (input.contains("shop")) { + location = 3; + } + if (input.contains("battle")) { + location = 4; + } + if (input.contains("exit")) { + location = -1; + } + if (input.contains("help")) { + System.out.println("1.Collection"); + System.out.println("2.Shop"); + System.out.println("3.Battle"); + System.out.println("4.Exit"); + System.out.println("5.Help"); + } + } + } + while (location == 2) { + String input = scanner.nextLine(); + if (input.contains("exit")) { + location = 1; + } else if (input.contains("show")) { + Collection.show(); + } else if (input.contains("search")) { + Collection.search(input.split(" ")[1]); + } else if (input.contains("save")) { + Collection.save(); + } else if (input.contains("create")) { + collection.createDeck(input.split(" ")[2]); + } else if (input.contains("delete")) { + collection.deleteDeck(input.split(" ")[2]); + } else if (input.contains("add")) { + collection.add(input.split(" ")[1], input.split(" ")[4]); + } else if (input.contains("remove")) { + collection.remove(input.split(" ")[1], input.split(" ")[4]); + } else if (input.contains("validate")) { + collection.validateDeck(input.split(" ")[2]); + } else if (input.contains("select")) { + collection.selectDeck(input.split(" ")[2]); + } else if (input.contains("show all")) { + collection.showAllDecks(); + } else if (input.contains("show deck")) { + collection.showDeck(input.split(" ")[2]); + } else if (input.contains("help")) { + Collection.help(); + } + } + while (location == 3) { + + } + while (location == 4) { + + } + } + } +}