Interface Swing à partir d'un tableau 2D

Interface Swing à partir d'un tableau 2D - API Win32 - Programmation

Marsh Posté le 21-11-2019 à 12:37:50    

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
Reply

Marsh Posté le 21-11-2019 à 12:37:50   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed