Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1527 connectés 

  FORUM HardWare.fr
  Programmation
  API Win32

  Interface Swing à partir d'un tableau 2D

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Interface Swing à partir d'un tableau 2D

n°2341922
Petter
Posté le 21-11-2019 à 12:37:50  profilanswer
 

Hello everyone,,
 
As part of my (short) training pro (java / php), we realized a mini project (no mastery of the combo Swing / listeners at "the time" ) where I had coded a little game (console display) of labyrinth, with a 2-dimensional array for the play area (and ASCII characters for display).
A character that moves, with HP, enemies placed on some boxes, and fights playing with dice (with a math.random).
 
 
It's basic but I find it not too bad at my level, and it could serve me for my exam defense (and then it's fun : o).
I would like to resume this project with my current level to make it more graphic (+ possibly connect to a database for high scores).
http://tradevenue.se/
The old arch was based on a 2-dimensional table-based labyrinth, which is fairly simple to calculate coordinates.
I would now like to retype it in graphical form, with a JFrame containing a JPanel in GridLayout.
My first idea was to represent the boxes with labels (square of 8x8 = 64) in which I put an Imageicon (representing the enemies + the character).
 
 
Only "worry", my method seems tedious: with the table, the position of the player was easy to read and update (x and y coordinates attributes of the object "player" ), there I had to create separately 64 labels to be able to name them (c1, c2, c3, ..., c64) and to interpret them it would be necessary that I realize a split on the name of the variable,
It seems simple to say but I feel that I'm going straight into a wall, and then it's not elegant (64 private labels in a class of JFrame, as many getters, it's too heavy to be optimized).
 
 
Would you see a solution to this problem? Another method, or simple way to retrieve the name of the JLabel on which the character falls (ex: from the JLabel listener c8 = new JLabel ();, get a String "c8" ).
 
I thought about a deduction-based solution (I know where the player is from and where he lands in the direction indicated), but even if I know that his movement brings him to box c12 (-> JLabel c12) , I can have a String "c12", but then it would be necessary to use a method setC12 (), and there it is dead : /
 
 
Hoping to have been clear, thank you for your help: D


Message édité par Petter le 26-12-2019 à 10:24:58
mood
Publicité
Posté le 21-11-2019 à 12:37:50  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  API Win32

  Interface Swing à partir d'un tableau 2D

 

Sujets relatifs
[PHP] Remplacer des mots dans une string par des valeurs d'un tableauExercice de tableau basique en C URGENT !
résoluactualiser une table à partir d'une autre
tableau de présence avec compteur[PHP] Garder uniquement les enregistrements présents dans un tableau
concaténer nom de tableau et variableTransmettre données ligne tableau
bash- recherche lignes dans bloc et affichage dans tableauInterface Swing à partir d'un tableau 2D (jeu)
Plus de sujets relatifs à : Interface Swing à partir d'un tableau 2D


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR