diff --git a/.gitattributes b/.gitattributes index d3bc9912094..54b4fe97f57 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10079,7 +10079,6 @@ src/main/java/forge/Gui_MigrateLocalMWSSetPictures_HQ.java svneol=native#text/pl src/main/java/forge/Gui_MultipleBlockers4.java svneol=native#text/plain src/main/java/forge/Gui_NewGame.java svneol=native#text/plain src/main/java/forge/Gui_ProgressBarWindow.java svneol=native#text/plain -src/main/java/forge/Gui_WinLose.java svneol=native#text/plain src/main/java/forge/HandSizeOp.java svneol=native#text/plain src/main/java/forge/HttpUtil.java svneol=native#text/plain src/main/java/forge/HumanPlayer.java svneol=native#text/plain @@ -10364,7 +10363,6 @@ src/main/java/forge/quest/data/QuestMatchState.java svneol=native#text/plain src/main/java/forge/quest/data/QuestPreferences.java svneol=native#text/plain src/main/java/forge/quest/data/QuestUtil.java svneol=native#text/plain src/main/java/forge/quest/data/QuestUtilCards.java -text -src/main/java/forge/quest/data/QuestUtilRewards.java -text src/main/java/forge/quest/data/ReadPriceList.java svneol=native#text/plain src/main/java/forge/quest/data/bazaar/QuestStallDefinition.java svneol=native#text/plain src/main/java/forge/quest/data/bazaar/QuestStallManager.java svneol=native#text/plain @@ -10466,7 +10464,6 @@ src/test/java/forge/GuiMigrateLocalMWSSetPicturesHQTest.java svneol=native#text/ src/test/java/forge/GuiMultipleBlockers4Test.java svneol=native#text/plain src/test/java/forge/GuiProgressBarWindowTest.java svneol=native#text/plain src/test/java/forge/GuiQuestOptionsTest.java svneol=native#text/plain -src/test/java/forge/GuiWinLoseTest.java svneol=native#text/plain src/test/java/forge/PanelTest.java svneol=native#text/plain src/test/java/forge/PhaseTest.java svneol=native#text/plain src/test/java/forge/RunTest.java svneol=native#text/plain diff --git a/src/main/java/forge/Gui_WinLose.java b/src/main/java/forge/Gui_WinLose.java deleted file mode 100644 index 06542fb8603..00000000000 --- a/src/main/java/forge/Gui_WinLose.java +++ /dev/null @@ -1,526 +0,0 @@ -package forge; - -import forge.error.ErrorViewer; -import forge.game.GameEndReason; -import forge.game.GameFormat; -import forge.game.GameLossReason; -import forge.game.GamePlayerRating; -import forge.game.GameSummary; -import forge.gui.CardListViewer; -import forge.gui.ListChooser; -import forge.item.CardPrinted; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; -import forge.properties.NewConstants.LANG.Gui_WinLose.WINLOSE_TEXT; -import forge.quest.data.QuestData; -import forge.quest.data.QuestMatchState; -import forge.quest.data.QuestPreferences; -import forge.quest.gui.QuestFrame; -import forge.quest.gui.main.QuestChallenge; -import forge.quest.gui.main.QuestEvent; -import forge.view.swing.Gui_HomeScreen; -import forge.view.swing.OldGuiNewGame; -import net.miginfocom.swing.MigLayout; - -import javax.swing.BorderFactory; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.SwingConstants; -import javax.swing.border.Border; -import javax.swing.border.TitledBorder; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - *
Gui_WinLose class.
- * - * @author Forge - * @version $Id$ - */ -public class Gui_WinLose extends JFrame implements NewConstants { - /** ConstantserialVersionUID=-5800412940994975483L. */
- private static final long serialVersionUID = -5800412940994975483L;
-
- private JLabel titleLabel = new JLabel();
- private JButton continueButton = new JButton();
- private JButton restartButton = new JButton();
- private JButton quitButton = new JButton();
- private JLabel statsLabel = new JLabel();
- private JPanel jPanel2 = new JPanel();
- @SuppressWarnings("unused")
- // titledBorder1
- private TitledBorder titledBorder1;
- @SuppressWarnings("unused")
- // border1
- private Border border1;
-
- private class WinLoseModel {
- public QuestMatchState match;
- public QuestData quest;
- public QuestEvent event;
- }
-
- private WinLoseModel model;
-
- /**
- * Constructor for Gui_WinLose.
- * - * @param matchState a QuestMatchState - * @param quest a QuestData object - * @param chall a QuestChallenge object - */ - public Gui_WinLose(final QuestMatchState matchState, final QuestData quest, final QuestEvent event) { - model = new WinLoseModel(); - model.match = matchState; - model.quest = quest; - model.event = event; - - try { - jbInit(); - } catch (Exception ex) { - ErrorViewer.showError(ex); - } - - setup(); - - Dimension screen = this.getToolkit().getScreenSize(); - setBounds(screen.width / 3, 100 /*position*/, 215, 370 /*size*/); - setVisible(true); - } - - /** - *setup.
- */ - private void setup() { - Phase.setGameBegins(0); - - if (model.match.isMatchOver()) { -// editDeckButton.setEnabled(false); - continueButton.setEnabled(false); - quitButton.grabFocus(); - } - - boolean isQuestMode = model.quest != null; - restartButton.setEnabled(!isQuestMode); // For quest always disabled, otherwise always on - - //show Wins and Loses - Player human = AllZone.getHumanPlayer(); - int humanWins = model.match.countGamesWonBy(human.getName()); - int humanLosses = model.match.getGamesPlayedCount() - humanWins; - statsLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.WON) + humanWins - + ForgeProps.getLocalized(WINLOSE_TEXT.LOST) + humanLosses); - - //show "You Won" or "You Lost" - if (model.match.hasWonLastGame(human.getName())) { - titleLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.WIN)); - } else { - titleLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.LOSE)); - } - } //setup(); - - /** - *jbInit.
- * - * @throws java.lang.Exception if any. - */ - private void jbInit() throws Exception { - titledBorder1 = new TitledBorder(""); - border1 = BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)); - titleLabel.setFont(new java.awt.Font("Dialog", 0, 26)); - titleLabel.setHorizontalAlignment(SwingConstants.CENTER); - titleLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.WIN)); - this.getContentPane().setLayout(new MigLayout("fill")); - continueButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.CONTINUE)); - continueButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(final ActionEvent e) { continueButton_actionPerformed(e); } - }); - restartButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.RESTART)); - restartButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(final ActionEvent e) { restartButton_actionPerformed(e); } - }); - quitButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.QUIT)); - quitButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(final ActionEvent e) { quitButton_actionPerformed(e); } - }); - statsLabel.setFont(new java.awt.Font("Dialog", 0, 16)); - statsLabel.setHorizontalAlignment(SwingConstants.CENTER); - jPanel2.setBorder(BorderFactory.createLineBorder(Color.black)); - jPanel2.setLayout(new MigLayout("align center")); - this.addWindowListener(new java.awt.event.WindowAdapter() { - @Override - public void windowClosing(final WindowEvent e) { this_windowClosing(e); } - }); - this.getContentPane().add(titleLabel, "align center, grow, wrap"); - this.getContentPane().add(statsLabel, "align center, grow, wrap"); - this.getContentPane().add(jPanel2, "grow"); - jPanel2.add(continueButton, "sg buttons, w 80%, h 20%, wrap"); - jPanel2.add(quitButton, "sg buttons, wrap"); - jPanel2.add(restartButton, "sg buttons"); - - } - - /** - *continueButton_actionPerformed.
- * - * @param e a {@link java.awt.event.ActionEvent} object. - */ - final void continueButton_actionPerformed(ActionEvent e) { - // issue 147 - keep battlefield up following win/loss - JFrame frame = (JFrame) AllZone.getDisplay(); - frame.dispose(); - - //open up "Game" screen - prepareForNextRound(); - AllZone.getDisplay().setVisible(true); - frame.setEnabled(true); - dispose(); - } - - void prepareForNextRound() { - if (Constant.Quest.fantasyQuest[0]) { - int extraLife = 0; - - if (model.event.getEventType().equals("challenge")) { - if (model.quest.getInventory().hasItem("Zeppelin")) { - extraLife = 3; - } - } - //AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], - //humanList, computerList, humanLife, computerLife); - CardList humanList = forge.quest.data.QuestUtil.getHumanStartingCards(model.quest, model.event); - CardList computerList = new CardList(); - - - int humanLife = model.quest.getLife() + extraLife; - int computerLife = 20; - if (model.event.getEventType().equals("challenge")) { - computerLife = ((QuestChallenge)model.event).getAILife(); - } - - AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], - humanList, computerList, humanLife, computerLife, model.event); - } else { - AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]); - } - - } - - /** - *restartButton_actionPerformed.
- * - * @param e a {@link java.awt.event.ActionEvent} object. - */ - final void restartButton_actionPerformed(ActionEvent e) { - // issue 147 - keep battlefield up following win/loss - JFrame frame = (JFrame) AllZone.getDisplay(); - frame.dispose(); - - model.match.reset(); - prepareForNextRound(); - AllZone.getDisplay().setVisible(true); - frame.setEnabled(true); - dispose(); - } - - /** - *getWinText.
- * - * @param creds a long. - * @param matchState a {@link forge.quest.data.QuestMatchState} object. - * @param q a {@link forge.quest.data.QuestData} object. - * @return a {@link java.lang.String} object. - */ - private String getCreditsAwardedText(final long creds, final QuestMatchState matchState, - final forge.quest.data.QuestData q) - { - // TODO use q.qdPrefs to write bonus credits in prefs file - StringBuilder sb = new StringBuilder(""); - - boolean hasNeverLost = true; - Player computer = AllZone.getComputerPlayer(); - for (GameSummary game : matchState.getGamesPlayed()) { - - if (game.isWinner(computer.getName())) { - hasNeverLost = false; - continue; // no rewards for losing a game - } - - GamePlayerRating aiRating = game.getPlayerRating(computer.getName()); - GamePlayerRating humanRating = game.getPlayerRating(AllZone.getHumanPlayer().getName()); - GameLossReason whyAiLost = aiRating.getLossReason(); - - int rewardAltWinCondition = q.getRewards().getCreditsRewardForAltWin(whyAiLost); - if (rewardAltWinCondition > 0) { - String winConditionName = "Unknown (bug)"; - if (game.getWinCondition() == GameEndReason.WinsGameSpellEffect) { - winConditionName = game.getWinSpellEffect(); - } else { - switch(whyAiLost) { - case Poisoned: winConditionName = "Poison"; break; - case Milled: winConditionName = "Milled"; break; - case SpellEffect: winConditionName = aiRating.getLossSpellName(); break; - default: break; - } - } - - String bonus = String.format("Alternate win condition: %s! Bonus: +%d credits.getIcon.
- * - * @param fileName a {@link java.lang.String} object. - * @return a {@link javax.swing.ImageIcon} object. - */ - private ImageIcon getIcon(final String fileName) { - File base = ForgeProps.getFile(IMAGE_ICON); - File file = new File(base, fileName); - ImageIcon icon = new ImageIcon(file.toString()); - return icon; - } - - /** - *quitButton_actionPerformed.
- * - * @param e a {@link java.awt.event.ActionEvent} object. - */ - final void quitButton_actionPerformed(ActionEvent e) { - // issue 147 - keep battlefield up following win/loss - JFrame frame = (JFrame) AllZone.getDisplay(); - frame.dispose(); - frame.setEnabled(true); - - //are we on a quest? - if (model.quest == null) { - model.match.reset(); - - - if (System.getenv("NG2") != null) { - if (System.getenv("NG2").equalsIgnoreCase("true")) { - String argz[] = {}; - Gui_HomeScreen.main(argz); - } else { - new OldGuiNewGame(); - } - } else { - new OldGuiNewGame(); - } - - } else { //Quest - - boolean wonMatch = false; - if (model.match.isMatchWonBy(AllZone.getHumanPlayer().getName())) { - model.quest.addWin(); - wonMatch = true; - } else { - model.quest.addLost(); - } - - //System.out.println("QuestData cardpoolsize:" + AllZone.getQuestData().getCardpool().size()); - model.quest.getCards().clearShopList(); - - - if (model.quest.getAvailableChallenges() != null) { - model.quest.clearAvailableChallenges(); - } - - model.quest.getCards().resetNewList(); - giveQuestRewards(wonMatch); - - model.match.reset(); - AllZone.setQuestEvent(null); - - model.quest.saveData(); - - new QuestFrame(); - } //else - on quest - - dispose(); - - //clear Image caches, so the program doesn't get slower and slower - //not needed with soft values - will shrink as needed -// ImageUtil.rotatedCache.clear(); -// ImageCache.cache.clear(); - } - - /** - *this_windowClosing.
- * - * @param e a {@link java.awt.event.WindowEvent} object. - */ - void this_windowClosing(WindowEvent e) { - quitButton_actionPerformed(null); - } - - /** - * - * TODO Write javadoc for this method. - */ - protected final void giveBooster() { - ListChoosergetCreditsToAdd.
- * - * @param matchState a {@link forge.quest.data.QuestMatchState} object. - * @return a long. - */ - public long getCreditsToAdd(final QuestMatchState matchState) { - - int base = QuestPreferences.getMatchRewardBase(); - double multiplier = 1; - - String diff = AllZone.getQuestEvent().getDifficulty(); - if(diff.equalsIgnoreCase("medium")) { - multiplier = 1.5; - } - else if(diff.equalsIgnoreCase("hard")) { - multiplier = 2; - } - else if(diff.equalsIgnoreCase("very hard")) { - multiplier = 2.5; - } - else if(diff.equalsIgnoreCase("expert")) { - multiplier = 3; - } - - long creds = (long) (base*multiplier - + (QuestPreferences.getMatchRewardTotalWins() * q.getWin())); - - boolean hasNeverLost = true; - Player computer = AllZone.getComputerPlayer(); - for (GameSummary game : matchState.getGamesPlayed()) { - - if (game.isWinner(computer.getName())) { - hasNeverLost = false; - continue; // no rewards for losing a game - } - - GamePlayerRating aiRating = game.getPlayerRating(computer.getName()); - GamePlayerRating humanRating = game.getPlayerRating(AllZone.getHumanPlayer().getName()); - GameLossReason whyAiLost = aiRating.getLossReason(); - - creds += getCreditsRewardForAltWin(whyAiLost); - creds += getCreditsRewardForWinByTurn(game.getTurnGameEnded()); - - int cntCardsHumanStartedWith = humanRating.getOpeningHandSize(); - if (0 == cntCardsHumanStartedWith) { - creds += QuestPreferences.getMatchMullToZero(); - } - } - - if (hasNeverLost) { - creds += QuestPreferences.getMatchRewardNoLosses(); - } - - switch(q.inventory.getItemLevel("Estates")) { - case 1: creds *= 1.1; break; - case 2: creds *= 1.15; break; - case 3: creds *= 1.2; break; - default: break; - } - - return creds; - } - - //add cards after a certain number of wins or losses - public boolean willGiveBooster(final boolean didWin) { - int cntOutcomes = didWin ? q.getWin() : q.getLost(); - return cntOutcomes % QuestPreferences.getWinsForBooster(q.getDifficultyIndex()) == 0; - } - - // this is a chance check, but used for random rare only by now - public boolean getLuckyCoinResult() { - boolean hasCoin = q.inventory.getItemLevel("Lucky Coin") >= 1; - - return MyRandom.random.nextFloat() <= (hasCoin ? 0.65f : 0.5f); - } - -} diff --git a/src/test/java/forge/GuiWinLoseTest.java b/src/test/java/forge/GuiWinLoseTest.java deleted file mode 100644 index 6da80b80cad..00000000000 --- a/src/test/java/forge/GuiWinLoseTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package forge; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import forge.quest.data.QuestMatchState; - -/** - * Created by IntelliJ IDEA. - * User: dhudson - */ -@Test(groups = {"UnitTest", "fast"}) -public class GuiWinLoseTest { - /** - * - * - */ - @Test(groups = {"UnitTest", "fast"}) - public void GuiWinLoseTest1() { - Gui_WinLose dialog = new Gui_WinLose( new QuestMatchState(), null, null ); - dialog.setVisible(true); - Assert.assertNotNull(dialog); - dialog.dispose(); - } -}