I'm trying to make a simple chess game, because I wanted to practice java a bit. I decided, that every single one of my tiles will be an object. And when it came to making the constructor for the Tile class I came upon a "problem". I'm not sure whether I should have a single JPanel object as the parameter (actually a Class extending JPanel, but nevermind that) thus computing the height and width 64 times (I want to let the "user" resize the window, so it can't be constant) or should I add additional parameters to the constructor, and compute it only once before creating Tile objects? Which would be a better practice in general (since in this case it doesn't seem like it would make a big difference) and why?
Thanks for the answers
Minimize parameters or increase speed?,
Members - Reputation: 103
Posted 21 September 2013 - 01:54 PM
Members - Reputation: 628
Posted 21 September 2013 - 02:37 PM
Well, there is no point to use more parameter for your Ctor, because you should know only the top left and bottom right position of the full table and you can calculate every other parameter from that. (anyways you shouldn't calculate the width and height 64 times, all part have the same, only the position change).
Edited by Melkon, 21 September 2013 - 02:38 PM.
Members - Reputation: 126
Posted 21 September 2013 - 07:53 PM
Sorry but I don't even understand what you are asking...
You are asking if you should have a single Jpanel as the parameter to a constructor of a class that is a Tile class *insert logical link here*, thus computing width and height 64 times *insert reason for doing so and details of dimensions of what is being computed here* or should you add more parameters and pre-compute it only once.
Is it me or your description doesn't make much sense except to yourself since you are the one who sees and knows what you are doing.
Also I have no idea what parameters you would pass (to each constructor ? of Tile class?) and how would that help you.
Edited by RoundPotato, 21 September 2013 - 07:57 PM.
Members - Reputation: 1104
Posted 22 September 2013 - 01:07 PM
I don't see why you need a graphical object for each individual tile. I mean, I can see the reasoning behind a 2D array, to store pieces currently on the board, but for a visual representation, you could just have a single image/texture for the entire board, which can be scaled accordingly.