-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttackMenu.java
122 lines (114 loc) · 5.49 KB
/
AttackMenu.java
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import java.awt.*;
import javax.swing.*;
public class AttackMenu extends JPanel {
private static final long serialVersionUID = 1L;
/*** AttackStats ***/
public Territory attacker;
public Territory defender;
/*** Component proportions ***/
public static final double MY_HEIGHT = 1.0 / 3;
public static final double MY_WIDTH = 1.0 / 3;
public static final double LABEL_HEIGHT = 0.25;
public static final double BAR_HEIGHT = 0.1;
public static final double DIE_HEIGHT = 0.5 / 3;
public static final double TROOP_HEIGHT = 0.25;
/*** Components ***/
private String[][] buttonNames = {{"retreat"}, {"1 army"}, {"2 armies"}, {"3 armies"}, {"do or die"}};
private JLabel[] dice;
private JTextArea[] labels;
private JLabel[] troopCount;
private JPanel buttonHolder;
public JButton[] buttons;
/*** Constructor ***/
public AttackMenu(Territory a, Territory d) {
//Territories
attacker = a;
defender = d;
attacker.getOccupation().battlesT++;
defender.getOccupation().battlesT++;
BoardState.dice = new int[5];
//Initialize Components
setLayout(null);
setBackground(GameBoard.MAIN);
setBorder(BorderFactory.createLineBorder(GameBoard.FONT));
dice = new JLabel[5];
labels = new JTextArea[2];
troopCount = new JLabel[2];
buttonHolder = new JPanel(new GridLayout(0, buttonNames.length));
buttonHolder.setBorder(BorderFactory.createLineBorder(GameBoard.FONT));
buttons = new JButton[buttonNames.length];
for(int i = 0; i < 5; i++){
dice[i] = new JLabel("-", SwingConstants.CENTER);
dice[i].setBackground(GameBoard.MAIN);
dice[i].setBorder(BorderFactory.createLineBorder(GameBoard.FONT));
dice[i].setForeground(GameBoard.FONT);
if(i < 3)
dice[i].setForeground(Color.RED);
add(dice[i]);
}
for(int i = 0; i < 2; i++){
labels[i] = new JTextArea();
labels[i].setOpaque(false);
labels[i].setEditable(false);
add(labels[i]);
}
labels[0].setForeground(attacker.getOccupation().getColor());
labels[1].setForeground(defender.getOccupation().getColor());
labels[1].setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
for(int i = 0; i < 2; i++){
troopCount[i] = new JLabel("", SwingConstants.CENTER);
troopCount[i].setBackground(GameBoard.MAIN);
add(troopCount[i]);
}
for(int i = 0; i < buttons.length; i++){
buttons[i] = new myButton(buttonNames[i], GameBoard.MAIN, GameBoard.MOUSE);
buttons[i].setForeground(GameBoard.FONT);
buttons[i].setFocusPainted(false);
buttons[i].setBorder(BorderFactory.createEmptyBorder());
buttons[i].setFont(new Font("Consolas", Font.PLAIN, buttons[i].getFont().getSize()));
buttonHolder.add(buttons[i]);
}
add(buttonHolder);
}
public int c(){return (labels[0].getHeight() + buttonHolder.getBounds().y) / 2;}
public void reset(){
//This
setBounds((int)(BoardState.BOARD.getWidth() * (0.5 - MY_WIDTH / 2)), (int)(BoardState.BOARD.getHeight() * (0.5 - MY_HEIGHT / 2)), (int)(BoardState.BOARD.getWidth() * MY_WIDTH), (int)(BoardState.BOARD.getHeight() * MY_HEIGHT));
//Labels
labels[0].setForeground(attacker.getOccupation().getColor());
labels[1].setForeground(defender.getOccupation().getColor());
labels[0].setBounds(0, 0, getWidth() / 2, (int)(getHeight() * LABEL_HEIGHT));
labels[1].setBounds(labels[0].getWidth(), 0, labels[0].getWidth(), labels[0].getHeight());
labels[0].setText(attacker.fullStats());
labels[1].setText(defender.fullStats());
labels[0].setMargin(new Insets(5, 5, 5, 5));
labels[1].setMargin(new Insets(5, 5, 5, 5));
labels[0].setFont(new Font("Consolas", Font.PLAIN, labels[0].getHeight() / 5));
labels[1].setFont(labels[0].getFont());
//Buttons
buttonHolder.setBounds(0, (int)(getHeight() * (1 - BAR_HEIGHT)), getWidth(), (int)(getHeight() * BAR_HEIGHT));
//Dice
dice[0].setBounds(0, c() + (int)(0.5 * getHeight() * DIE_HEIGHT), (int)(getHeight() * DIE_HEIGHT), (int)(getHeight() * DIE_HEIGHT));
dice[1].setBounds(0, dice[0].getBounds().y - dice[0].getHeight(), dice[0].getWidth(), dice[0].getHeight());
dice[2].setBounds(0, dice[1].getBounds().y - dice[1].getHeight(), dice[0].getWidth(), dice[0].getHeight());
dice[3].setBounds(getWidth() - dice[0].getWidth(), c(), dice[0].getWidth(), dice[0].getWidth());
dice[4].setBounds(dice[3].getX(), c() - dice[0].getWidth(), dice[0].getWidth(), dice[0].getWidth());
for(int i = 0; i < dice.length; i++){
dice[i].setFont(new Font("Consolas", Font.BOLD, (int)(0.8 * dice[0].getHeight())));
dice[i].setText(BoardState.dice[i] != 0 ? Integer.toString(BoardState.dice[i]) : "-");
}
//Troop counts
troopCount[0].setForeground(attacker.getOccupation().getColor());
troopCount[1].setForeground(defender.getOccupation().getColor());
troopCount[0].setBounds(getWidth() / 2 - (int)(1.5 * TROOP_HEIGHT * getHeight()), c() - (int)(TROOP_HEIGHT * getHeight()) / 2, (int)(TROOP_HEIGHT * getHeight()), (int)(TROOP_HEIGHT * getHeight()));
troopCount[1].setBounds(getWidth() / 2 + troopCount[0].getWidth() / 2, troopCount[0].getY(), troopCount[0].getWidth(), troopCount[0].getHeight());
troopCount[0].setFont(new Font("Consolas", Font.BOLD, (int)(0.8 * troopCount[0].getHeight())));
troopCount[1].setFont(new Font("Consolas", Font.BOLD, (int)(0.8 * troopCount[1].getHeight())));
troopCount[0].setText(Integer.toString(attacker.getTroops()));
troopCount[1].setText(Integer.toString(defender.getTroops()));
//Repaint
repaint();
if(BoardState.BOARD.getMoveMenu() != null)
BoardState.BOARD.getMoveMenu().reset();
}
}