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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
| package jdr;
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.*;
import java.awt.event.*;
public class FrameJDR extends AbstractAction implements KeyListener,EcouteurMiseAJour{
/** Définition **/
// private final static String Fr_Attaque = "";
/** Variables **/
/** Interface **/
private volatile JTextField txtTchat = new JTextField( "" , 30 );
private volatile JLabel lbTchat;
private Tchat trdTchat;
private JButton monde[][] ;// a initialise
private JPanel panelCenter = new JPanel();
/** Outils **/
private Var var = new Var("Pref");
private JFrame fenaitre;
private Carte carte = new Carte();
/** Constructeur **/
public FrameJDR(){
/* Fenaitre */
super();
/* Délcaration de l'interface */
carte.addEcouteurMiseAJour(this);
/* Interface */
fenaitre = new JFrame();
/* Aspect */
fenaitre.setTitle("JDR");
// fl.setSize(800,600);
fenaitre.setBounds(java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
fenaitre.setVisible(true);
fenaitre.setIconImage(new ImageIcon(getClass().getResource("img/favicon.gif")).getImage());
fenaitre.setLocationRelativeTo(null); //On centre la fentre sur l'écran
fenaitre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/* Zone de positionnement */
JPanel panel = new JPanel();
BorderLayout struct = new BorderLayout();
fenaitre.setContentPane(panel);
panel.setLayout(struct);
if (var.isVar("bg")){// Couleur de fond
panel.setBackground(new Color(new Integer(var.getVar("bg"))));
}else{
panel.setBackground(Color.BLACK);
}
/* Site : ( North ) */
JPanel panelNorth = new JPanel();
/***
* Menu :
***/
JMenuBar menu = new JMenuBar();
JMenu mnAbout = new JMenu("?");
menu.add(mnAbout);
JMenuItem mnThinksTo = new JMenuItem("Remerciement");
mnAbout.add(mnThinksTo);
mnThinksTo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JOptionPane.showMessageDialog(new Frame(),
"Chef de projet :\n"+
"Ungar Didier\n"+
"Programmeurs :\n"+
"Ungar Didier\n"+
"Desplanque Valentin"+
"Relectrice :\n"+
"Le Tiec Alexandra\n"+
"Mais aussi les testeurs...");
}
});
panelNorth.add(menu);
panel.add(panelNorth,BorderLayout.NORTH);
panelNorth.setBackground(panel.getBackground());
/* Quit : ( South ) */
JPanel panelSouth = new JPanel();
// Vie
JProgressBar barVie;
barVie = new JProgressBar(0, 100);
barVie.setValue(20);
barVie.setStringPainted(true);
barVie.setBackground(Color.WHITE);
barVie.setForeground(Color.RED);
panelSouth.add(barVie);
// Action
JComboBox lstAct = new JComboBox();
lstAct.addItem("Attaque Corp à Corp");
lstAct.addItem("Attaque Distance");
lstAct.addItem("Sort de soin léger");
lstAct.addItem("Sort de soin lourd");
lstAct.addItem("Sort de boule de feu");
lstAct.addItem("Sort d'aura foudroyante");
panelSouth.add(lstAct);
// Bouton
JButton bt_Sac = new JButton("Sac");
bt_Sac.addActionListener(this);
panelSouth.add(bt_Sac);
// Mana
// Vie
JProgressBar barMana;
barMana = new JProgressBar(0, 100);
barMana.setValue(20);
barMana.setStringPainted(true);
barMana.setBackground(Color.WHITE);
barMana.setForeground(Color.BLUE);
panelSouth.add(barMana);
// Général
panel.add(panelSouth,BorderLayout.SOUTH);
panelSouth.setBackground(panel.getBackground());
/* Resultat : ( Center ) */
panelCenter.setLayout(new GridLayout(carte.getSizeX(),carte.getSizeY()));
monde = new JButton[carte.getSizeX()][carte.getSizeY()];
for (int y=0 ; y<carte.getSizeY() ; y++){
for (int x=0 ; x<carte.getSizeX() ; x++){
monde[x][y] = new JButton("");// On crée la case
panelCenter.add(monde[x][y]);// On place la case
monde[x][y].addActionListener(new ActCase(x,y));// On rend interactif
}
}// Affichage du monde
affCentre();
panel.add(panelCenter,BorderLayout.CENTER);
panelCenter.setBackground(panel.getBackground());
/* Menu : ( West ) */
JPanel panelWest = new JPanel();
panelWest.setLayout(new BoxLayout(panelWest,BoxLayout.Y_AXIS));
panel.add(panelWest,BorderLayout.WEST);
panelWest.setBackground(panel.getBackground());
/* Options : ( East ) */
JPanel panelEast = new JPanel();
panelEast.setLayout(new BoxLayout(panelEast,BoxLayout.Y_AXIS));
panelEast.add(txtTchat);
JButton bt_Dire = new JButton("Dire");
bt_Dire.addActionListener(this);
panelEast.add(bt_Dire);
lbTchat = new JLabel();
trdTchat = new Tchat(lbTchat);
trdTchat.start();
panelEast.add(lbTchat);
panel.add(panelEast,BorderLayout.EAST);
panelEast.setBackground(panel.getBackground());
// Relation
txtTchat.addKeyListener(this);
// Affichage
fenaitre.setVisible(true);
}
/** Affichages **/
/*
* Calcul/Recalcul le tableaux de la carte
*/
private void affCentre(){
panelCenter.setLayout(new GridLayout(carte.getSizeY(),carte.getSizeX()));
for (int y=0 ; y < carte.getSizeY() ; y++ ){
for (int x=0 ; x < carte.getSizeX() ; x++ ){
if ( carte.getCase(x, y) != null ){
if ( carte.getCase(x, y).getImg() != null )
monde[x][y].setIcon( carte.getCase(x, y).getImg() );
else{
monde[x][y].setIcon( null );
monde[x][y].setText( new Integer(carte.getCase(x, y).getObstacle()).toString() );
}
}else{
monde[x][y].setIcon( null );
monde[x][y].setText("?");
}
monde[x][y]
.setToolTipText("Position : ("
+(carte.getPosiX()-7+x)+","
+(carte.getPosiY()+7-y)+")");
}
}
//panelCenter.repaint();
//fenaitre.repaint();
}
public synchronized void miseAJour(){
affCentre();
}
/** Interface **/
public void actionPerformed(ActionEvent e) {
if ( e.getActionCommand()=="Dire" ){
trdTchat.dire(txtTchat.getText());
txtTchat.setText("");
}else
System.err.println(e.getActionCommand());
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER ){
trdTchat.dire(txtTchat.getText());
txtTchat.setText("");
}
}
/* Classe interne pour la gestion des cliques sur la carte */
class ActCase extends AbstractAction{
private int x;
private int y;
public ActCase(int x,int y){
this.x=x;
this.y=y;
}
/* Gestion des cliques sur la carte : */
public void actionPerformed(ActionEvent e){
if ( carte.getCase(x,y) == null )
return;
if ( carte.getCase(x,y).getObstacle() <= 1)// Déplacement
carte.mov(x-7, -y+7);
else if ( carte.getCase(x,y).getObstacle() == 3)// Monstre
monde[x][y].setIcon( new ImageIcon("img/attaque.gif") );
}
}
/** Accesseur **/
/** Testeur **/
public static void main(String[] args){
new FrameJDR( );
}
} |
Partager