Minimize parameters or increase speed?

Started by
2 comments, last by Goran Milovanovic 10 years, 7 months ago

Hello everyone!
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 smile.png

Advertisement

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).

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.

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.

+---------------------------------------------------------------------+

| Game Dev video tutorials -> http://www.youtube.com/goranmilovano | +---------------------------------------------------------------------+

This topic is closed to new replies.

Advertisement