diff --git a/src/main/java/views/MainPanel.java b/src/main/java/views/MainPanel.java index e7282a6..cb9c889 100644 --- a/src/main/java/views/MainPanel.java +++ b/src/main/java/views/MainPanel.java @@ -21,6 +21,8 @@ private List selectableMyHandKeys; private List selectableOpponentHandKeys; + JPanel myHandButtonsPanel; + JPanel opponentButtonsPanel; int guess; int attacker; int target; @@ -35,8 +37,8 @@ } void setButtons(IAttack stepScheduler) { - JPanel myHandButtonsPanel = new JPanel(); - JPanel opponentButtonsPanel = new JPanel(); + myHandButtonsPanel = new JPanel(); + opponentButtonsPanel = new JPanel(); var myHands = stepScheduler.getMyHands(); var opponentHands = stepScheduler.getOpponentHands(); @@ -57,13 +59,15 @@ cardButton.setPreferredSize(new Dimension(CARD_WIDTH, CARD_HEIGHT)); cardButton.setEnabled(false); cardButton.addActionListener(new ActionListener() { + final int index=indexForOpponent; public void actionPerformed(ActionEvent e) { var baseColor= cardButton.getBackground(); cardButton.setBackground(SELECTED_COLOR); - + //相手のカードを選択したときに確認用ダイアログを出す var option = JOptionPane.showConfirmDialog(null, "Select This Card?", "confirmation", 2); if (option == JOptionPane.YES_OPTION) { - target = opponentHands.size()-indexForOpponent;//, + target = opponentHands.size()-index;//画面上,相手の手札も自分の手札と同じように左から右へ並べられているため,それを補正するために反転させている + var t = index; setStep(Step.Declare); String[] optionsToChoose = new String[DECK_COUNT]; for (var i = 0; i < optionsToChoose.length; i++) optionsToChoose[i] = String.valueOf(i); @@ -77,15 +81,18 @@ optionsToChoose[0]); if(getDeclaredNumber!=null) { guess = Integer.parseInt(getDeclaredNumber); - stepScheduler.Attack(guess, attacker, target); + var g= Integer.parseInt(getDeclaredNumber); + stepScheduler.Attack(g, attacker, t); setStep(Step.Confirm); - boolean isSucceed=stepScheduler.getOpponentHands().get(target).getKey()==guess; + boolean isSucceed=stepScheduler.getOpponentHands().get(t).getKey()==g; String resultMessage="Your Attack Was "; resultMessage+=isSucceed?"Succeed.":"Failed."; JOptionPane.showMessageDialog(null,resultMessage); + //次の画面に遷移する処理 + update(stepScheduler); }else{ setStep(Step.SelectOpponentHands); } @@ -94,7 +101,7 @@ } }); opponentHandButtons.add(cardButton); - opponentButtonsPanel.add(cardButton, 0); + opponentButtonsPanel.add(cardButton, 0);//見た目の順序が逆になるように,0番目に挿入 indexForOpponent++; } add(myHandButtonsPanel, BorderLayout.SOUTH); @@ -124,11 +131,29 @@ } void update(IAttack iAttack){ - myHandButtons.stream().filter(x -> x.getText().equals(CLOSED_SYMBOL)).forEach(x -> { + myHandButtons.stream().forEach(x -> { x.setEnabled(false); }); - opponentHandButtons.stream().filter(x -> x.getText().equals(CLOSED_SYMBOL)).forEach(x -> { - x.setEnabled(false); + + //opponentHandButtons.clear(); + //remove(opponentButtonsPanel); + for(int i=0,n=opponentHandButtons.size();i{ +// +// var cardButton = new JButton(x.getValue() ? x.getKey().toString() :CLOSED_SYMBOL); +// cardButton.setPreferredSize(new Dimension(CARD_WIDTH, CARD_HEIGHT)); +// cardButton.setEnabled(true); +// opponentHandButtons.add(cardButton); +// opponentButtonsPanel.add(cardButton, 0);//見た目の順序が逆になるように,0番目に挿入 +// }); + opponentHandButtons.stream().forEach(x -> { + x.setEnabled(true); }); + // add(opponentButtonsPanel); + /// repaint(); } }