diff --git a/src/main/java/controls/BotIntelligence.java b/src/main/java/controls/BotIntelligence.java index 5623208..1435452 100644 --- a/src/main/java/controls/BotIntelligence.java +++ b/src/main/java/controls/BotIntelligence.java @@ -4,6 +4,7 @@ import interfaces.IBotBehavior; import java.util.*; +import java.util.stream.Collectors; import static views.Constants.DECK_COUNT; @@ -20,8 +21,8 @@ var candidates = new ArrayList(); for(int i=0;i x.getKey()).toList()); - candidates.removeAll(iAttack.getMyHands().stream().filter(x -> x.getValue()).map(x -> x.getKey()).toList()); + candidates.removeAll(iAttack.getOpponentHands().stream().map(x -> x.getKey()).collect(Collectors.toList())); + candidates.removeAll(iAttack.getMyHands().stream().filter(x -> x.getValue()).map(x -> x.getKey()).collect(Collectors.toList())); return candidates; } diff --git a/src/main/java/views/MainPanel.java b/src/main/java/views/MainPanel.java index 93fc672..02334f2 100644 --- a/src/main/java/views/MainPanel.java +++ b/src/main/java/views/MainPanel.java @@ -23,7 +23,11 @@ private List selectableOpponentHandKeys; Constants.Step currentStep; JPanel myHandButtonsPanel; + JPanel myHandAttackerPanel; + JPanel myPanel; JPanel opponentButtonsPanel; + JPanel opponentAttackerPanel; + JPanel opponentPanel; /** * アタックで使用するカードが既に決定しているか */ @@ -45,6 +49,18 @@ deckButtonPanel = new JPanel(); myHandButtonsPanel = new JPanel(); opponentButtonsPanel = new JPanel(); + + myHandAttackerPanel = new JPanel(); + myPanel = new JPanel(); + opponentAttackerPanel = new JPanel(); + opponentPanel = new JPanel(); + + myPanel.add(myHandAttackerPanel); + myPanel.add(myHandButtonsPanel); + + opponentPanel.add(opponentAttackerPanel); + opponentPanel.add(opponentButtonsPanel); + if(!stepScheduler.isDeckLess()){ //デッキが存在する場合 var cardButton =new JButton("deck"); cardButton.setPreferredSize(new Dimension(CARD_HEIGHT,CARD_WIDTH)); @@ -56,65 +72,47 @@ * */ add(deckButtonPanel,BorderLayout.WEST); - add(myHandButtonsPanel, BorderLayout.SOUTH); + //add(myHandButtonsPanel, BorderLayout.SOUTH); + add(myPanel,BorderLayout.SOUTH); - add(opponentButtonsPanel, BorderLayout.NORTH); - setStep(Step.SelectOpponentHands); + //add(opponentButtonsPanel, BorderLayout.NORTH); + add(opponentPanel,BorderLayout.NORTH); + opponentHandButtons.stream().filter(x -> x.getText().equals(CLOSED_SYMBOL)).forEach(x -> { + x.setEnabled(true); + }); repaint(); } - - void setStep(Step step) { - currentStep = step; - switch (step) { - case SelectMyHands: - break; - case SelectOpponentHands: - opponentHandButtons.stream().filter(x -> x.getText().equals(CLOSED_SYMBOL)).forEach(x -> { - x.setEnabled(true); - }); - break; - - case Declare: - opponentHandButtons.stream().filter(x -> x.getText().equals(CLOSED_SYMBOL)).forEach(x -> { - x.setEnabled(false); - }); - break; - case Confirm: - - break; - } - } void botBehave(IAttack iAttack){ iAttack.shiftTurn(); var bot = new BotIntelligence(); - JOptionPane.showMessageDialog(null,"Bot`s Turn."); + JOptionPane.showMessageDialog(null,"Botのターンです。"); var selectText = ""; var atk =0; if(!iAttack.isDeckLess()){ //デッキにカードが存在するとき paintDrawCard(iAttack);//デッキから引いたカードを描画する - selectText = "Bot drew."; + selectText = "Botはカードをドローしました。"; }else{ atk= bot.selectAttacker(iAttack); opponentHandButtons.get(atk).setEnabledSelection(true); - selectText = "Bot selected. "; + selectText = "Botはアタックに使用するカードを選びました。"; } JOptionPane.showMessageDialog(null,selectText); var targetText = ""; var tar = bot.selectTarget(iAttack); myHandButtons.get(tar).setEnabledSelection(true); - JOptionPane.showMessageDialog(null,"Bot targeted this."); + JOptionPane.showMessageDialog(null,"Botはこのカードを対象にしました。"); var dec = bot.declareNumber(iAttack, tar); - JOptionPane.showMessageDialog(null,"Bot declared "+ dec +"."); + JOptionPane.showMessageDialog(null,"Botは\""+ dec +"\"を宣言しました。"); iAttack.Attack(dec, atk, tar); boolean isSucceed=iAttack.isSucceedLatestAttack(); - String resultMessage="Bot`s Attack Was "; - resultMessage+=isSucceed?"Succeed.":"Failed."; + String resultMessage="Botのアタックは "; + resultMessage+=isSucceed?"成功しました。":"失敗しました。"; JOptionPane.showMessageDialog(null,resultMessage); myHandButtons.get(tar).setEnabledSelection(false); @@ -134,13 +132,11 @@ var cardButton =new CardButton(deckTopCard.getKey().toString()); cardButton.setBounds(0,100,CARD_WIDTH,CARD_HEIGHT); if(iAttack.isATurn()){ - myHandButtons.add(cardButton); - myHandButtonsPanel.add(cardButton, BorderLayout.WEST); + myHandAttackerPanel.add(cardButton); isDecidedAttacker=true; }else { cardButton.setText(CLOSED_SYMBOL); - opponentHandButtons.add(cardButton); - opponentButtonsPanel.add(cardButton, BorderLayout.WEST); + opponentAttackerPanel.add(cardButton); } if(iAttack.getDeckNumber()==1){ deckButtonPanel.removeAll(); @@ -161,10 +157,11 @@ isDecidedAttacker=false; myHandButtonsPanel.removeAll();// myHandButtons.clear(); + myHandAttackerPanel.removeAll(); + opponentAttackerPanel.removeAll(); opponentButtonsPanel.removeAll();// opponentHandButtons.clear(); - /** * 自分の手札に関する処理 */ @@ -174,8 +171,8 @@ cardButton.setStatus(i.getValue()? CardButton.Status.OPEN: CardButton.Status.MY_CLOSED); myHandButtons.add(cardButton); - myHandButtonsPanel.add(cardButton, BorderLayout.WEST); - + //myHandButtonsPanel.add(cardButton, BorderLayout.WEST); + myHandButtonsPanel.add(cardButton); final var a=indexForMyHands;//actionPerformedの中に書くと、クリックされて初めて、回しきったindexForMyHandsを参照してしまうため、ここで一時変数に格納する cardButton.addActionListener(new ActionListener() { @Override @@ -183,7 +180,7 @@ if(!iAttack.isDeckLess())return;//デッキがあるときは何も反応しないように for(var my:myHandButtons)my.setEnabledSelection(false); cardButton.setEnabledSelection(true); - var option = JOptionPane.showConfirmDialog(null, "Attack with This Card?", "confirmation", 2); + var option = JOptionPane.showConfirmDialog(null, "このカードを使ってアタックをしますか?", "confirmation", 2); if (option == JOptionPane.YES_OPTION){ @@ -211,7 +208,7 @@ public void actionPerformed(ActionEvent e) { if(!iAttack.isDeckLess())isDecidedAttacker=true; if(!isDecidedAttacker){ - JOptionPane.showMessageDialog(null, "Select Attacker from Your Hands. ", "Warn", + JOptionPane.showMessageDialog(null, "あなたの手札からアタックに使用するカードを選んでください. ", "Warn", JOptionPane.WARNING_MESSAGE); return; } @@ -219,16 +216,18 @@ cardButton.setEnabledSelection(true); //相手のカードを選択したときに確認用ダイアログを出す - var option = JOptionPane.showConfirmDialog(null, "Select This Card?", "confirmation", 2); + var option = JOptionPane.showConfirmDialog(null, "このカードを選びますか?", "confirmation", 2); if (option == JOptionPane.YES_OPTION) { target = opponentHands.size()-index;//画面上,相手の手札も自分の手札と同じように左から右へ並べられているため,それを補正するために反転させている var t = index; - setStep(Step.Declare); + opponentHandButtons.stream().filter(x -> x.getText().equals(CLOSED_SYMBOL)).forEach(x -> { + x.setEnabled(false); + }); String[] optionsToChoose = new String[DECK_COUNT]; for (var i = 0; i < optionsToChoose.length; i++) optionsToChoose[i] = String.valueOf(i); var getDeclaredNumber = (String) JOptionPane.showInputDialog( null, - "What number is this card?", + "このカードの数字を宣言してください。", "Declare Number", JOptionPane.QUESTION_MESSAGE, null, @@ -238,15 +237,16 @@ guess = Integer.parseInt(getDeclaredNumber); var g= Integer.parseInt(getDeclaredNumber); iAttack.Attack(g, attacker, t); - setStep(Step.Confirm); boolean isSucceed=iAttack.isSucceedLatestAttack(); - String resultMessage="Your Attack Was "; - resultMessage+=isSucceed?"Succeed.":"Failed."; + String resultMessage="あなたのアタックは"; + resultMessage+=isSucceed?"成功しました。":"失敗しました。"; JOptionPane.showMessageDialog(null,resultMessage); }else{ - setStep(Step.SelectOpponentHands); + opponentHandButtons.stream().filter(x -> x.getText().equals(CLOSED_SYMBOL)).forEach(x -> { + x.setEnabled(true); + }); return; } @@ -275,19 +275,19 @@ public void playerBehave(IAttack iAttack){ isDecidedAttacker=false; - JOptionPane.showMessageDialog(null,"Your Turn."); + JOptionPane.showMessageDialog(null,"あなたのターンです。"); var selectText = ""; var atk =0; if(!iAttack.isDeckLess()){ //デッキにカードが存在するとき - selectText = "You drew \""+ iAttack.getTopCard().getKey()+"\"."; + selectText = "あなたは数字\""+ iAttack.getTopCard().getKey()+"\"のカードをドローしました。"; }else{ - selectText = "Select Card used in Your Attack from Your Hands."; + selectText = "アタックに使用するカードを手札から選んでください。"; } paintDrawCard(iAttack); JOptionPane.showMessageDialog(null,selectText); - if(!iAttack.isDeckLess())JOptionPane.showMessageDialog(null,"Select Card from Opponent`s Hands."); + if(!iAttack.isDeckLess())JOptionPane.showMessageDialog(null,"アタックする対象を相手の手札から選んでください。"); } @@ -348,9 +348,9 @@ validate(); repaint(); if(iAttack.isALose()){ - JOptionPane.showMessageDialog(null,"Bot Win."); + JOptionPane.showMessageDialog(null,"Botが勝利しました。"); }else if(iAttack.isBLose()){ - JOptionPane.showMessageDialog(null,"You Win."); + JOptionPane.showMessageDialog(null,"あなたが勝利しました。"); } }