-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeedback.java
More file actions
72 lines (59 loc) · 2.64 KB
/
Copy pathFeedback.java
File metadata and controls
72 lines (59 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import javax.swing.*;
import java.awt.*;
public class Feedback {
// Tamanho dos pinos de feedback
private static final int PIN_SIZE = 110;
// Método para obter o painel de feedback
public static JPanel getFeedbackPanel(String[] correctSequence, String[] playerSequence) {
JPanel feedbackPanel = new JPanel();
feedbackPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
int blackPins = 0;
int whitePins = 0;
boolean[] usedInSolution = new boolean[correctSequence.length];
boolean[] usedInGuess = new boolean[correctSequence.length];
// Contar os pinos pretos
for (int i = 0; i < correctSequence.length; i++) {
if (playerSequence[i].equals(correctSequence[i])) {
blackPins++;
usedInSolution[i] = true;
usedInGuess[i] = true;
}
}
// Contar os pinos brancos
for (int i = 0; i < correctSequence.length; i++) {
if (!usedInGuess[i]) {
for (int j = 0; j < correctSequence.length; j++) {
if (!usedInSolution[j] && playerSequence[i].equals(correctSequence[j])) {
whitePins++;
usedInSolution[j] = true;
break;
}
}
}
}
// Escalar as imagens dos pinos com as proporções corretas
final int desiredHeight = PIN_SIZE;
// Obter as imagens dos pinos pretos e brancos
ImageIcon blackIcon = new ImageIcon("pinoPreto.png");
double blackScale = (double) desiredHeight / blackIcon.getIconHeight();
Image blackImage = blackIcon.getImage().getScaledInstance((int) (blackIcon.getIconWidth() * blackScale),
desiredHeight, Image.SCALE_SMOOTH);
ImageIcon scaledBlackIcon = new ImageIcon(blackImage);
ImageIcon whiteIcon = new ImageIcon("pinoBranco.png");
double whiteScale = (double) desiredHeight / whiteIcon.getIconHeight();
Image whiteImage = whiteIcon.getImage().getScaledInstance((int) (whiteIcon.getIconWidth() * whiteScale),
desiredHeight, Image.SCALE_SMOOTH);
ImageIcon scaledWhiteIcon = new ImageIcon(whiteImage);
// Adicionar pinos pretos
for (int i = 0; i < blackPins; i++) {
JLabel blackLabel = new JLabel(scaledBlackIcon);
feedbackPanel.add(blackLabel);
}
// Adicionar pinos brancos
for (int i = 0; i < whitePins; i++) {
JLabel whiteLabel = new JLabel(scaledWhiteIcon);
feedbackPanel.add(whiteLabel);
}
return feedbackPanel;
}
}